Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - Forcing paint event in Java applets | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
Squash Monster

New Age Retro Hippie
Togateiru Fohku Kohgeki!!
GRUNGE no HAMSTER otona bite
Peace love and turnpike!

Level: 40

Posts: 487/677
EXP: 430507
For next: 10802

Since: 03-15-04
From: Maryland (of the Country Between Canada and Mexico)

Since last post: 5 hours
Last activity: 5 hours
Posted on 12-21-04 05:05 AM Link | Quote
So I'm coding this Java applet type dealy, a game. I've got all the main code in a class, called Stepper, which has an object generated by the main class (the one with paint and init). The Stepper object does event handling for keyboard input and a timer that the main class sets up.

Now, whenever the Stepper event fires from the timer, it does a good deal of stuff, and thus I should redraw the screen. Unfortunately, I don't know how to come back to the main class and call the paint event or force it to paint or anything good like that, and this is a problem, becouse the screen needs to be redrawn when the game is being played.

Anyone know how to deal with this? Do I need to try to explain this in a different way?
neotransotaku

Baby Mario
戻れたら、
誰も気が付く
Level: 87

Posts: 1899/4016
EXP: 6220548
For next: 172226

Since: 03-15-04
From: Outside of Time/Space

Since last post: 11 hours
Last activity: 1 hour
Posted on 12-21-04 06:25 AM Link | Quote
what class are you using as your drawing surface? If you use Swing to build your applet, a simple call to repaint() should be enough...
Squash Monster

New Age Retro Hippie
Togateiru Fohku Kohgeki!!
GRUNGE no HAMSTER otona bite
Peace love and turnpike!

Level: 40

Posts: 489/677
EXP: 430507
For next: 10802

Since: 03-15-04
From: Maryland (of the Country Between Canada and Mexico)

Since last post: 5 hours
Last activity: 5 hours
Posted on 12-21-04 07:42 AM Link | Quote
I'm building it on java.awt. and java.applet, I think. The book I'm learning from glosses over and doesn't explain anything on the topics .
neotransotaku

Baby Mario
戻れたら、
誰も気が付く
Level: 87

Posts: 1903/4016
EXP: 6220548
For next: 172226

Since: 03-15-04
From: Outside of Time/Space

Since last post: 11 hours
Last activity: 1 hour
Posted on 12-21-04 08:21 AM Link | Quote
(1) have your class implement Runnable interface
(2) move all your drawing code to void run() { while(true) { // paint code } -- replacing the comment with your paint code
(3) insert the following code into main: (new Thread(this)).start();

basically, what I'm having you do is move all your painting code into a function that will run on its own thread. thus, giving you the refresh you want. i'm not sure if there is a better way to do with with AWT but if you were using Swing, it would be a little easier. To switch to Swing, you need to extend JPanel and override its paintComponent() method
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 2568/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 12-21-04 09:41 PM Link | Quote
Surprisingly, I actually know what that means. But don't you have to use a Try/Catch statement when you start a new thread?
neotransotaku

Baby Mario
戻れたら、
誰も気が付く
Level: 87

Posts: 1918/4016
EXP: 6220548
For next: 172226

Since: 03-15-04
From: Outside of Time/Space

Since last post: 11 hours
Last activity: 1 hour
Posted on 12-21-04 10:27 PM Link | Quote
yes, that is right, you need to use a try-catch block. Not unless you have your main function throw Exception, then you do not need try-catch anywhere--but that is bad programming style (which I'm a victim of since I did that with my Graphics Engine )
Squash Monster

New Age Retro Hippie
Togateiru Fohku Kohgeki!!
GRUNGE no HAMSTER otona bite
Peace love and turnpike!

Level: 40

Posts: 490/677
EXP: 430507
For next: 10802

Since: 03-15-04
From: Maryland (of the Country Between Canada and Mexico)

Since last post: 5 hours
Last activity: 5 hours
Posted on 12-22-04 06:30 AM Link | Quote
Well, I just tried your method, and another where Stepper takes a reference to the main class and tries to run its paint method. However, neither worked. Paint needs a Graphics class as an argument, so what I tried to do was to store a reference to the last one that was used for calling it. I'm thinking that the only Graphics class that works is the one automatically provided to the applet.

This is starting to look like more effort than it's worth. All I'm using the applet for is getting a Graphics context for painting, and starting the program. Could anyone give me a crash course in a better way to set everything up?
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - Forcing paint event in Java applets | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.026 seconds.