JButton属性 ■text ■icon mnemonic horizontalAlignment verticalAlignment horizontalTextPosition verticalTextPosition ©2006计算机系杨厚群 All rights lefts reserved
©2006 计算机系 杨厚群 All rights & lefts reserved. JButton 属性 text icon mnemonic horizontalAlignment verticalAlignment horizontalTextPosition verticalTextPosition
JButton事件响应 public void actionPerformed(ActionEvent e) f /Get the button label String actionCommand e.getActionCommand(); /Make sure the event source is a button if (e.getSource()instanceof JButton) /Make sure it is the right button if (My Button".equals (actionCommand) System.out.println (Button pressed!); } ©2006计算机系杨厚群 All rights lefts reserved
©2006 计算机系 杨厚群 All rights & lefts reserved. JButton 事件响应 public void actionPerformed(ActionEvent e) { // Get the button label String actionCommand = e.getActionCommand(); // Make sure the event source is a button if (e.getSource() instanceof JButton) // Make sure it is the right button if ("My Button".equals(actionCommand) System.out.println ("Button pressed!"); }
JLabel label是短文本或图像的显示区域,没有修饰,不响应 用户输入。下面是非缺省的labels构造函数: JLabel(String text,int horizontalAlignment) JLabel(String text) JLabel(Icon icon) JLabel(Iconicon,int horizontalAlignment) 范例:使用Labels 源码 ©2006计算机系杨厚群 All rights lefts reserved
©2006 计算机系 杨厚群 All rights & lefts reserved. label 是短文本或图像的显示区域,没有修饰,不响应 用户输入。下面是非缺省的 labels 构造函数: JLabel(String text, int horizontalAlignment) JLabel(String text) JLabel(Icon icon) JLabel(Icon icon, int horizontalAlignment) 范例:使用 Labels 源码 JLabel
JLabel属性 text ■1con horizontalAlignment verticalAlignment ©2006计算机系杨厚群 All rights lefts reserved
©2006 计算机系 杨厚群 All rights & lefts reserved. text icon horizontalAlignment verticalAlignment JLabel 属性
JTextField text field允许用户输入字符 范例:使用Text Fields 源码 ©2006计算机系杨厚群 All rights lefts reserved
©2006 计算机系 杨厚群 All rights & lefts reserved. text field 允许用户输入字符 范例: 使用 Text Fields 源码 JTextField