1. create ovals at given (x,y) coordinates at different points of time. (the time is in milliseconds). The time points are not periodical. they r random.
2. For eg.,
JFrame frame = new JFrame("Ladder Rung Sensor");
frame.add(lc);
frame.setSize(200,100);
frame.setVisible(true);
}
}
Now, I dont know how to create a timer with my requirements mentioned in Post 1. I am a complete beginner in Java. Can u pls help me now? Ofcourse, I dont ask u if I didnot put any effort.
Your class should not extend JFrame, it should extend JPanel.
You should not override the paint() method, you should override paintComponent() instead.
As for the timer, you could use a javax.swing.Timer and change the delay time each time the listener is called to randomize the delay or you could create a background thread that loops around and in the loop puts the thread to sleep for a random amount of time before calling repaint().
After trying keang's method you could try this if you find it easier.
Code:
Public class t1 implements Runnable()
{
Int curentTime = 0;
Random rand1 = new Random();
Int time1 = 1+rand1.nextInt(100);//the upper limit of time
time1 = time1*1000; // we want to use seconds not milis
Public void Run(){
while(curentTime>100000)
{
//put code to check if time1 == curentTime.. This can also be applied to other timers
// put code to draw circles if needed
Thread.sleep(1000);
CurentTime+= 1000;
}
}
}
But if i were you i'd use keangs way since mine looks a little too complicated
Bookmarks