java之swing实现复选框的方法
程序员文章站
2024-03-05 18:05:55
本文实例讲述了java之swing实现复选框的方法。分享给大家供大家参考。具体如下:
import java.awt.*;
import javax.swing...
本文实例讲述了java之swing实现复选框的方法。分享给大家供大家参考。具体如下:
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class test extends japplet implements itemlistener{ jtextfield jtf; public void init(){ container contentpane = getcontentpane(); contentpane.setlayout(new flowlayout()); imageicon a1 = new imageicon("d:/data/images/6.gif"); imageicon a2 = new imageicon("d:/data/images/7.gif"); imageicon a3 = new imageicon("d:/data/images/8.gif"); jcheckbox cb = new jcheckbox("c", a1); cb.setrollovericon(a2); cb.setselectedicon(a3); cb.additemlistener(this); contentpane.add(cb); cb = new jcheckbox("c++", a1); cb.setrollovericon(a2); cb.setselectedicon(a3); cb.additemlistener(this); contentpane.add(cb); cb = new jcheckbox("java", a1); cb.setrollovericon(a2); cb.setselectedicon(a3); cb.additemlistener(this); contentpane.add(cb); jtf = new jtextfield(15); contentpane.add(jtf); } public void itemstatechanged(itemevent ie){ jcheckbox cb = (jcheckbox)ie.getitem(); jtf.settext(cb.gettext()); } }
希望本文所述对大家的java程序设计有所帮助。