Java Assignment 10 You have until Monday, May 14 to complete this assignment and have it submitted in the pass-in folder on the G: drive. There is a folder called “Java - Assignment 10” where you are to place all your Java files for this assignment.

In this assignment, we are going to explore using Applets. An applet is a graphical interface in a java program. Instead of reading in user input and writing text back to the screen, an applet has to draw things on a canvas and respond to the user’s mouse clicks. JCreator makes creating applets very simple. You are going to create a very basic applet and make it draw something.

To create your first applet in JCreator, follow these steps:

1) Click “File” menu, select “New” and then select “Project”. 2) In the window that pops up, select “Basic Java Applet” and then click “Next”. 3) Enter a name for your applet. This will also be the class name used so don’t use any spaces in the name. 4) Select a location on your H: where the files will be stored. You should create a new folder for each applet to keep the code organized. 5) You can now click “Finish” since you don’t need to change any of the other options.

On the left side of the screen, you will see a directory tree for the project you just created. Open the “src” tree and you will see your .java file. Double click on it to open it. Inside this applet, you will see that they have created a basic application for you. There are two methods. The first is the init method which is used to initialize any variables. We won’t be using this during this assignment. The other method is the one we are concerned with. The paint method is called by the system each time the screen needs to draw the applet. So when the applet first runs, the paint method is called by the system. When you minimize the applet and then restore it, the paint method is called by the system.

The paint method takes in a Graphics object as a parameter. This Graphics object is created by the system and is what you use to draw things on the applet window. The Graphics object by default has the variable name “g”. You use this “g” variable to make calls to the drawing program. The Graphic object has many different methods that you can use to draw things to the screen. By default, the applet calls the drawString method to write out some text to the applet window. You can see that drawString takes a String and two ints as parameters. The String is the words that are to be drawn and the two ints are the x and y coordinates of where the text should be drawn. Open Internet Explorer and have a look at the Java API documentation for the Graphics class at the following URL. Have a look at the definitions and description for the different Graphics methods.

You can look at the specification for each method to find out how to use it to draw things to the screen.

Problem 1

For the first problem, you must create an applet called “Problem1”. Using this applet, you are to draw a face using the Graphics object in the applet. The face should be made up of simple shapes such as circles, rectangles, lines, etc. You must use the web page given above to find out how to use each of the drawing methods. Here are some that you may be interested in:

- setColor - drawLine - drawOval and fillOval - drawRect and fillRect - drawRoundRect and fillRoundRect - drawPolygon and fillPolygon

Use as many different colors and different shapes as you can. Be creative. Problem 2

Create an applet called “Problem2” and use it to draw a TicTacToe board. The board should be very large and take up most of the window. Draw at least one X and one O on the board. Do not use the drawString method. Use the drawLine and drawOval methods as well as the drawRect and fillRect methods to draw the board.

Problem 3

Create an applet called “Problem3” and use it to draw Mr. Coombs. You should draw his whole body in this and use different colors and shapes. The person who creates the applet that most resembles Mr. Coombs will be given bonus points.