Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

repaint() won't call paint() and I'm out of ideas why

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been banging my head on this for a while now. In run() everything is peachy if I use show(). I'm pretty sure I need to use repaint() if I want to move the figure around the board without tracers. also, the thread doesn't quit when I close the app, but that's not my big problem now.

heres the code (all of it) edited, compiled and run in BlueJ

 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

First, I note that in your haste to come in and ask a question, you seem to have missed reading our policy on display names, which quite clearly states that you must use a real (sounding) first and last name for your display name -- no joke names, "handles," or last initials are acceptable. You can fix your display name here. We take this policy rather seriously. Thanks for your cooperation!

Second, your problem: this ought to work, more or less, if you get the JFrame to appear on the screen by calling setVisible(true) in your constructor.

As far as the threads not stopping: graphics programs simply won't quit unless you, one way or another, arrange to have System.exit() be called; usually just by calling setDefaultCloseOperation() on your JFrame.

I should point out that you're mixing AWT and Swing techniques here. With Swing, you don't override paint(), but rather paintComponent(); you always call super.paintComponent(); and you don't need to override update(). Typically you'd write a subclass of a JPanel, not a JFrame, and add that JPanel to an "off-the-shelf" JFrame.

Finally, we've got a Swing/AWT forum here where this post would fit right in. I'm going to move it there. See you around the Ranch!
 
Jeff Finn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You for your Help, I've fixed my name, too.
 
Jeff Finn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now that It moves, how do I get rid of the flicker? or is it just my compiler?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see if this is any better

 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure Michael's code is going to be a big improvement flicker-wise; the JPanel class implements double-buffering internally, and he's doing things the Swing way, as I suggested.

Art Vandelay is the fake name George Costanza gave to prospective dates and employers, etc. A famous fake name is worse, I think, than what you started with! Can we go with something a bit less flashy, please? "Joe Finn" sounds nice.
 
Jeff Finn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow. that's slick; I got a long way to go...
thanks for your help,
Jeff
 
    Bookmark Topic Watch Topic
  • New Topic