Sicuramente sbagli qlcosa da qlche altra parte, quel codice funziona benissimo:
Codice PHP:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.util.*;
import javax.swing.border.*;
class RicercaBloccatiAction extends AbstractAction
{
JDesktopPane desktop;
JMenuItem tempItem ;
RicercaBloccatiAction(JDesktopPane desktop)
{
super("Allegati bloccati");
this.desktop = desktop;
}
public void actionPerformed(ActionEvent e)
{
tempItem = (JMenuItem)e.getSource();
TrovaAllegatiBloccatiFrame trovaAllegatiBloccatiFrame = new TrovaAllegatiBloccatiFrame(tempItem.getText());
trovaAllegatiBloccatiFrame.setSize(150, 150);
trovaAllegatiBloccatiFrame.setVisible(true);
tempItem.setEnabled(false);
System.out.println("appena disabilitato" + tempItem.getText());
desktop.add(trovaAllegatiBloccatiFrame);
trovaAllegatiBloccatiFrame.moveToFront();
trovaAllegatiBloccatiFrame.addInternalFrameListener(new InternalFrameAdapter()
{
public void internalFrameClosing(InternalFrameEvent ife) {
tempItem.setEnabled(true);
System.out.println("appena abilitato" + tempItem.getText());
}
});
}
}
class TrovaAllegatiBloccatiFrame extends JInternalFrame{
public TrovaAllegatiBloccatiFrame(String title){
super(title,
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
}
}
public class Ciao extends JFrame{
JDesktopPane desktop;
public Ciao(){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
desktop = new JDesktopPane();
getContentPane().add(desktop);
setTitle("Ciao");
setSize(340, 340);
JMenuBar bar = new JMenuBar();
JMenu menu = new JMenu("uffa");
JMenuItem item = new JMenuItem("ciao 1");
item.addActionListener(new RicercaBloccatiAction(desktop));
menu.add(item);
bar.add(menu);
item = new JMenuItem("ciao 2");
item.addActionListener(new RicercaBloccatiAction(desktop));
menu.add(item);
item = new JMenuItem("ciao 3");
item.addActionListener(new RicercaBloccatiAction(desktop));
menu.add(item);
getContentPane().add(bar, "North");
setLocation(0, 0);
validate();
show();
}
public static void main(String[] args){
new Ciao();
}
}
ciao.