等待ActionPerformed

时间:2015-05-29 08:57:03

标签: java swing

我想在actionPerfromed()

之间的arr[1]=bot and try{...内等待

我尝试使用swing.timerThread.sleep(),但它们无法正常工作。如果你需要,我会附上整个程序。

感谢您的帮助。

LINK

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");
            try {
                //espera(4000);// --> IT DOES NOT WORK AS I WANT
                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 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");
    }

}

0 个答案:

没有答案