我用netbeans编写了一个简单的程序:源文件如下:
package swingtest;
import javax.swing.*;
import javax.swing.event.*;
public class MFrame extends javax.swing.JFrame {
/** Creates new form MFrame */
public MFrame() {
initComponents();
bgroup = new ButtonGroup();
bgroup.add(jRadioButton1);
bgroup.add(jRadioButton2);
s = bgroup.getButtonCount();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate= "collapsed " desc= " 生成的代码 ">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jToggleButton1 = new javax.swing.JToggleButton();
jCheckBox1 = new javax.swing.JCheckBox();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText( "jLabel1 ");
jButton1.setText( "jButton1 ");
jToggleButton1.setText( "jToggleButton1 ");
jCheckBox1.setText( "jCheckBox1 ");
jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0));
jCheckBox1.addItemListener(new java.awt.event.ItemListener() {