tailieunhanh - Lecture Software construction - Lab 8: Java programming with SWING GUI builder
In this chapter, the following content will be discussed: JButton, JLabel; JTextField, JTextArea; JCheckBox, JRadioButton; ButtonGroup; icon/imageicon; JScrollPane; JFileChooser; JColorChooser; JMenuItem; JCheckBoxMenuItem/JRadioButtonMenuItem; JComboBox. | Software Construction LAB 08 Java Programming with SWING GUI Builder JButton, JLabel The most common component— a button is a clickable onscreen region that the user interacts with to perform a single command A text label is simply a string of text displayed on screen in a graphical program. Labels often give infor- mation or describe other components public JButton(String text) public JLabel(String text) Creates a new button / label with the given string as its text. public String getText() Returns the text showing on the button / label. public void setText(String text) Sets button / label's text to be the given string. JTextField, JTextArea A text field is like a label, except that the text in it can be edited and modified by the user. Text fields are commonly used for user input, where the user types information in the field and the program reads it A text area is a multi-line text field public JTextField(int columns) public JTextArea(int lines, int columns) Creates a | Software Construction LAB 08 Java Programming with SWING GUI Builder JButton, JLabel The most common component— a button is a clickable onscreen region that the user interacts with to perform a single command A text label is simply a string of text displayed on screen in a graphical program. Labels often give infor- mation or describe other components public JButton(String text) public JLabel(String text) Creates a new button / label with the given string as its text. public String getText() Returns the text showing on the button / label. public void setText(String text) Sets button / label's text to be the given string. JTextField, JTextArea A text field is like a label, except that the text in it can be edited and modified by the user. Text fields are commonly used for user input, where the user types information in the field and the program reads it A text area is a multi-line text field public JTextField(int columns) public JTextArea(int lines, int columns) Creates a new text field that is the given number of columns (letters) wide. public String getText() Returns the text currently in the field. public void setText(String text) Sets field's text to be the given string. A check box is a toggleable button with two states: checked and unchecked A radio button is a button that can be selected; usually part of a group of mutually-exclusive radio buttons (1 selectable at a time) public JCheckBox / JRadioButton(String text) public JCheckBox(String text, boolean isChecked) Creates checked/unchecked check box with given text. public boolean isSelected() Returns true if check box is checked. public void setSelected(boolean selected) Sets box to be checked/unchecked. JCheckBox, JRadioButton ButtonGroup A logical group of radio buttons that ensures that only one is selected at a time public ButtonGroup() public void add(JRadioButton button) The ButtonGroup is not a graphical component, just a logical group; the RadioButtons themselves are added
đang nạp các trang xem trước