The problem is really detailed and i am not understanding much of it. But its exercise 8.18 in Dietel Java How to Prgram book. Essentially, i need to create an applet that randomly draws lines, rectangles, and ovals. Can anyone help? I know it should start like this....
import java.awt.Graphics;
public class MyLine extends Object { // holds the coordniates of the line private int x1, y1, x2, y2; // default constructor public MyLine() { x1=y1=x2=y2=0; } // convenience constructor public MyLine(int x1, int y1, int x2, int y2) { this.x1=x1; this.y1=y1; this.x2=x2; this.y2=y2; } // Draw the line on a Graphics object public void draw( Graphics g ) { g.drawLine(x1, y1, x2, y2); } /* Java Beans style get and set methods * need one for each private variable that * that we wish to make available */ public void setX1( int x1 ) { this.x1 = x1; } public int getX1() { return this.x1; } }
public class MyName extends JApplet { /* Soon we will learn how to use an * array and a superclass to do this * more elegantly */ public MyLine m0, m1, m2, m3;
/* Create (instantiate) instances of * our letters */ public void init() { m0 = new MyLine(5,95,5,5); m1 = new MyLine(95,5,95,95); m2 = new MyLine(5,5,95,95); } /* Draw them, soon we will learn how * to use an array and dynamic dispatch * to do this more elegantly */ public void paint( Graphics g ) { m0.draw(g); m1.draw(g); m2.draw(g); } }