The applets you produce in this lab may appear very insubstantial compared to the magnificent stories you put together in Alice. Nevertheless, you should be able to have some fun putting together a tableau of text, shapes, colors and characters.
First thing to do is to fire up Eclipse and begin a new Java project called lab6 in your workspace (the same workspace as you created last week will be fine). It is the folder lab6 that you will zip up and submit to the graders. So be sure you know where you can find it. If you need to, ask your lab instructor.
In that project, make a new package called HuckleberryHoundPackage (Do I have to say "Replace HuckleberryHound by your own name?)
Now create a new Class called Ex1 that extends javax.swing.JApplet. Eclipse will do all the work for you as long as you tell it the Superclass.
As we have done in class I want you to set the size of the applet in an init() method.
Then I want you to create a paint method that will let you draw things in your applet. Study the documentation and you will see that paint requires a parameter of type Graphics. Again look at the documentation and you will see that a Graphics object has methods to draw rectangles, draw ovals, fill rectangles, draw strings, draw images! The paint method is called by the runtime system which will pass a Graphics object for your actual device to the method. Your method can then tell the Graphics object (whose name, as a parameter, is g) what to do. In my code below, I set the painting color to pink by commanding g.setColor(Color.pink), and then I tell the Graphics object to fill the entire rectangular applet with this color via g.fillRect(0,0,getWidth(),getHeight()).
If you copy the code that I give you here, you will get an applet that produces a solid pink square. For Exercise 1 you will need to modify my code to give you a solid pink Oval within a rectangular applet.
Here is my code, some of which was generated by Eclipse. You will need to make some small changes for Exercise 1.
package RhysPriceJonesPackage; import java.awt.Color; import java.awt.Graphics; import javax.swing.JApplet; public class Ex1 extends JApplet { public void init() { setSize(350,350); } public void paint(Graphics g) { g.setColor(Color.pink); g.fillRect(0, 0, getWidth(), getHeight()); } }