Witam
oto kod
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class cos extends JFrame implements ActionListener{
private static JTextField x1;
private static JButton start;
public cos() {
setBounds(50,50,120, 150);
setLayout(null);
x1 = new JTextField();
x1.setBounds(10, 20, 85, 30);
start = new JButton("start");
start.setBounds(10, 65, 85, 30);
add(x1);
add(start);
start.addActionListener(this);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void jeden(){
x1.setText("jeden");
}
public static void dwa(){
x1.setText("dwa");
}
public static void trzy(){
x1.setText("trzy");
}
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
cos program = new cos ();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==start)
{
jeden();
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
dwa();
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
trzy();
}
}
}
niestety wyświetla się po czasie tylko "trzy"
dlaczego?
i jak to poprawnie zrobić aby wyświetlało się po kolei w odstępach czasu?
poooomocy
czekam na wszelkie sugestie