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:
public class picture extends java.applet.Applet
public void paint(Graphics g)
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
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:
Everything I put in the parenthesis below should be numbers(ints), I am just describing them with
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.drawArc(X,Y,width,height,start(ex. 0 as in 0 degrees),degrees to rotate);
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>
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