Galera, estou fazendo um jogo da memória. Estava com problema em deixar imagens clicadas à mostra. Estava usando o Thread.sleep(); mas tava dando problema. Resolvi tentar usar o wait(); ta funcionando de boa, mas no eclipse ocorre o seguinte erro:
Exception in thread “AWT-EventQueue-0” java.lang.IllegalMonitorStateException
at java.lang.Object.wait(Native Method)
at Memoria2$TratarEventos.actionPerformed(Memoria2.java:84)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
o código é esse:
public void actionPerformed (ActionEvent evento) {
for (int i = 0; i < botao.length; i++) {
if (evento.getSource() == botao[i]) {
botao[i].setIcon(icones[i]);
temp = new Timer (2500, this);
temp.start();
if (but1 ==-1) {
but1 = i;
jogada++;
}
else {
but2 = i;
jogada++;
}
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Pelo que percebi, o wait () se refere ao Timer, correto?