Java Reference
In-Depth Information
The HTML file for this program contains the following code:
<HTML>
<HEAD>
<TITLE>TEMPCONVERT APPLET</TITLE>
</HEAD>
<BODY>
<OBJECT code = "TempConvertApplet.class" width = "500"
height = "50">
</OBJECT>
</BODY>
</HTML>
Additional GUI Components
The remainder of this chapter introduces GUI components in addition to those intro-
duced in Chapter 6. For the most part, these additional GUI components are used in the
same way as the ones introduced earlier. For example, you create an instance (or object)
using the operator new . If the program needs to respond to an event occurring in a GUI
component, such as JTextField or JButton , you must add an event listener and
provide the associated method that needs to be invoked, commonly called the event
handler. We will also illustrate the use of various methods of the class Graphics .
JTextArea
The GUI programs in previous chapters extensively used the class JTextField to
display a line of text. However, there are situations when the program must display
multiple lines of text. For example, an employee's address is shown in three or more lines.
Because an object of the class JTextField can display only one line of text, you
cannot use an object of this class to display multiple lines of text. Java provides the class
JTextArea to either collect multiple lines of input from the user or to display multiple
lines of output. Using an object of this class, the user can type multiple lines of text,
which are separated by pressing the Enter key. In Java, each line ends with the newline
character '\n' .
The GUI part of the Student Grade Report programming example in Chapter 10,
(available with the Additional Student Files at www.cengagebrain.com) uses a JTextArea
to display multiple lines of text to show the various courses taken by a student and the
student's grade for each course. This section discusses the capabilities of the class
JTextArea in some detail.
Both JTextField and JTextArea are derived from the class JTextComponent and,
as such, share many common methods. However, you cannot create an instance of the
class JTextComponent because it is an abstract class. Table 12-8 lists some of the
constructors and methods of the class JTextArea .
1
2
 
 
Search WWH ::




Custom Search