2011.04.22

eyelashesnectarineSoftware and s/w Development

Nov 3, 2013 (3 years and 8 months ago)

64 views

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