Criei uma unica classe onde eu fiz um desenho onde usei o metodo paint e repaint e usei thread para faze-lo mover automaticamente. Não estou conseguindo fazer um outro desenho e move-lo junto com o primeiro desenha criado. Como eu resolvo este problema ? Alguem pode me ajudar?
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
import java.util.*;
import java.io.*;
import java.math.*;
public class Desen extends Frame implements Runnable {
//09 13 23 29 49 /// ///
double px[]={0.,20.,20.,30.,140.,150.,150.,130.,40.,50.,130.,110.,70.,80.,70.,90.,100.,40.,50.,60.,70.,60.,50.,100.,110.,120.,130.,120.,110.,40.,50.,60.,70.,80.,90.,100.,110.,120.,130.,40.,50.,60.,70.,80.,90.,100.,110.,120.,130.,90.,90.,120.,140.,60.,40.,40.,130.,150.,150.,150.,20.,20.,20., 220.,220.,230.,340.,350.,350.,330.,240, 250.,330.,310.,270.,280.,270.,300.,290.,240.,250.,260.,270.,250.,260.,300.,310.,320.,330.,320.,310.,240.,250.,260.,270.,280.,290.,300.,310.,320.,330.,240.,250.,260.,270.,280.,290.,300.,310.,320.,330.,290.,290.};
double py[]={0.,30.,120.,130.,130.,120.,30.,10.,10.,50.,50.,40.,40.,70.,60.,70.,60.,90.,100.,100.,90.,80.,80.,90.,100.,100.,90.,80.,80.,130.,130.,130.,130.,130.,130.,130.,130.,130.,130.,160.,160.,160.,160.,160.,160.,160.,160.,160.,160.,-130.,10.,-160.,-160,-160.,-160,-50.,-50.,-50.,-60.,-40.,-50.,-60.,-40., 30.,120.,130.,130.,120.,30.,10.,10.,50.,50.,40.,40.,70.,60.,60.,70.,90.,100.,100.,90.,80.,80.,90.,100.,100.,90.,80.,80.,130.,130.,130.,130.,130.,130.,130.,130.,130.,130.,150.,150.,150.,150.,150.,150.,150.,150.,150.,150.,-130.,10.};
int arestai[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,50,49,51,53,53,55,56,56,56,55,55,55,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,79,80,81,82,84,83,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,111,111,111};
int arestaf[]={2,3,4,5,6,7,8,1,10,11,12,9,14,16,15,18,19,20,21,22,17,24,25,26,27,28,23,39,40,41,42,43,44,45,46,47,48,49,51,52,49,54,56,57,58,59,60,61,62,64,65,66,67,68,69,70,63,72,73,74,71,76,77,78,80,81,82,84,83,79,86,87,88,89,90,85,101,102,103,104,105,106,107,108,109,110,112};
int np = 78 ;
int na = 101;
int xt =200, yt = 400;
double pxl[] = new double[20000];
double pyl[] = new double[20000];
double beta = 0*3.1415/180 ;
double angulo = 0;
double cgx;
double cgy;
public Desen() {
setLocation(10, 10);
setSize(680, 700);
setTitle(" Exemplo CG 2D");
setLayout(new FlowLayout());
cgx = 0;
cgy = 0;
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowOpened(WindowEvent e)
{
}
public void windowClosed(WindowEvent e)
{
}
});
}
public void desIncr()
{
for (int i = 0; i <1 ; i ++){
this.angulo = angulo + 40;
beta = angulo*3.1415/180 ;
repaint();
}
}
public void paint(Graphics g){
for (int i = 0; i <= np ; i ++){
px[i]= px[i]-cgx;
py[i]= py[i]-cgy;
}
for (int j = 0; j <= np ; j ++)
{
pxl[j]= px[j]*Math.cos(beta)-py[j]*Math.sin(beta);
pyl[j] = px[j]*Math.sin(beta)+py[j]*Math.cos(beta);
}
for (int i = 0; i <= np ; i ++){
px[i]= px[i]+cgx;
py[i]= py[i]+cgy;
pxl[i]= pxl[i]+cgx;
pyl[i]= pyl[i]+cgy;
}
for (int i=0; i< na; i++)
{
g.drawLine((int) pxl[arestai[i]]+xt, yt-(int) pyl[arestai[i]],
(int) pxl[arestaf[i]]+xt, yt-(int) pyl[arestaf[i]] );
}
}
public void run() {
repaint();
try{
for(int i=0; i<9; i++)
{
desIncr();
Thread.sleep(1000);
}
}catch (Exception e) {
System.out.println("Error");
}
}
public static void main(String arg[]){
System.out.println("Inicio");
Desen des = new Desen();
des.show();
new Thread(des).start();
System.out.println("Fim");
}
}
EDIT - Por favor, use as tags [ code ] para postar código