Java
@Ch17. Creating Graphical User Interfaces
2011.04.22
Outline
•
Swing GUI components
•
Buttons
•
Button Alignments
•
CheckBox
[Sample code]
TestButtonIcons.java
、
TestCheckBox.java
Swing GUI components
(
課本
p.596)
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
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)
程式範例
:
TestButtonIcons.java
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)
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)
程式範例
:
TestCheckBox.java
程式練習
:
Programming Exercises 17.2
Enter the password to open this PDF file:
File name:
-
File size:
-
Title:
-
Author:
-
Subject:
-
Keywords:
-
Creation Date:
-
Modification Date:
-
Creator:
-
PDF Producer:
-
PDF Version:
-
Page Count:
-
Preparing document for printing…
0%
Comments 0
Log in to post a comment