i have two class .. class panel extends JPanel,
and another class that control the paint of that jpanel every seconds.. (i use swing.Timer)
my code below is fail
heres i try so far..
class panel extends JPanel :
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Control control = new Control(this,g);
repaint();
}
class Control :
public class Control implements ActionListener{
private int XX=0;
private int YY=0;
private Graphics2D g2;
private JPanel panel;
Timer tim = new Timer(1000, this);
public Control(JPanel el,Graphics g) {
this.g2=(Graphics2D)g.create();
this.panel=el;
tim.start();
}
@Override
public void actionPerformed(ActionEvent e) {
XX++;
YY++;
/////////////////////
//my priority
GradientPaint gp = new GradientPaint(XX, YY, Color.BLUE, panel.getWidth(), panel.getHeight(), Color.WHITE);
//////////////////////
g2.setPaint(gp);
g2.fillRect(0, 0, panel.getWidth(), panel.getHeight());
panel.repaint();
}
}
i need the start point of GradientPaint change every second
then paint it in jpanel every second
what should i do?
thanks ..
Everything that mKorbel has said and…
Graphicscontext passed to you by the paint sub system. It changes between paint cyclesrepaintor any method that might cause a repaint request from within thepaintXxxmethods, it will cause the repaint manager to schedule a new repaint at some time in the future and eventually cycle your CPU 100%