![]() |
Sample Code
The following code is a portion of a simple applet that I will use to demonstrate the 4 major types of objects in Java and their methods. Click on each link to reveal a popup description of what that portion of the code is about. I have seperated the sections by color. Some colors have an brief comment enclosed in the official commented out symbols of /* comments */ and then a clickable explanation that goes into greater detail. On other colors, the code itself is clickable.
/* This portion of the code in green imports the needed packages and classes to be used in the applet. See explanation*/
import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;
import java.awt.Image;
import java.applet.*;
public class Example1 extends java.applet.Applet implements Cloneable {
/*This portion of the code in red names the variables for class Example1. See explanation.*/
/*This portion of the code in purple names the submethods for the method paint() The first 9 lines are for drawing 3 strings of text. See explanation.*/
/*This portion of the code in gray is a continuation of the paint() method and draws a simple smiley face graphic and for placing a jpg image on the screen. See explanation.*/
/*This portion of the code in maroon overides the automatic method init() to add new qualities to the init method. See explanation.*/
}
So, this is the source code, the .java file that you write in your text editor. When you compile the above code it looks like this in a text editor(sample portion only):

You also need to write some html code to call this applet much like you would write html code to call an image. Here is the html code for this applet:

And finally here is the output of the simple applet I wrote:
Grading
Schedule
Syntax
JavaDocs
Video
Projects
Links