• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

super.painComponent(g) not clearing my Jpanel

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The posted code doesn't even compile.
 
mikey strauss
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry you need point class ......

 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



Why did you create that class when java.awt.Point already exists?
 
mikey strauss
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i did not know about it till i allready built the class
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. Do you have some code which demonstrates that problem?
 
mikey strauss
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .....
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic