ola! vc pode implementar sua classe com ‘InternalFrameListener’ para habilitar os botões. Segue um exemplo que pode ajudar.
import java.awt.<em>;
import java.awt.event.</em>;
import javax.swing.<em>;
import javax.swing.event.</em>;
public class TFrame extends JFrame implements InternalFrameListener, ActionListener,ItemListener {
JButton btn1, btn2, btn3;
JDesktopPane desktop;
JInternalFrame win1;
JInternalFrame win2;
JInternalFrame win3;
JCheckBox checkbox;
boolean recurso;
public TFrame() {
super("Teste");
desktop = new JDesktopPane();
desktop.putClientProperty("JDesktopPane.dragMode","outline");
setContentPane(desktop);
desktop.setLayout(null);
JPanel pane = new JPanel();
pane.setLayout(null);
btn1 = new JButton("Abrir Janela 1");
btn2 = new JButton("Abrir Janela 2");
btn3 = new JButton("Abrir Janela 3");
checkbox = new JCheckBox("Desabilitar botões quando clicar",true);
recurso = true;
checkbox.addItemListener(this);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
pane.setBounds(0,0,200,500);
btn1.setBounds(20,20,150,22);
btn2.setBounds(20,47,150,22);
btn3.setBounds(20,74,150,22);
checkbox.setBounds(10,101,180,40);
pane.add(btn1);
pane.add(btn2);
pane.add(btn3);
pane.add(checkbox);
desktop.add(pane);
}
public void internalFrameClosing(InternalFrameEvent e) {
}
public void internalFrameClosed(InternalFrameEvent e) {
enableBtns(true);
}
public void internalFrameOpened(InternalFrameEvent e) {
}
public void internalFrameIconified(InternalFrameEvent e) {
}
public void internalFrameDeiconified(InternalFrameEvent e) {
}
public void internalFrameActivated(InternalFrameEvent e) {
}
public void internalFrameDeactivated(InternalFrameEvent e) {
}
private void enableBtns(Boolean v){
btn1.setEnabled(v);
btn2.setEnabled(v);
btn3.setEnabled(v);
}
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.DESELECTED)
recurso = false;
else
recurso = true;
}
public void actionPerformed(ActionEvent e) {
if (recurso)
enableBtns(false);
if (e.getSource().equals(btn1)){
btn1.setEnabled(false);
win1 = new JInternalFrame("Janela 1", true, true, true, true);
win1.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
win1.addInternalFrameListener(this);
win1.setSize(300, 100);
win1.setLocation(200,0);
desktop.add(win1);
win1.show();
} else if(e.getSource().equals(btn2)){
btn2.setEnabled(false);
win2 = new JInternalFrame("Janela 2", true, true, true, true);
win2.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
win2.addInternalFrameListener(this);
win2.setSize(400, 150);
win2.setLocation(200,100);
desktop.add(win2);
win2.show();
} else {
btn3.setEnabled(false);
win3 = new JInternalFrame("Janela 3", true, true, true, true);
win3.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
win3.addInternalFrameListener(this);
win3.setSize(500, 200);
win3.setLocation(200,300);
desktop.add(win3);
win3.show();
}
}
public static void main(String[] args) {
JFrame frame = new TFrame();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(800, 600);
frame.setVisible(true);
}
}