1

As I wrote in title, I want to drawLine additionally when Timer generates events.

Line will be draw like

first time;

second time;

ㅡ
ㅡ
  1. I want line will be added on before's maintained situation
  2. If first purpose cannot be done, (because I'm not good at Java yet, that's just my idea) I want to draw N line in Nth events then i redraw new N+1 line in (N+1)th events.

Which could be done in Java?

P.S. How to stop the Swing Timer?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 2
    Hi @user, welcome to SO. Generally, we like to see some effort and code samples, so, can you show us what you've tried? – Ben Nov 23 '12 at 01:16
  • This [example](http://stackoverflow.com/a/5048863/230513) starts and stops a `javax.swing.Timer`. – trashgod Nov 23 '12 at 02:52

1 Answers1

3

You'll basically have to (not in order):

  • Build an event to happen on each tick of the timer
  • Pass it to a new timer (stopping the timer is in the documentation)
  • Set some sort of incrementing counter, either coordinate-based or tick-based
  • Override the paintComponent method in a component to draw the lines, based on the incrementing counter
  • From inside the event, call repaint() on your component (will happen on each timer tick)

Work on each one of those tasks individually, and when you feel you've mastered each one, you can try putting them all together.

Ben
  • 54,723
  • 49
  • 178
  • 224