第11章图形用户界面 ava 111GU组件简介 112程序框架 113事件处理 114布局管理器 115基本Swng组件 116高级Swng组件 11.7习题
第11章 图形用户界面 11.1 GUI组件简介 11.2 程序框架 11.3 事件处理 11.4 布局管理器 11.5 基本Swing组件 11.6 高级Swing组件 11.7 习题
111GUⅠ组件简介 ava java. lang obi wt.compoNent Container wing组件 javax. swing.JComponent Window Applet AbstractButton JTextComponent F1 Dialog JApplet MEnuitem JButton JTextArea Fram JDialo CheckBoxMenultem TOggle Button JE qitorPane RAdio Button menuitem RAdio Button JTextField PAssword Field JMenu JCheck Box FIle chooser、 IColorchooser、 MTree.. JPanel、 JLabel、 COmbo Box、 JList、 JMenu bar、 POpupmEnu、 JOptionPane、 JScrllPane、 JSlider、 JProgressBar
11.1 GUI组件简介 java.lang.Object java.awt.Component Container Panel javax.swing.JComponent Window Applet JApplet Frame Dialog JFrame JDialog JTextComponent Swing组件 AbstractButton JMenuItem JButton JToggleButton JCheckBox JRadioButton JCheckBoxMenuItem JMenu JRadioButtonMenuItem JEditorPane JTextArea JTextField JPasswordField JPanel、JLabel、JComboBox、JList、JMenuBar、JPopupMenu、JOptionPane、JScrllPane、JSlider、JProgressBar JFileChooser、JColorChooser、JTree
112程序框架 ava 要创建一个图形用户界面,首先需要创 建一个特殊的窗口来容纳用户界面组件。 Java语言中,这个特殊的窗口一般是 个应用程序框架或 applet
11.2 程序框架 要创建一个图形用户界面,首先需要创 建一个特殊的窗口来容纳用户界面组件。 Java语言中,这个特殊的窗口一般是一 个应用程序框架或applet
11.2.1创建应用程序框架l JFrame的构造方法: public jFrame( //创建一个没有标题的框架 public jFrame(string title) /创建一个带有指定标题的框架 例11-1创建应用程序框架 源代码
11.2.1 创建应用程序框架 JFrame的构造方法: – public JFrame() //创建一个没有标题的框架 – public JFrame(String title) //创建一个带有指定标题的框架 例11-1 创建应用程序框架 源代码 运 行
1122添加组件 ava 例11-2添加组件 源代码 运行 例11-3直接调用方法ada()添加组件 源代码 运
11.2.2 添加组件 例11-2 添加组件 例11-3 直接调用方法add()添加组件 源代码 运 行 源代码 运 行
11.3.1事件和事件源 ava java. lang Object javautil. EventObject ListSelection Event java.awt. AWTEvent Change Event ActionEvent Container Event Adjustment Event FocusEvent KeyEvent Componentevent nputEvent Item event Paint event Mouse event WindowEvent Textevent
11.3.1 事件和事件源 java.lang.Object java.util.EventObject java.awt.AWTEvent ActionEvent AdjustmentEvent ComponentEvent ItemEvent TextEvent FocusEvent InputEvent WindowEvent ContainerEvent PaintEvent KeyEvent MouseEvent ListSelectionEvent ChangeEvent
113.1事件和事件源(续)b JButton 点击按钮 Actionevent JTextField在文本域按回车键 Actionevent CHeckbox 点击复选框 ActionEvent itemEvent RAdiobUtton点击单选按钮 ActionEvent itemEvent COmboboxⅹ 选定选项 Actionevent itemEvent LIst 选定选项 ListselectionEvent MEnuitem 选定菜单项 Actionevent itemevent JSlider 滑动滑块 ChangeEvent Window 窗口打开、关闭等 Windowevent Component 点击或移动鼠标 Mouseevent Component 按下或释放键 KeyEvent Container 在容器中添加或删除组件 Containerevent Component 组件获得或失去焦点 FocusEvent Component 组件移动、改变大小等 Componentevent
11.3.1 事件和事件源(续) JButton 点击按钮 ActionEvent JTextField 在文本域按回车键 ActionEvent JCheckBox 点击复选框 ActionEvent、ItemEvent JRadioButton 点击单选按钮 ActionEvent、ItemEvent JComboBox 选定选项 ActionEvent、ItemEvent JList 选定选项 ListSelectionEvent JMenuItem 选定菜单项 ActionEvent、ItemEvent JSlider 滑动滑块 ChangeEvent Window 窗口打开、关闭等 WindowEvent Component 点击或移动鼠标 MouseEvent Component 按下或释放键 KeyEvent Container 在容器中添加或删除组件 ContainerEvent Component 组件获得或失去焦点 FocusEvent Component 组件移动、改变大小等 ComponentEvent
11.3.2事件监听器(续)闆 Actionevent Actionlistener actionPerformed(ActionEvent e) addActionlistener( ItemEvent Itemlistener itemStateChanged(itemEvent e) addItemListener ( Mouseevent Mouselistener mouseClicked( MouseEvent addMouselistener( mousePressed (mouseevent e) mouseRe leased(Mouse Event e) mouseEntered ( mouseevent e) mouseExited (Mouse Event e) louseEvent MouseMotionlistener louseDragged (MouseEvent e) addMouseMotionListener( mouseMoved (MouseEvent e) dowOpened(WindowEvent e) addwindowListener ( windowClosing (Window Event e) windowClosed (Window Event e) windowIconified(WindowEvent e) fied(WindowEvent e) windowActivated(windowEvent e) windowDeactivated(WindowEvent e) ListselectionEvent ListselectionListener value Changed (listselectionEvent e addListselectionListener (
11.3.2 事件监听器(续) ActionEvent ActionListener actionPerformed(ActionEvent e) addActionListener() ItemEvent ItemListener itemStateChanged(ItemEvent e) addItemListener() MouseEvent MouseListener mouseClicked(MouseEvent e) addMouseListener() mousePressed(MouseEvent e) mouseReleased(MouseEvent e) mouseEntered(MouseEvent e) mouseExited(MouseEvent e) MouseEvent MouseMotionListener mouseDragged(MouseEvent e) addMouseMotionListener() mouseMoved(MouseEvent e) WindowEvent WindowListener windowOpened(WindowEvent e) addWindowListener() windowClosing(WindowEvent e) windowClosed(WindowEvent e) windowIconified(WindowEvent e) windowDeiconified(WindowEvent e) windowActivated(WindowEvent e) windowDeactivated(WindowEvent e) ListSelectionEvent ListSelectionListener valueChanged(ListSelectionEvent e) addListSelectionListener()