Por favor alguem pode me ajudar a criar 3 threads e fazer com que elas trabalhem simultaneamente?
qual sua dúvida :?: já usou link Buscar do lado esquerdo :?: não :?: então use :!:
tony_roger, testa esse exemplo que eu fiz e vê se é isso que vc precisa:
import javax.swing.*;
import java.awt.*;
public class RunButtons extends JFrame{
private JButton bts1 = new JButton("01 >>");
private JButton bts2 = new JButton("02 >>");
private JButton bts3 = new JButton("03 >>");
public RunButtons() {
super("Run Buttons");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(600,200);
JPanel pane = new JPanel();
pane.setLayout(null);
pane.add(bts1);
pane.add(bts2);
pane.add(bts3);
MyThread th1 = new MyThread(bts1,10,10);
th1.start();
MyThread th2 = new MyThread(bts2,10,50);
th2.start();
MyThread th3 = new MyThread(bts3,10,90);
th3.start();
setContentPane(pane);
setVisible(true);
}
class MyThread extends Thread{
private JButton btn = new JButton();
int x, y;
public MyThread(JButton btn, int x, int y){
this.btn = btn;
this.x = x;
this.y = y;
}
public void run(){
try{
for(int i=0;i<100;i++){
btn.setBounds((int)(btn.getX()+Math.random()*10),y,70,30);
sleep(100);
}
} catch(Exception e){
e.printStackTrace();
}
}
}
public static void main(String []args) {
new RunButtons();
}
}
Falows