MDI Aplication -JButton and JInternalFrame
Hi.
I am starting to learn MDI, already made some test, but i have a problem that i cant resolve.
I have a small application where the objective is, going to menu, click on "new doc". When i click i add a button to a toolbar and at the same time create a JInternalFrame in a DesktopPane. My problem is, i cant associate the button, to the JInternalFrame.
For example:I have multiples JInternalFrame in a DesktopPane, and i want to, when click on the button "1", appear my JInteranalframe "1".
I want to associate button1 to JInternalFrame1, button2 to JInternalFrame2, etc.
Thanks for you attention, and i hope some help :)
[662 byte] By [
DrSnakea] at [2007-11-27 1:51:44]

# 1
One way to use AbstractAction...
That is, create a class which will take three parameters
first is the text which is to be displayed on the toolbar button
one is desktopPane on which the internal frame should get displayed second one is your internalFrame reference... for example
class ButtonAction extends AbstractAction {
private final JDesktopPane jdp;
private final JInternalFrame jif;
public ButtonAction(String title, JDesktopPane jdp, JInternalFrame jif) {
super(title, null);
this.jdp = jdp;
this.jif = jif;
}
public void actionPerformed(ActionEvent ae) {
try {
jdp.remove(jif);
jdp.add(jif);
jif.setVisible(true);
jif.setSelected(true);
} catch (Exception e) {
}
}
}
now create an object of the above class and add it to toolbar on menu click... for example...
// on menu ckick do the following...
toolbar.add(new ButtonAction());