Java Reference
In-Depth Information
￿ getCodeBase()
Returns a URL object of the code base directory.
Creates a URL that
points to the file x.jpg of the subdirectory images of the code base directory.
URL url = new URL(getCodeBase(), "images/x.jpg");
Reads the image from the URL and saves
Image image =;
it in the image object.
￿ g2.drawImage(oImage, x,y, w, h, null);
Draws an image with the specified
dimensions. The point (x,y) is the top left corner of the image, while w and h are the
width and height of the image, respectively.
￿ paint(Graphics g) {
Replaces the paintComponent method for drawing
in a JApplet .
JOptionPane.showMessageDialog( ... , "I win!");
Shows the message I win!
in a dialog box. The first parameter is a reference to the parent window.
￿ <HTML> ... </HTML>
Start and end of an HTML file.
￿ <HEAD> ... </HEAD>
Creates the HEAD part of an HTML document.
Sets the title of the document to be
￿ <H3> ... </H3>
Creates text with size H3.
￿ <P> ... </P>
Creates a paragraph that is separated by lines.
15.7 Important Points
1. When Java files are compiled, Java binary code is created in the form of .class files.
For an applet, these files are shipped and executed at the client. The client must have
the Java Virtual Machine (JVM) software to execute the .class files.
2. An applet does not have a main method. Instead, it overrides the init method of the
JApplet class.
3. The code of a Java Applet cannot set applet title, size, location, and so on. All these
parameters are set in the HTML file.
4. Only the web browser can close an applet. Therefore, an applet should not have code
that terminates the applet.
5. Use the codebase property to define the directory of the .class files. Resource files,
such as images, can be created in a subdirectory of the codebase directory.
6. The HTML code <APPLET codebase="classes" code="TicTacToe.class" width
= 350 height=200></APPLET> inserts an applet with code base directory classes
(relative to the directory that contains the .html file). The code of the applet is in
the file TicTacToe.class . The applet will be displayed in a 350 x 200 pixels rectan-
gular area inside the web browser.
Search WWH ::

Custom Search