Java 在执行的操作中等待

Java 在执行的操作中等待,java,swing,Java,Swing,我想在此actionperformed()中等待arr[1]=bot,然后尝试{… 我已经试过使用swing.timer和Thread.sleep()但是它们不能像我想的那样工作。如果需要,我会附加整个程序 谢谢你的帮助 我试过这个,但不起作用。它错了吗 class pulsarBoton implements ActionListener,Serializable{ @Override public void actionPerformed(ActionEvent e) {

我想在此
actionperformed()中等待
arr[1]=bot,然后尝试{…

我已经试过使用
swing.timer
Thread.sleep()
但是它们不能像我想的那样工作。如果需要,我会附加整个程序

谢谢你的帮助

我试过这个,但不起作用。它错了吗

class pulsarBoton implements ActionListener,Serializable{
    @Override
    public void actionPerformed(ActionEvent e) {
        JButton bot=(JButton)e.getSource();
        if (arrBot[0]==null) {
            arrBot[0]=bot;
            arrBot[0].setIcon(new ImageIcon(arr.get(Integer.valueOf(bot.getName()))+".jpg"));//como puedo quitar el texto del boton pero referenciarlo al array??
        }else{
           bot.setIcon(new ImageIcon(arr.get(Integer.valueOf(bot.getName()))+".jpg"));
           arrBot[1]=bot;
           //JOptionPane.showMessageDialog(null, "Continuar");
           //espera(4000);// --> IT DOES NOT WORK AS I WANT
            try {
                Timer tiempo=new Timer(3000, new timerPerformed());
                tiempo.start();
                comprobar(arrBot);
            } catch (IOException ex) {
                Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

class timerPerformed implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("A");
    }

}

为什么?使用Swing
定时器
设置为
4000
的延迟,调用时调用
comprobar(arrBot);
。您不能阻止EDT,否则UI将停止响应。请参阅和了解更多详细信息。我尝试了它,但没有工作。可能是我写的行不正确。我更新了post.Move
comprobar(arrBot)
class pulsarBoton implements ActionListener,Serializable{
    @Override
    public void actionPerformed(ActionEvent e) {
        JButton bot=(JButton)e.getSource();
        if (arrBot[0]==null) {
            arrBot[0]=bot;
            arrBot[0].setIcon(new ImageIcon(arr.get(Integer.valueOf(bot.getName()))+".jpg"));//como puedo quitar el texto del boton pero referenciarlo al array??
        }else{
           bot.setIcon(new ImageIcon(arr.get(Integer.valueOf(bot.getName()))+".jpg"));
           arrBot[1]=bot;
           //JOptionPane.showMessageDialog(null, "Continuar");
           //espera(4000);// --> IT DOES NOT WORK AS I WANT
            try {
                Timer tiempo=new Timer(3000, new timerPerformed());
                tiempo.start();
                comprobar(arrBot);
            } catch (IOException ex) {
                Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

class timerPerformed implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("A");
    }

}