Java Reference
In-Depth Information
In Swing, this is no longer in vogue. The same effect is obtained by extending
JPanel and overriding the public method
void paintComponent( Graphics g );
Although this works for any component, by using a JPanel of a preferred size, one
can avoid having any painting run over the boundary of the “canvasing area.”
JTextField and JTextArea s
A JTextField is a component that presents the user with a single line of text. A
JTextArea allows multiple lines and has similar functionality. Thus only
JTextField is considered here. By default, the text can be edited by the user,
but it is possible to make the text uneditable. In Figure B.1, there are three
JTextField objects: two for the coordinates and one, which is not editable by
the user, that is used to communicate error messages. The background color
of an uneditable text field differs from that of an editable text field. Some of
the common methods associated with JTextField are
A JTextField is a
component that
presents the user
with a single line of
text. A JTextArea
allows multiple lines
and has similar
functionality.
JTextField( );
JTextField( int cols );
JTextField( String text, int cols );
String getText( );
boolean isEditable( );
void setEditable( boolean editable );
void setText( String text );
A JTextField is constructed either with no parameters or by specifying
initial optional text and the number of columns. The setEditable method
can be used to disallow input into the JTextField . setText can be used to
print messages into the JTextField , and getText can be used to read from the
JTextField .
basic principles
B.3
This section examines three important facets of AWT programming: first, how
objects are arranged inside a container, followed by how events, such as but-
ton pushing, are handled. Finally, it describes how graphics are drawn inside
canvas objects.
 
 
Search WWH ::




Custom Search