Java demo: How it works ************************** import java . . . . . This is the equivalent of #import in C or Uses in Pascal - tells the compiler what extra information is needed to compile the program. public class banner extends java.applet.Applet{ 1. The main class MUST have the same name as the file. 2. Unlike C/Pascal, file names ARE case sensitive 3. The main class MUST be declared "public" so that the browser can load it. 4. ALL Java code for a browser will "extend" (i.e. be derived from) the base class, java.applet.Applet String StrLine[]= new String[1]; Font appFont; Java has built in String functions and the first line creates a new, empty, string in memory. appFont is a variable of type Font. (Pascal note: the keyword var is not accepted.) public void paint(Graphics g){ FontMetrics fm; fm=g.getFontMetrics(appFont); Rectangle r = bounds(); g.setColor(Color.red); g.setFont(appFont); g.drawString(StrLine[0], (r.width - fm.stringWidth(StrLine[0]))/2, (r.height - fm.getHeight())/2); stop(); } } paint has similar functions to Paint under Windows. FontMetrics too is similar, containing details of the measurements of the current font. Rectangle is self-explanatory. Note that bounds() is pre-defined within Java as returning the bounds of the applet as a rectangle. drawString needs to be told where to draw the text. Rectangle includes two members, width and height. FontMetrics also contains two measurements, stringWidth(String) and getHeight(). Note that r.width is a variable but fm.getHeight() is a function (similar to a Pascal procedure). stop(); just notifies the browser that the applet has completed and the document can now be shown as "Done.".