Java Reference
In-Depth Information
This applet creates an instance of the InputsPane l class, shown below, and adds
it to the content pane. Using JPanel subclasses like InputsPanel allows for
aflexible modular approach to graphical interface building.
import java.awt.*;
import javax.swing.*;
/** Panel to hold input text fields. **/
public class InputsPanel extends JPanel
{
JTextField fTextfieldTop;
JTextField fTextfieldBot;
/** Constructor builds panel with labels and text
* fields.
**/
InputsPanel (String label - strtop, String init - top,
String label - str - bot, String init - bot) {
// Set the layout with 2 rows by 2 columns
setLayout (new GridLayout (2, 2));
// Create two text fields with the initial values
fTextfieldTop = new JTextField (init - top);
fTextfieldBot = new JTextField (init - bot);
// Create the first label and right justify the text
JLabel label - top =
new JLabel (label - str - top, SwingConstants.RIGHT);
// Insert the label and textfield into the top grid
// row
add (label - top);
add (fTextfieldTop);
// Create the second label and right justify the text
JLabel label - bot =
new JLabel (label - str - bot, SwingConstants.RIGHT);
// Insert the second label and textfield into
// the bottom grid row
add (label - bot);
add (fTextfieldBot);
} // ctor
} // class InputsPanel
 
Search WWH ::




Custom Search