Strings
?sequences of characters treated as an object
We have already
met and used strings. Consider this application program:
class ProgramMessage
{
public
static void main( String args[])
{
System.out.println("This application is running");
}
}
The following output
is produced:
We are passing
a string as a message argument:
System.out.println("This
application is running");
The string itself
is:
"This application
is running"
A
string is a sequence of characters treated as a single object. String objects
are instance of the String class.
Applet example
using a String object
Just
as the simple Java application above displays a String object to the console,
we have also encountered String objects being drawn onto the graphics object
of an Applet window:
// <APPLET
code="DrawStringApplet.class" width=275 height=100></APPLET>
import java.applet.Applet;
import java.awt.*;
public class
DrawStringApplet extends Applet
{
// methods
public
void paint( Graphics g )
{
g.drawString( "This applet is running", 100, 30 );
}
} // class
When compiled and
run with the appletviewer:
the screen should
look as follows:

In this example
the string "This
applet is running"is
passed as an argument when the message:
drawString(
"This applet is running", 100, 30 );
is send to theGraphicsobject
g:
g.drawString(
"This applet is running", 100, 30 );
Back
to top
RITSEC - Global Campus
Copyright © 1999 RITSEC- Middlesex
University. All rights reserved.
webmaster@globalcampus.com.eg
|