java之swing实现复选框的方法
本文实例讲述了java之swing实现复选框的方法。分享给大家供大家参考。具体如下:
importjava.awt.*; importjavax.swing.*; importjava.awt.event.*; publicclasstestextendsJApplet implementsItemListener{ JTextFieldjtf; publicvoidinit(){ ContainercontentPane=getContentPane(); contentPane.setLayout(newFlowLayout()); ImageIcona1=newImageIcon("D:/data/Images/6.gif"); ImageIcona2=newImageIcon("D:/data/Images/7.gif"); ImageIcona3=newImageIcon("D:/data/Images/8.gif"); JCheckBoxcb=newJCheckBox("C",a1); cb.setRolloverIcon(a2); cb.setSelectedIcon(a3); cb.addItemListener(this); contentPane.add(cb); cb=newJCheckBox("C++",a1); cb.setRolloverIcon(a2); cb.setSelectedIcon(a3); cb.addItemListener(this); contentPane.add(cb); cb=newJCheckBox("java",a1); cb.setRolloverIcon(a2); cb.setSelectedIcon(a3); cb.addItemListener(this); contentPane.add(cb); jtf=newJTextField(15); contentPane.add(jtf); } publicvoiditemStateChanged(ItemEventie){ JCheckBoxcb=(JCheckBox)ie.getItem(); jtf.setText(cb.getText()); } }
希望本文所述对大家的java程序设计有所帮助。