第8章图形用户界面 GUI基础
第8章 图形用户界面 ——GUI 基础
8.1文件类File 8.2运用try、catch、finally处理异常 8.3运用throw抛出异常 8.4运用throws声明异常
8.1 文件类File 8.2 运用 try 、catch 、 finally 处理异常 8.3 运用 throw 抛出异常 8.4 运用 throws 声明异常
Motivations 本章介绍Java GUI程序设计的基础知识
Motivations 本章介绍 Java GUI 程序设计的基础知识
Creating GUI Objects /Create a button with text OK JButton jbtoK new JButton ("OK"); /Create a label with text "Enter your name: JLabel jlblName new JLabel("Enter your name:") Display GUI Components -▣x OK Enter your name:Type Name HereBold RedRed Red Green Blue /Create a text field with text "Type Name Here" JTextField jtfName new JTextField("Type Name Here"); /Create a check box with text bold JCheckBox jchkBold new JCheckBox("Bold"); /Create a radio button with text red JRadioButton jrbRed new JRadioButton("Red"); /Create a combo box with choices red,green,and blue JComboBox jcboColor new JComboBox(new String[]{"Red", "Green","Blue"});
Creating GUI Objects // Create a button with text OK JButton jbtOK = new JButton("OK"); // Create a label with text "Enter your name: " JLabel jlblName = new JLabel("Enter your name: "); // Create a text field with text "Type Name Here" JTextField jtfName = new JTextField("Type Name Here"); // Create a check box with text bold JCheckBox jchkBold = new JCheckBox("Bold"); // Create a radio button with text red JRadioButton jrbRed = new JRadioButton("Red"); // Create a combo box with choices red, green, and blue JComboBox jcboColor = new JComboBox(new String[]{"Red", "Green", "Blue"}); Button Label Text field Check Box Radio Button Combo Box
Swing vs.AWT GUI API包含的类可以分成三个组:组件类( component class.)、容器类(container class)和 辅助类(helper class)
Swing vs. AWT GUI API包含的类可以分成三个组:组件类( component class)、容器类(container class)和 辅助类(helper class)