0

Possible Duplicate:
want to drawLine additionally when Timer generates Events

public class test4 extends JFrame implements ActionListener {
static test4 test = new test4();
Vector vec = new Vector();

Timer t = new Timer(1000, this);
int timerCount = 4;
int lineCount=1;

public static void main(String[] args) {
    test.t.start(); // START THE TIMER - MAKE EVENTS EVERY 1SECONDS

    test.setSize(400,400);
    test.setVisible(true);
}

public void actionPerformed(ActionEvent e){

    int[] nums = new int[4];
    nums[0] = 0;            //X1
    nums[2] = 400;          //X2        MAKE LINE HORIZONTALLY 

    nums[3] = nums[1] = 5+test.lineCount*5;// Y1,Y2     MAKE LINE HORIZONTALLY GO DOWN
    vec.add(nums);

    timerCount--;

    //FOR TEST, LIMITED COUNTS TO 5 TIMES
    if(test.timerCount<=0)
        test.t.stop();

    test.repaint();

}

public void paint(Graphics g){
    g.setColor(Color.blue);

    for(int i = 0 ; i < vec.size() ; i++)
    {
        int[] pos = (int[])vec.get(i);
        g.drawLine(pos[0], pos[1], pos[2], pos[3]);
    }

}
}

In test, i checked the timer and positions for drawLine. these are going well

BUT i can't see any lines when running this codes in JFrame window.. :(

which should i correct the code?

Community
  • 1
  • 1
  • You need to override `paintComponent`, as I said in my last answer: http://stackoverflow.com/questions/13522031/want-to-drawline-additionally-when-timer-generates-events/13522050#13522050 – Ben Nov 23 '12 at 02:01
  • 2
    No problem. I'd appreciate an accept or upvote my last answer, if it helped you. This question can be deleted. Welcome to SO! – Ben Nov 23 '12 at 02:08
  • @user1776472: Please update your [original question](http://stackoverflow.com/q/13522031/230513) and delete this one. – trashgod Nov 23 '12 at 02:47
  • don't draw directly to the `JFrame`, put a `JPanel` and draw to it. – Mordechai Nov 23 '12 at 04:03

0 Answers0