wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes super.painComponent(g) not clearing my Jpanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "super.painComponent(g) not clearing my Jpanel" Watch "super.painComponent(g) not clearing my Jpanel" New topic
Author

super.painComponent(g) not clearing my Jpanel

mikey strauss
Greenhorn

Joined: Nov 02, 2009
Posts: 19
the polygon i am trying to draw and change does not repaint the Jpanel instead it leavs a trail ....
here is my code any help would be Wonderful thanks


Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7
The posted code doesn't even compile.
mikey strauss
Greenhorn

Joined: Nov 02, 2009
Posts: 19
sorry you need point class ......

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

mikey strauss wrote:sorry you need point class ......


Why did you create that class when java.awt.Point already exists?
mikey strauss
Greenhorn

Joined: Nov 02, 2009
Posts: 19
i did not know about it till i allready built the class
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

I ran it and it drew a quadrilateral like the tail of an airplane. What is it supposed to do instead?

(I did replace all of your "point" references by "java.awt.Point" references to simplify things, but that shouldn't affect the output at all.)
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7
mikey strauss wrote:i did not know about it till i allready built the class


So get rid of your "point" class and convert your code to use the standard "Point" class. Don't reinvent the wheel, espcially when you don't follow Java class naming conventions.
mikey strauss
Greenhorn

Joined: Nov 02, 2009
Posts: 19
there is a polygon i am trying to change the 10,10 point to 300,200 (creating a new polygon) it changes but the first polygon stays and on it the new polygon is drawn there for creating a unwanted airplane tale instead of clearing the JPanel and drawing the second (4-point) polygon........
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

Okay. Do you have some code which demonstrates that problem?
mikey strauss
Greenhorn

Joined: Nov 02, 2009
Posts: 19
this is my code i do not understand why the jpanel dose not clear when the repaint in move()
act's on the paintComponent()- super.paintComponent;
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

It does. I had to run the program in debug mode and put a breakpoint at the call to move() though, otherwise all I see is the screen after that call. Before the breakpoint I see one quadrilateral, after the breakpoint I see a different one. What should the program do if not that? And why write a program which you have to run in debug mode to see the results?
mikey strauss
Greenhorn

Joined: Nov 02, 2009
Posts: 19
sorry i am new i don't realy understand what is debuging is (i think it is a breakpoint so you can see part of the code)
the Thread.sleep sould stop the first (4-point) polygon from changing for some time then when the move()
is called the JPanel sould clear and the second (4-point) polygon sould apeer with out there remains of the first one
sould not lokk like an airplane tail-(5-point polygon)
i did not understand way it is a progam that has to be run from debuging...
mikey strauss
Greenhorn

Joined: Nov 02, 2009
Posts: 19
OK thanks i got it i do not know why but the casting from graphics to graphics2D was the problem
some how whin i only used graphics it worked fine
thanks .....
Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
In your code you draw only one polygone.

Thread.sleep causes the main thread (Event Dispatch Thread, EDT) to sleep, in that half of second the application hangs.

And even if it draws that first polygon before call to move() the super.painComponent(g) will clear that and then it draws that polygon after move()...

Maybe you could call move() in painComponent(Graphics) method... and for the second polygone create a new GeneralPath.

Debugging is finding bugs
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7
mikey strauss wrote:OK thanks i got it i do not know why but the casting from graphics to graphics2D was the problem
some how whin i only used graphics it worked fine


What are you doing now? It doesn't even compile when you use the Graphics Object. the fill(...) and draw(...) methods of defined in the Graphics2D class.

Anyway if I understand your original problem its because you are trying to reuse the same GeneralPath method. I think code like the following is what you are trying to do:

mikey strauss
Greenhorn

Joined: Nov 02, 2009
Posts: 19
i ment using graphics methods too it works fine when i do that i will check your answer later when i am on my computer
thanks any way you'v bin a great help i keep you posted about you'r answer..(if you have not tried it allready)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: super.painComponent(g) not clearing my Jpanel