By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,060 Members | 1,906 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,060 IT Pros & Developers. It's quick & easy.

[Help Please] Graphics programming problem.

P: n/a
Ok, I've spent nearly a week trying to sort what should be an easy
task to accomplish but I'm totally flumoxed!

I want to do something pretty simple...
1. display image1

2. wait until image1 is drawn to the screen

3. wait 0.25 seconds
4. display image2

5. wait until image2 is drawn to the screen

6. wait 0.25 seconds
7. display image3

8. wait until image3 is drawn to the screen

9. ...
I've been using Java for about a year now (self taught) but this is
the first time I have tried to do anything with graphics. The above
sequence is to simulate a dice rolling. What happens is that Java
appears to jump straight to #8. From reading books and posts etc, I'm
guessing that #1, #4 and #8 are being done but the screen repaint is
only being done after #8.

***
So, the simple question is:
How do I force Java to wait until the screen has been updated before
doing another graphics op.
***

A friend found the following in a book:

public synchronized void repaintAndWait() {
repaint();
try {
wait();
}
catch (InterruptedException ex) { }
}

public synchronized void paint(Graphics g) {
// do painting here
...
// notify that we're done painting
notifyAll();
}
However, on trying this, the compiler gives me an error:

PokerDice.java [682:1] cannot resolve symbol
symbol : method repaint ()
location: class gameDice
repaint();
^
1 error
Errors compiling PokerDice.
I don't understand the error because I use "repaint();" in several
places without error but it doesn't seem to like that particular
instance.

I'd be very greatful to anybody that can help me out with this. As I'm
self taught when it comes to Java, (I'm a Pascal & VB programmer by
nature!) I'm keenly aware that there are great gaps in my knowledge.
However, I'm amazed that something that should be so simple is proving
to be so difficult.

Cheers,

Pudi.

BTW I'm using the NetBeans IDE.
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.