[填空题] 阅读下面程序段,SelectItem应用程序显示从文本域的组合框中进行选择,请在程序中的画线处添上正确的语句使得程序能够正确运行。 ... JTextField result = new
[填空题] 阅读下面程序段,SelectItem应用程序显示从文本域的组合框中进行选择,请在程序中的画线处添上正确的语句使得程序能够正确运行。 ... JTextField result = new JTextField(); JComboBox pick = new JComboBox (); public SelectItem() { super ("Select Item"); pick.addItemListener(this); pick.addItem("Navigtor"); pick.addItem("Internet Explorer"); pick.addItem("Opera"); pick.setEditable(false); result.setHorizontalAlignment(SwingConstants.CENTER); result, setEditable (false); pane.setLayout(new BorderLayout()); 【12】 pane.add(pick,"Center"); pane.add(result,"South"); setContentPane(pane); } public void itemStateChanged(ItemEvent evt) { Object source = evt.getSource(); if(source == pick) {Object newPick = evt.getItem();result .setText(newPick.toString()+" is the selection. "); } repaint(); }
参考答案: