Java Reference
In-Depth Information
Sample Run: (Figure 6-6 shows a sample run.)
6
FIGURE 6-6 Sample run for RectangleProgramTwo
Now you are ready to create and place the text fields and buttons. The techniques
for creating and placing components, such as JTextField and JButton ,ina
container are similar to the ones used for JLabel , and are described in the next
two sections.
JTextField
As you may recall, text fields are objects belonging to the class JTextField . Therefore,
you can create a text field by declaring a reference variable of type JTextField followed
by an instantiation of the object.
Table 6-4 describes some of the methods of the class JTextField .
TABLE 6-4 Some Methods of the class JTextField
Method / Description
public JTextField(int columns)
//Constructor to set the size of the text field.
public JTextField(String str)
//Constructor to initialize the object with the text specified
//by str.
 
 
 
Search WWH ::




Custom Search