| 发表于:2007-03-31 16:21:502楼 得分:10 |
给个jlist的例子看看 import javax.swing.*; import java.awt.event.*; import java.awt.*; public class comboboxes extends japplet { private string[] description = { "ebullient ", "obtuse ", "recalcitrant ", "brilliant ", "somnescent ", "timorous ", "florid ", "putrescent " }; private jtextfield t = new jtextfield(15); private jcombobox c = new jcombobox(); private jbutton b = new jbutton( "add items "); private jpasswordfield jp = new jpasswordfield(10); string[] items = { "足球 ", "蓝球 ", "网球 ", "拖拉机 "}; jlist list = new jlist(items); private int count = 0; public void init() { for (int i = 0; i < 4; i++){ c.additem(description[count++]); } t.seteditable(false); b.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { if (count < description.length) c.additem(description[count++]); } }); c.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { t.settext( "index: " + c.getselectedindex() + " " + ((jcombobox) e.getsource()).getselecteditem()); } }); container cp = getcontentpane(); cp.setlayout(new flowlayout()); cp.add(t); cp.add(list); cp.add(jp); cp.add(c); cp.add(b); } public static void main(string[] args) { console.run(new comboboxes(), 200, 125); } } | | |
|