Pessoal minha duvida quanto as threads é a seguinte
eu tenho uma classe eu to com uma classe/objeto que estende javax.swing.JLabel e inicia uma thread (outra classe) que deveria ficar atualizando o objeto com um numero ou string no caso dois valores para posicionar um JLabel em um JFrame
ou seja a classe tela é um JFrame que chama a classe pane que gera os JLabel, a classe Pane deveria ser um objeto que tem sua posicao dentro do JFrame alterada pela classe Mov que seria a thread Dessa forma a classe Tela criaria varios JLabels que ficariam andando na tela
Segue o codigo
//classe Tela
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package celulas;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* @author billy
*/
class Tela extends JFrame{
JLabel label;
public Tela(){
setVisible(true);
setLayout(null);
setSize(900, 700);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(new Pane());
}
}
/////////////////////////////////////////////////////////////////////////////////////
//classe Pane
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package celulas;
import javax.swing.ImageIcon;
/**
*
* @author billy
*/
public class Pane extends javax.swing.JLabel {
public Pane(){
ImageIcon icon = new ImageIcon("C:/Users/billy/Documents/NetBeansProjects/celulas/src/celulas/y.gif");
setVisible(true);
setBounds(0, 0, 31, 25);
setIcon(icon);
Runnable r_ola = (Runnable) new Mov();
Thread t_ola = new Thread(r_ola);
t_ola.start();
}
}
//classe Mov (a bendita thread)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package celulas;
/**
*
* @author billy
*/
public class Mov implements Runnable {
int y;
int x;
public void run() {
x=0;
y=0;
for(int c=0; c<=2; c++){
int i = 1+(int)(Math.random() * 8);
System.out.println(""+i+"");
if(i==1){
if(y<=0){
y=y+100;
}
y--;
}else if(i==2){
if(y<=0){
y=y+100;
}
if(x>=769){
x=x-100;
}
x++;
y--;
}else if(i==3){
if(x>=769){
x=x-100;
}
x++;
}else if(i==4){
if(y>=575){
y=y-100;
}
if(x>=769){
x=x-100;
}
x++;
y++;
}else if(i==5){
if(y>=575){
y=y-100;
}
y++;
}else if(i==6){
if(y>=575){
y=y-100;
}
if(x<=0){
x=x+100;
}
x--;
y++;
}else if(i==7){
if(x<=0){
x=x+100;
}
x--;
}else if(i==8){
if(y<=0){
y=y+100;
}
if(x<=0){
x=x+100;
}
x--;
y--;
}
c--;
}
}
}