Ms Gold

2/13

Introduction to Object Oriented Programming

Lesson Plan 18 - Java Application vs Java Applet

 

Mass Framework:

Standard 1:

Standard 2:

Standard from Technology/Engineering Standards for a Full First-Year Course in Grades 9 or 10

Learning Objective: To try to grapple with the issues surrounding the future of digital media brought to light by the recent storm of WikiLeaks activities.

Learning Experience:

The init Method: The init method is called when the applet is first created and loaded by the underlying software. This method performs one-time operations the applet needs for its operation such as creating the user interface or setting the font. In the example, the init method initializes the text string and sets the background color.

The start Method: The start method is called when the applet is visited such as when the end user goes to a web page with an applet on it. The example prints a string to the console to tell you the applet is starting. In a more complex applet, the start method would do things required at the start of the applet such as begin animation or play sounds.

After the start method executes, the event thread calls the paint method to draw to the applet's Panel. A thread is a single sequential flow of control within the applet, and every applet can run in multiple threads. Applet drawing methods are always called from a dedicated drawing and event-handling thread.

The stop and destroy Methods: The stop method stops the applet when the applet is no longer on the screen such as when the end user goes to another web page. The example prints a string to the console to tell you the applet is stopping. In a more complex applet, this method should do things like stop animation or sounds.

The destroy method is called when the browser exits. Your applet should implement this method to do final cleanup such as stop live threads.

Appearance

The Panel provided in the Applet class inherits a paint method from its parent Container class. To draw something onto the Applet's Panel, you implement the paint method to do the drawing.
The Graphics object passed to the paint method defines a graphics context for drawing on the Panel. The Graphics object has methods for graphical operations such as setting drawing colors, and drawing graphics, images, and text.
The paint method for the SimpleApplet draws the I'm a simple applet string in red inside a blue rectangle.

public void paint(Graphics g){
System.out.println("Paint");
//Set drawing color to blue
g.setColor(Color.blue);
//Specify the x, y, width and height for a rectangle
g.drawRect(0, 0,
getSize().width -1,
getSize().height -1);
//Set drawing color to red
g.setColor(Color.red);
//Draw the text string at the (15, 25) x-y location
g.drawString(text, 15, 25);
}

Give back grades