как вызвать paintComponent (Graphics g) метод ??Как вызвать компонент компонента Paint в java
method(){
Timer timer = new Timer();
timer.schedule(new Class(), 1000,1000);
}
public void run() {
//invoke PaintComponent
}
Здесь! это обновленный один минимальный код Я хочу изменить конечную точку строки каждую секунду просто как вызвать paintComponent (Graphics g) метод ??
public class SimpleTest extends TimerTask {
JFrame frame;
int count ,x1,y1,x2,y2;
public void run() {
count+=5;
x1=count;
y1=count;
x2=count-1;
y2=count-1;
// repaint(); i want to invoke paintcomponent method from here , simply to change the end point of line every secd
}
void guiMethod(){
frame=new JFrame("Libra's");
frame.setBounds(50, 50, 250, 250);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new NewPanel());
}
public static void main(String[] args){
SimpleTest c=new SimpleTest();
c.guiMethod();
Timer timer = new Timer();
timer.schedule(new SimpleTest(), 1000,1000);
}
}
class NewPanel extends JPanel{
SimpleTest obj=new SimpleTest();
@Override
protected void paintComponent(Graphics g){
Graphics2D g2=(Graphics2D)g;
g2.setStroke(new BasicStroke(3));
g.drawLine(120, 120, 70, 80);
g.drawLine(120, 120, obj.x1, obj.y1);
g.drawLine(120, 120, obj.x2, obj.y2);
}}
я хочу, чтобы вызвать метод paintComponent (Графика г) каждый второй –
panel.repaint() –
Сэр @GilbertLeBlanc перерисовки (нет) работ. Не знаете, почему? –