Xem mẫu

LẬP TRÌNH JAVA CSDL

BÀI 3

COMPONENTS

Nguyễn Hữu Thể

1

Nội dung

 JLabel
 JButton
 JTextField
 JCheckBox
 JRadioButton
 JPanel
 JComboBox, JList

 JTable
 JMenu
 JToolBar
 JOptionPane
 JFileChooser

2

GUI Components
 JButton, JLabel, JTextField, JCheckBox, JRadioButton, and
JComboBox.

 Each GUI component class provides several constructors that
you can use to create GUI component objects.

3

GUI Components
// Create a button with text OK

JButton btOK = new JButton("OK");
// Create a label with text "Enter your name: "
JLabel lbName = new JLabel("Enter your name: ");
// Create a text field with text "Type Name Here"
JTextField txtName = new JTextField("Type Name Here");
// Create a check box with text bold
JCheckBox chkBold = new JCheckBox("Bold");

// Create a radio button with text red
JRadioButton rbRed = new JRadioButton("Red");
// Create a combo box with choices red, green, blue

JComboBox cboColor = new JComboBox(new String[]{"Red",
4
"Green", "Blue"});

Working with Components
 javax.swing.Jcomponent
 Several methods:
 setEnabled(boolean): receive user input (an argument of
true) or is inactive and cannot receive input (false).
Components are enabled by default.
 isEnabled() returns a boolean value.
 setVisible(boolean): for all components. Use true to display
a component and false to hide it.

 isVisible()
 setSize(int, int): width and height specified as arguments
 setSize(Dimension) uses a Dimension

 getSize(): returns a Dimension object with height and width

5

nguon tai.lieu . vn