• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a.update(a.getGraphics());

 
Paul muellerl
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

can anybody tell what I have to do that when I use a.update(a.getGraphics()); in my Gui and my Window is always refreshing?
But actually I just want du refresh my Gui.
I tryed it with this

I think I´m nearly there....



 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's so much wrong there that I'm not going to even try to answer the question you asked. Instead I'm going to point you to the tutorials on Performing Custom Painting and How to Use Swing Timers.

Oh, and you do know there's a repaint() method, don't you?
 
Paul muellerl
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know there is a repaint method but it dosne´t work,
When I use repaint they just draw me the finish picture.


AND there can´t be so mutch wrong... it works... the only thing is that there is a flickering.
 
Paul Clapham
Sheriff
Posts: 20983
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul muellerl wrote:When I use repaint they just draw me the finish picture.


Yes, that's what it's for. Once you read and understand the custom painting tutorial you have a better chance of understanding how to do it right.

AND there can´t be so mutch wrong... it works... the only thing is that there is a flickering.


Maybe that's so, but you can't modify it to do what you want. Instead you have to stop, go back, and start down the right road. To do that it would be best if you read the tutorials which Darryl linked to. And then, write code like the code in those tutorials.

(What I usually do when I'm learning a new Java topic: I go through the tutorial. Then I download the sample code and start changing things in it, so that I am sure I understand it. Then I keep changing things in it until it turns into the code which I originally wanted to write.)
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> AND there can´t be so mutch wrong... it works... the only thing is that there is a flickering.

you seem to have a hard time believing what we've been telling you, and it's not a language problem.

here's 2 demo programs to prove to you the problems that will bite you when you least expect it.

1) using Thread.sleep in Swing is a no-no, it blocks painting and listeneing
run this, it will only last 5 seconds, but you cannot close the program in that 5 seconds,
and the label text will not appear until the while loop stops (which is the thread.sleep stopping)


2) getGraphics() is another no-no (generally) in Swing
run this, Hello World will appear, now minimize the frame then immediately restore it,
the text will disappear, as getGraphics() draws once only
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic