Download presentation
Presentation is loading. Please wait.
1
Java @Ch17. Creating Graphical User Interfaces 2011.04.22
2
Outline Swing GUI components Buttons Button Alignments CheckBox [Sample code] TestButtonIcons.java 、 TestCheckBox.java
3
Swing GUI components ( 課本 p.596)
4
Buttons JButton inherits AbstractButton Defined in javax.swing.AbstractButton javax.swing.AbstractButton -actionCommand: String -text: String -icon: javax.swing.Icon -pressedIcon: javax.swing.Icon -rolloverIcon: javax.swing.Icon -mnemonic: int -horizontalAlignment: int -horizontalTextPosition: int
5
javax.swing.JButton +JButton() +JButton(icon: javax.swing.Icon) +JButton(text: String) +JButton(test: String, icon: Icon) +addActionListener(listener: ActionListener) : void javax.swing.AbstractButton ( 課本 p.597)
6
程式範例 : TestButtonIcons.java
7
Button Alignments Horizontal alignment: ( 調校按鈕 icon 及 text 水平位置 ) LEADING 、 LEFT 、 CENTER 、 RIGHT 、 TRAILING Ex:.setHorizontalAlignment(SwingConstants.CENTER) Vertical alignment: ( 調校按鈕 icon 及 text 垂直位置 ) TOP 、 CENTER 、 BOTTOM Ex:.setVerticalAlignment(SwingConstants.CENTER)
8
CheckBox javax.swing.JCheckBox +JCheckBox() +JCheckBox(text: String) +JCheckBox(text: String, selected: boolean) +JCheckBox(icon: Icon) +JCheckBox(text: String, icon: Icon) +JCheckBox(text: String, icon: Icon, selected: boolean) +addActionListener(listener: ActionListener): void +addItemListener(listener: ItemListener): void javax.swing.JToggleButton javax.swing.AbstractButton ( 課本 p.602)
9
程式範例 : TestCheckBox.java
10
程式練習 : Programming Exercises 17.2
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.