A Java Applet tutorial

first of all, you are going to need either an sdk or jdk to make these programs. I recommend
Jbuilder9 from borland. You can get it here http://www.borland.com/products/downloads/. Registration is required though.
For this tut I will be using jcreator and the latest sdk from http://java.sun.com. You can get jcreator from http://www.jcreator.com under downloads. Remember to get the freeware version not the
shareware.

Now that that's out of the way we can get down to the programming aspect of this tutorial.
This tutorial will focus on graphics in java through applets. Let me give you an example:

Code:
import java.awt.*;

public class picture extends java.applet.Applet
{
	public void paint(Graphics g)
	{
		g.setColor(Color.red);
		g.drawRect(50,50,150,100);
	}
}
drawRect() is built into the import that we use. The first number is the x coordinate of the top
left corner, and the second number is the y coordinate. The third number is the horizontal length
of the sides and the fourth is the vertical length. You could also do fillRect() to fill in the
rectangle.

the setColor() method does what it sounds like it does, it sets the color. you should be able
to figure out on your own how to get other built in colors(Color.blue, etc.). If you want to
customize a color you could type:

g.setColor(new Color(254,235,234));

Everything I put in the parenthesis below should be numbers(ints), I am just describing them with
words.

Other methods are:
(note: you always need the g. before the method. Although it could be anything else as long as
it matches the value in the head of the paint method.
ex. public void paint(Graphics g))

g.drawOval(X,Y,width,height);

g.drawArc(X,Y,width,height,start(ex. 0 as in 0 degrees),degrees to rotate);

g.drawLine(X1,Y1,X2,Y2);

g.drawRoundRect(X,Y,width,height,cornerwidth,cornerheight);


As you can see, with an applet, no main method is required. The paint method kindof acts as the
main method for applets. Save this file as picture.java. To run this applet we will need to make
an html file containing the following text:

<applet code="picture.class" width=400 height=400>
</applet>
You can adjust the width and height as needed.

Save that file as anything as long as it is in the same directory as the java program
above and is saved as a .html. To run this you must first compile picture.java which creates the
picture.class file you see above, which is used to run the applet. You run the program with the
html page not through jcreator. If you double click your .html file it should open up in your
web browser and you will see the applet you just made.

That should get you started with applets, also I wanted to include a little bouncing ball program
I wrote:

Code:
import java.awt.*;



public class bounce extends java.applet.Applet

{   

	public void paint(Graphics g)

	{  		

	int x=0;

	int y=0;

	int X=0;

	int Y=0;

	for(int b=1;b<=100;b++)

	{	

	  for(int i=1;i<=500;i++)

	  {

	    g.setColor(Color.red);

	    g.fillOval(x,y,50,50);

	    for(int j=1;j<=150000;j++)

	    {}

	    g.setColor(Color.white);

	    g.fillOval(x,y,50,50);

	    x++;

	    y++;

	    }

	  for(int a=1;a<=250;a++)

	  {

	    g.setColor(Color.red);

	    g.fillOval(x,y,50,50);

	    for(int j=1;j<=150000;j++)

	    {}

	    g.setColor(Color.white);

	    g.fillOval(x,y,50,50);

	    x++;

	    y-=2;

	  }

	  for(int a=1;a<=500;a++)

	  {

	    g.setColor(Color.red);

	    g.fillOval(x,y,50,50);

	    for(int j=1;j<=150000;j++)

	    {}

	    g.setColor(Color.white);

	    g.fillOval(x,y,50,50);

	    x--;

	    y++;

	  }

	  for(int a=1;a<=250;a++)

	  {

	    g.setColor(Color.red);

	    g.fillOval(x,y,50,50);

	    for(int j=1;j<=150000;j++)

	    {}

	    g.setColor(Color.white);

	    g.fillOval(x,y,50,50);

	    x--;

	    y-=2;

	  }

	}

  	}

}
Save this file as bounce.java and compile it.

Here is the .html file:

<applet code="bounce.class" width=800 height=600>
</applet>

I'm not going to explain it but you can fool around with it for fun.

And one more thing, the coordinates are messed up in java. The top left of the applet is (0,0)
and the bottom right is (800,600), therefore making down positive in the applet.

I know this tut isn't perfect, but it is a start for anyone wanting to jump into the world
of java applets.

Hope you all enjoyed and learned from this.