Java Reference
In-Depth Information
JPanel pricePanel = new JPanel(); // Uses
FlowLayout
pricePanel.add(new JLabel("Your Price:"));
pricePanel.add(priceTextField);
JPanel centerPanel = new JPanel(); // Uses
FlowLayout
centerPanel.add(radioButtonPanel);
centerPanel.add(checkBoxPanel);
// Frame uses BorderLayout by default
add(centerPanel, BorderLayout.CENTER);
add(pricePanel, BorderLayout.SOUTH);
Of course, you also need to add event handlers to the components. That is the
topic of How To 10.1.
P RODUCTIVITY H INT 18.1: Use a GUI Builder
As you have seen, implementing even a simple graphical user interface in Java is
quite tedious. You have to write a lot of code for constructing components, using
layout managers, and providing event handlers. Most of the code is boring and
repetitive.
A GUI builder takes away much of the tedium. Most GUI builders help you in
three ways:
ȗ You drag and drop components onto a panel. The GUI builder writes the
layout management code for you.
ȗ You customize components with a dialog box, setting properties such as
fonts, colors, text, and so on. The GUI builder writes the customization
code for you.
ȗ You provide event handlers by picking the event to process and providing
just the code snippet for the listener method. The GUI builder writes the
boilerplate code for attaching a listener object.
801
802
Java 6 introduced GroupLayout , a powerful layout manager that was
specifically designed to be used by GUI builders. The free NetBeans
Search WWH ::




Custom Search