Java Reference
In-Depth Information
fTextOutput.setBackground (Color.LIGHT - GRAY);
fTextOutput.setEditable (false);
// The grid fills the 3 columns sequentially.
content - pane.add (buttons - panel);
content - pane.add (fInputsPanel);
content - pane.add (fTextOutput);
} // init
} // class MultiPanelApplet
/** JPanel subclass with two buttons. **/
class ActionButtonsPanel extends JPanel
{
ActionButtonsPanel () {
// Create two buttons
JButton add - but = new JButton ("Add");
JButton mult - but = new JButton ("Mult");
// Put a button in each grid cell
add (add - but);
add (add - but);
} // ctor
} // class ActionButtonsPanel
Figure 6.4(b) shows the resulting display. These components now comprise a user
interface with text fields for user input, buttons to control the operation, and a
text area to display the results of the operations. The program only lacks the event
handling that we add in the next chapter.
6.5.3 Text display
In the previous section we introduced three text related components. The
JLabel component is a static component for labeling items on the interface.
JTextField and JTextArea provide for both the display and input of text.
JTextField displays a single line of text while JTextArea can display mul-
tiple lines.
In the previous chapters our example programs sent their output to the Java
console with the print methods available with the System.out object. We now
show how to use a JTextArea to display text in a fashion similar to the Java
console but on a graphical interface. We put the JTextArea component on a
JPanel subclass, which we name TextOutputPanel .Wealso put it into a
JScrollPane, which is a Swing component that provides scroll bars when text
goes beyond the boundaries.
 
Search WWH ::




Custom Search