对于一个控件,比如JButton,首先初始化:
button1 = new javax.swing.JButton();
添加一个监听器,如
button1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button1ActionPerformed(evt);
}
});
其中将该监听器与button1ActionPerformed()函数进行了关联。
然后在UI相应的layout里添加group、添加component,写好该函数就行了。