PDA

View Full Version : Java event help...


Muffinking
2003.10.13, 05:17 PM
Does anyone know how to implement an event handler in java?

I need to update a JFrame when my simulation is going... so I need to update the window as often as possible..

my main class implemets the ActionListener class.. but i have never used events in Java... I don't really know how they work.. from what I have seen it looks like they run on strings passed to the event handler...

I need to know how to pass an idle event to my own app..

any thoughts on this?

my assignment is due tomorrow and I have yet to get to the actual assignment part... this damn Swing crap... grrr..


Hank-

akisha
2003.10.13, 09:02 PM
First create a class which implements ActionListener.


public class MyTimer implements ActionListener {
public void actionPerformed(ActionEvent evt) {
//Do everything you need to do
}
}


Then you have to install your timer:


new Timer (IntervalInMilliseconds, new MyTimerInstance()).start();


You could probably have the frame as an attribute in the MyTimer class, passed to the constructor when you create the timer

HTH
-wep