ButtonGroup cbGroup=new ButtonGroup();//创建单选框 for(int i=0; i<4; i++) { radio[i]=new JRadioButton(Item[i]); p2.add(radio[i]); cbGroup.add(radio[i]); radio[i].addItemListener(this); } c.add(p2); JPanel p3=new JPanel(); p3.setLayout(new FlowLayout()); p3.add(new JLabel(\转换结果:\ JScrollPane sta=new JScrollPane(area); p3.add(sta); p3.setSize(300, 70); c.add(p3); pack(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Dimension screen =
Toolkit.getDefaultToolkit().getScreenSize(); this.setSize(540, 400);
setLocation((int)((screen.getWidth()-getWidth())/2),(int)((screen.getHeight()-getHeight())/2)); } public void itemStateChanged(ItemEvent e) { if(TF.getText()==null || TF.getText().equals(\ int x=0; try{ x=Integer.parseInt(TF.getText()); }catch(Exception e3){x=0;} if(radio[0].isSelected()) area.append (\整数\的\为: \Integer.toBinaryString(x)+\ if (radio[1].isSelected()) area.append (\你选择的是\为: \Integer.toOctalString(x)+\ if (radio[2].isSelected()) area.append (\你选择的是\为: \ if (radio[3].isSelected()) area.append (\你选择的是\为:
\ } public static void main(String[] args) { MyComputer app=new MyComputer(); app.setVisible(true); } } ¨ 编译运行程序。
四、思考题
1. 什么是Java GUI的组件?Java组件事件处理模型的三个基本要素是什么?Java组件事件处理方式有那些?。