This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes rectangles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "rectangles" Watch "rectangles" New topic
Author

rectangles

yassire SANIE
Greenhorn

Joined: Mar 11, 2006
Posts: 4
hi
can anyone help please, i've been working on this code but it all the times generates errors: " write an applet that draws a variety of rectangles of different sizes and locations."
thanx
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
What is your code, and what errors do you get?
yassire SANIE
Greenhorn

Joined: Mar 11, 2006
Posts: 4
here is the code ( the problem is that i didn't get the idea of different locations)


class Rectangle extends Shape {
private int width;
private int height;

// constructor
Rectangle(int newx, int newy, int newwidth, int newheight) {
super(newx, newy);
setWidth(newwidth);
setHeight(newheight);
}

// accessors for the width & height
int getWidth() { return width; }
int getHeight() { return height; }
void setWidth(int newwidth) { width = newwidth; }
void setHeight(int newheight) { height = newheight; }

// draw the rectangle
void draw() {
System.out.println("Drawing a Rectangle at " + getX() + ", " + getY() +
"), width " + getWidth() + ", height " + getHeight());
}
}
 
 
subject: rectangles
 
Similar Threads
exam question
Chart bars
Applet help needed why wont it work???
java swings with 2D graphics
drawRect()