Java JComponent paint --Almost working

后端 未结 3 1225
渐次进展
渐次进展 2021-01-16 19:04

I almost have the repaint() Jcomponent working. I had it working and then tried to make an absolute positioning and now it doesn\'t work.

import java.awt.Col         


        
3条回答
  •  误落风尘
    2021-01-16 19:56

    With Swing animation, the Timer class is an exceptional option.

    //this class is a JPanel that implements ActionListener`
    Timer t = new Timer(1000,this);//the first arg is how many times it repeats in milliseconds
    //Then in the constructor...
    t.start();
    //the ActionPerformed function normally increments a variable then calls the repaint method.
    rectangle_x++;
    repaint(); //calls paintComponent 
    

    Another good idea is to cast g to a Graphics2D object- it's a lot safer and more capable.

提交回复
热议问题