Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 19th, 2013, 06:49 PM
jikatz09 jikatz09 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 3 jikatz09 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 43 sec
Reputation Power: 0
Help creating Rectangle.class that is utilized in a different program

Hey everyone. I have an assignment to create a rectangle class. The end result of the assignment is a graphic with multiple rectangles of different colors and on top of that, different colors where they overlap. "The Rectangle constructor should accept arguments in this order: x1, y1, x2, y2, r, g, b. The r,g,b should determine the color of the rectangle. The coordinates should determine its location, but it shouldn't matter what order they come in. The left side of the rectangle should be at whichever x is smaller, and the right side should be at the larger x. Likewise, the top side of the rectangle should be at whichever y is smaller, and the bottom side should be at the larger y." This is the instructions for the first section of the program and I am a little confused as to what instance data I am creating and how to set up the constructor? Any help would be appreciated.

Reply With Quote
  #2  
Old March 19th, 2013, 06:53 PM
jikatz09 jikatz09 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 3 jikatz09 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 43 sec
Reputation Power: 0
Would I separately define each variable on its own like:
private int x1;
private int y1;
etc..?

Reply With Quote
  #3  
Old March 19th, 2013, 07:47 PM
jikatz09 jikatz09 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 3 jikatz09 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 43 sec
Reputation Power: 0
import java.awt.Color;
import java.awt.Graphics;

public class Rectangle {

private int x1;
private int y1;
private int x2;
private int y2;
private int r, g, b;



public Rectangle (int x1, int y1, int x2, int y2, int r, int g, int b) {

this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.r = r;
this.g = g;
this.b = b;


}

public void draw(Graphics page) {
Color color = new Color (r, g, b);
page.setColor(color);
page.drawRect(x1, y1, x2, y2);
}
}

This is what I have so far. Sorry it isn't in the right format...I forgot how to do that if anyone wants to refresh my memory.
Now I have to create a method called overlapsWith. The overlapsWith method should return whether or not the rectangle you call it on (this) overlaps with another rectangle (the argument). Here's a strategy for checking if this rectangle overlaps with another:

If the left x of this rectangle is larger than the right x of the other (or vice versa), they don't overlap.
If the top y of this rectangle is larger than the bottom y of the other (or vice versa), they don't overlap.
Otherwise, they do overlap.

Is this a boolean method? Some pointers on this section would be awesome guys.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Help creating Rectangle.class that is utilized in a different program

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap