simple gui program
i cant seem to get my arg to jump all over the place when the button is initalized can any one help this is my code
class colorListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if (arcs == 300)
{
arcs = 360;
}
else if (arcs == 360)
{
arcs = 300;
}
for (int i = 0; i<300; i++)
{
x = (int)(Math.random()*600);
y = (int)(Math.random()*600);
frame.repaint();
drawPanel.repaint();
//***************time delay**********
try
{
Thread.sleep(0);
}
catch(Exception ex)
{}
}//end for loop
}// end of actionpreformed
}//ends colorlistener
Well by looping on the EDT you're effectively stopping it from processing anything else (like painting).You should do your looping in a worker thread, take a look at http://java.sun.com/javase/6/docs/api/javax/swing/Timer.html
dwga at 2007-7-12 19:57:00 >

1. new Timer(delay, ColorListener).start();
isn't correct, it should benew Timer(delay, new ColorListener()).start();
2. Where are you starting the timer ? I hope you're not doing it in the actionPerformed method in ColorListener, as that would give you infinite recursion.
3. Did you change the actionPerformed method in ColorListener to stop looping?
The Timer will fire an event at "delay" intervals, effectively calling ColorListener's actionPerformed method, but as the API states this is done on the EDT, so the actionPerformed must finish quickly.
Something like having your actionPerformed method only update x and y and calling repaint, no looping.
dwga at 2007-7-12 19:57:00 >
