To help with exercises and to provide a quick way to test code
snippets in the following chapters, we provide a set of prepackaged
programs with which you can begin to write a program rather than
starting from scratch each time.
These starter programs (our terminology), like the ones
shown below, can run by themselves but accomplish very little. Instead,
you insert example snippets or your own code to make them do something
interesting. The starters allow you to concentrate on the particular
topic of interest rather than taking the time to writing a whole
program
For example, we show here the application program StartApp1:
StartApp1.java |
public
class
Start_App1
{
public
static void main (String args[])
{
//
Put code between this line
//----------------------------
//----------------------------
// and this line.
}
}
|
Insert
the example codes or your exercise code between these lines.
|
We also provide starters for applets. At this early
stage, however, before we discuss Java graphics, we will just
send output to the browser's Java
console and only paint a brief text message in the
browser window .
StartApplet1.java |
public
class
Start_Applet1 extends
java.applet.Applet
{
public void init ()
{
//
Put code between this line
//----------------------------
//----------------------------
// and this line.
}
// Paint text in the applet window.
public void paint (java.awt.Graphics
g)
{
g.drawString ("Start_Applet1",10,20);
}
}
|
We will
learn later
how user applets
inherit the Applet
class.
The browser always calls init()to let the applet do initialization
tasks.
Insert the example codes or your exercise program between
these lines.
Paint a simple message in the applet window.
|
The Codes
List describes each of the starter applications and applets.
We recommend that you give each example program
a unique class name, e.g. starting from StartApp1.java
create class
XApp1 in file XApp1.java.
In the comments at the top of our classes, we will indicate what
starter we used.
References & Web Resources
Latest update: Oct. 14, 2004
|