Java Reference
In-Depth Information
￿ JRadioButton rb = new JRadioButton("Increment",true);
Creates a new ra-
dio button that is selected and has label Increment .
￿ rb.isSelected()
True if the radio button is selected.
Adds an action listener to the radio button. When
the radio button is changed, the actionPerformed method of the a object will be
called.
￿
rb.addActionListener(a);
Creates a button group. At most one ra-
dio button in a button group can be pressed at any time.
￿
ButtonGroup b = new ButtonGroup();
￿
b.add(rb);
Add the radio button rb to the button group b .
￿
JDialog db = new JDialog(owner, "About", true);
Creates a new dialog box.
The variable owner refers to the owner window of the dialog box. The text About is
the title of the dialog box. The last parameter means that the dialog box is modal.
￿ JPasswordField pf = new JPasswordField("", 10);
Creates a password field
of size 10 characters.
￿ char[] password = pf.getPassword();
Returns the password that is typed in
the password field.
￿ int i = Double.parseDouble(s);
Converts the string s to a double. If the con-
version fails, then an exception is raised.
￿ int i = Integer.parseInt(s);
Converts the string s to an integer. If the con-
version fails, then an exception is raised.
Returns the source of the e event.
￿
e.getSource
12.15 Important Points
1. A window can contain multiple panels. Every panel, in turn, can contain multiple
panels.
2. In a flow layout, the components are arranged in rows from top to bottom in the
surrounding container.
3. In a border layout, the components are placed in the south, east, north, west, and
center of the container. One can place only one component in each of the five areas.
4. In a grid layout, the components are placed in a grid. When adding components, they
fill the grid from top to bottom. The first row is filled from left to right as are the
successive rows.
5. The JTextField and JTextArea classes are similar. However, the first class should
be used to display a single user input line, while the second class should be used to
display an area that contains multiple user input lines.
 
Search WWH ::




Custom Search