Lesson 1 How to make applets

Activities

  1. Compiling
  2. Java source files and HTML files
  3. Basic structure of java source files
  4. for-next sentences
  5. Screen coordinates

Example 1 Drawing line design

Screen of the applets

Exm1.java
import java.awt.*;                  //use all awt package
import java.applet.*;               //use applet package

public class Exm1 extends Applet    //declaration of class
{
	public void paint(Graphics g)   //paint method
	{
		int x;                      //variable x
		for(x=0;x<=200;x=x+10){     //for - next
		    g.drawLine(x,200,0,x);  //drawing line
		}
	}
}

Exm1.html
<HTML>
<HEAD>
<TITLE>Exm1</TITLE>
</HEAD>
<BODY>
<APPLET CODE="Exm1.class" WIDTH=200 HEIGHT=200></APPLET>
</BODY>
</HTML>


Excercise 1a Create applets that draws the following figure. The interval of each line is 20 pixels.

Excercise 1b Create applets that draws the following figure.