<html>
<head>
<title>HTMLTest</title>
</head>
<body>
<H1>
<font color= #557055>
An applet with code and document in
adjacent sub-sub-directories
</font color>
</H> <BR><BR>
<applet code=AppT.class codebase=../../C/C2
width=300 height=175>
</applet>
</body>
</html>
A Note on the Codebase tag in two forms first taking a relative path and then a URL The HTML page above was put in H2 directory, in H directory in P directory.The Applet code was put in C2 directory in C directory in P directory as per the Fig. 1 Directory Tree Fig.1 DirectoryTree P
The first form uses the url for a file on the local machine
Both forms of the Tag worked when tested in Netscape 4.6 and Explorer 5
|
This note refers to what happens on my PC. On the server
which provided you this page the same directory structure was created however
P would now refer to the user, public directory. The relative path
is still accurate though the URL reference would change to a http
protocol form. ie http://www.sentex.net/~pkomisar/C/C2
or a file protocol referenced within the server directory |
import java.awt.*;
import java.applet.*;
public class AppT extends Applet {
public void init(){
setBackground(Color.gray);
//component not graphic's methods
setForeground(Color.white);
}
public void paint (Graphics g) {
// A Dimension object contains width and height variables and is returned
by getSize( )
Dimension d=getSize();
//set font before the string you want to effect
g.setFont(new Font("Helvitica",Font.PLAIN,20));
g.drawString("Gray's Variety",40,55);
g.setColor(Color.yellow);
g.draw3DRect
(d.width-( d.width-15),
d.height-(d.height-15), d.width-30, d.height-30, true );//see
below *
// note when the window is resized the rectangle
with relative values resizes with it
g.setColor(Color.red);
g.draw3DRect(12,12,276,76,true);
}
}
* This line of code is pretty awful
g.draw3DRect( d.width-(d.width-15) , d.height-(d.height-15) , d.width-30 , d.height-30 , true );
For reading and clarity it would be be better written as follows.
// Upper left x,y coordinates;
int upperLeft_X = d.width - (d.width - 15);
int upperLeft_Y = d.width - (d.width - 15);
// width of border box is width and height less
30 each
int w = d.width - 30;
int h = d.height - 30;
// raised is signalled by the boolean value 'true'
and the expression becomes
boolean raised = true;
g.draw3DRect(upperLeft_x, upperLeft_y, w , h , raised );
The downside is you are trading six lines of
code for one, not including comments.