Vertical Text positions Vertical text position specifies the vertical position of the text relative to the icon You can set the vertical text position using one of the three constants TOP CENTER The default vertical text position is Swing Constants. CENTER TOP X CENTER ×B0TT Grapes Grapes Grapes Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 16 Vertical Text Positions ⚫Vertical text position specifies the vertical position of the text relative to the icon. ⚫You can set the vertical text position using one of the three constants: TOP, CENTER. The default vertical text position is SwingConstants.CENTER
Example 13.1: Using Buttons Write a program that displays a message on a panel and uses Buttondemo two buttons. < and => to move the message on the panel to the Run left or right &5 Button Demo _ Welcome to java MessagePanel JButton setMnemonic(using alt key) get Source to judge the source UI Liang, Introduction to Java Programming, rewsed by Dai-kalyl
Liang,Introduction to Java Programming,revised by Dai-kaiyu 17 Example 13.1: Using Buttons Write a program that displays a message on a panel and uses two buttons, <= and =>, to move the message on the panel to the left or right. Run ButtonDemo JButton JButton MessagePanel setMnemonic (using alt key) getSource() to judge the source UI
Checkbox J Box inherits all the properties such as text, icon mnemonic. verticalAlignment, horizontalAlignment horizontalTextPosition. verticalTextPosition, and selected from AbstractButton, and provides several constructors to create check boxes I javax. swing. AbstractButton L javax. swing JToggle Button javax. swing JCheck Box JCheck Boxo Creates a default check box button with no text and icon JCheck Box(text: String) Creates a check box with text JCheck Box(text String, selected Creates a check box with text and specifies whether the check box is initially selected JCheck Box(icon: Icon Creates a check box with an icon JCheckBox( text: String, icon: Icon) Creates a checkbox with text and an icon JCheckBox( text: String, icon: Icon Creates a check box with text and an icon, and specifies whether the check selected: boolean) box is initially selected Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 18 JCheckBox JCheckBox inherits all the properties such as text, icon, mnemonic, verticalAlignment, horizontalAlignment, horizontalTextPosition, verticalTextPosition, and selected from AbstractButton, and provides several constructors to create check boxes. 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) Creates a default check box button with no text and icon. Creates a check box with text. Creates a check box with text and specifies whether the check box is initially selected. Creates a checkbox with an icon. Creates a checkbox with text and an icon. Creates a check box with text and an icon, and specifies whether the check box is initially selected. javax.swing.AbstractButton javax.swing.JToggleButton
Example(13.2: Using Check Boxes Add three check boxes named CheckBoxDemo Centered. Bold. and italic into v Centered Wecome to java v Bold Example 13.1 to let the user v Italic specify whether the message Left Right is centered bold or italic ButtonDemo CheckBoxdemo Run Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 19 Example 13.2: Using Check Boxes Add three check boxes named Centered, Bold, and Italic into Example 13.1 to let the user specify whether the message is centered, bold, or italic. CheckBoxDemo Run ButtonDemo CheckBoxDemo
RAdiobutton Radio buttons are variations of check boxes They are often used in the group where only one button is checked at a time L javax. swing. Abstract Button J javax.swing TOggle Button Javax. swing RAdiobUtton RAdiobutton Creates a default radio button with no text and icon RAdiobUtton( text: String) Creates a radio button with text RAdiobutton( text: String, selected Creates a radio button with text and specifies whether the radio button is boolean) nitially selecte RAdiobUtton(icon Icon Creates a radio button with an icon JRadioButton(text: String, icon: Icon) Creates a radio button with text and an icon JRadioButton(text: String, icon: Icon, Creates a radio button with text and an icon, and specifies whether the radio selected: boolean) button is initially selected Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 20 JRadioButton Radio buttons are variations of check boxes. They are often used in the group, where only one button is checked at a time. javax.swing.JRadioButton +JRadioButton() +JRadioButton(text: String) +JRadioButton(text: String, selected: boolean) +JRadioButton(icon: Icon) +JRadioButton(text: String, icon: Icon) +JRadioButton(text: String, icon: Icon, selected: boolean) Creates a default radio button with no text and icon. Creates a radio button with text. Creates a radio button with text and specifies whether the radio button is initially selected. Creates a radio button with an icon. Creates a radio button with text and an icon. Creates a radio button with text and an icon, and specifies whether the radio button is initially selected. javax.swing.AbstractButton javax.swing.JToggleButton