Results 1 to 6 of 6
- 01-14-2012, 10:10 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
Display shape drawn from another class
Hi I draw a shape in one class but i need it do actually appear when i play another class. The class I wish to play from extends from a gui class which will draw the frame. So all that is required is for the shape to draw.
Rect class:
Java Code:package work; import java.awt.*; import java.awt.event.*; import java.awt.Graphics2D; class Rect extends Shapes{ public Rect(int x, int y, int w, int h) { super(x,y,w,h); } public void draw(Graphics2D g) { g.setColor(Color.black); g.fillRect(x, y, w, h); } public static void main(String[] args) { } }
Java Code:package work; public class TestDraw extends Gui implements ShapeListener { public TestDraw(){ Rect rect = new Rect(20, 20, 200, 100); rect.addListener(this); } public static void main(String[] args) { new TestDraw(); } }
-
Re: Display shape drawn from another class
What is a Gui class? Are you supposed to add your Rect object to something? You create it, but don't do anything with it (that I can tell). What is the contract for the ShapeListener interface?
Also, it's usually good practice to answer the replies in previous threads before starting a new one.
- 01-14-2012, 10:19 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
Re: Display shape drawn from another class
the gui class has the coding for jframe and jpanels etc. I can play draw the rect in the same class by saying:
Java Code:Gui rect = new Rect(20,20,100,100); //Gui has a go method which repaints. rect.go();
-
Re: Display shape drawn from another class
There are too many unknowns here for me, seeing as how I have absolutely no knowledge of what's going on in your other classes.
- 01-14-2012, 11:02 PM #5
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
Re: Display shape drawn from another class
i have tested something and it seems like theres a problem with the class constructor for rect...aparantly its not inputting the values into the draw method in order to draw the shape. Can you help?
- 01-15-2012, 02:39 AM #6
Similar Threads
-
Strange extra shape drawn
By eyebrow in forum New To JavaReplies: 2Last Post: 10-26-2011, 12:18 AM -
A Shape Class
By GoodApollo in forum AWT / SwingReplies: 7Last Post: 06-20-2011, 02:13 PM -
How can I display these objects from another class?
By xx__rose in forum New To JavaReplies: 5Last Post: 05-07-2010, 09:01 PM -
how to change the shape of the JFrame to a oval shape
By kiki2009 in forum Java 2DReplies: 1Last Post: 04-02-2010, 01:48 PM -
SWT – Display class
By Java Tip in forum Java TipReplies: 0Last Post: 12-30-2007, 01:19 PM
Bookmarks