SwiXml: 5th solution for internalframe initiation?
[email protected] Wed, 30 Mar 2005 19:11:35 +1000 (EST)
| Newsgroups | gmane.comp.embedded.carlsbad-cubes |
|---|---|
| Message-ID | <[email protected]> |
Hi,
could someone please advise me (and others) - what is
the best aproach for internalframe initiation?
I've come up with 4 (3 SwingEngine based, 1
programatic). See the bellow code.
I think the best aproach is with Option 3, but without
the getSubWindow() method (should work just similary
to programatic Option 4). But how can you do it with
SwingEngine?
Thanks,
Peter
--------------------------------------
--------------------------------------
[MainWindow.java]:
import org.swixml.SwingEngine;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
public class MainWindow {
private SwingEngine swix;
public JDesktopPane desktopPane;
public MainWindow() throws Exception {
swix = new SwingEngine(this);
swix.render("xml/MainWindow.xml");
Container rootContainer = swix.getRootComponent();
rootContainer.setVisible(true);
}
public static void main(String[] args) throws
Exception {
new MainWindow();
}
public AbstractAction actionMailRegister = new
AbstractAction() {
public void actionPerformed(ActionEvent a) {
try {
/* Option 1: passing in SwingEngine reference
SubWindow subWindow = new SubWindow(swix);
desktopPane.add(swix.getRootComponent());
swix.getRootComponent().show();
// */
/* Option 2: passing in JDesktopPane reference
SubWindow subWindow = new SubWindow(desktopPane);
// */
//* Option 3: calling getSubWindow method
SubWindow subWindow = new SubWindow();
desktopPane.add(subWindow.getSubWindow());
// */
/* Option 4: direct/programatic internalframe
creation (no SwiXml)
// seems the best aproach, but how can this be
done with SwingEngine?
// NOTE: Uncomment Contructor 4, and commnet
Constractor 3 in SubWindow class when using this
Option
SubWindow subWindow = new SubWindow();
desktopPane.add(subWindow);
// */
} catch (Exception e) {
//
}
}
};
}
--------------------------------------
File:[SubWindow.java]
import org.swixml.SwingEngine;
import javax.swing.*;
import java.awt.*;
public class SubWindow extends JInternalFrame {
private JInternalFrame subWindow = this;
//* Constructor 1
public SubWindow(SwingEngine swix) throws Exception {
swix.render("xml/SubWindow.xml");
System.out.println("Constructor 1");
}
// */
//* Constructor 2
public SubWindow(JDesktopPane desktopPane) throws
Exception {
Component subWindow = new
SwingEngine(this).render("xml/SubWindow.xml");
desktopPane.add(subWindow);
subWindow.show();
desktopPane.validate();
System.out.println("Constructor 2");
}
// */
//* Constructor 3 and get
public SubWindow() throws Exception {
SwingEngine swix = new SwingEngine(this);
subWindow = (JInternalFrame)
swix.render("xml/SubWindow.xml");
subWindow.show();
System.out.println("Constructor 3");
}
public JInternalFrame getSubWindow() {
return subWindow;
}
// */
/* Constructor 4 -> Window created directly, without
SwiXml
public SubWindow() {
super("Sub Window",
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
//...Create the GUI and put it in the
window...
//...Then set the window size or call pack...
setSize(300,300);
show();
System.out.println("Constructor 4");
}
// */
}
--------------------------------------
File:[xml/MainWindow.xml]
<frame size="800,600" title="Main"
DefaultCloseOperation="JFrame.EXIT_ON_CLOSE"
Location="100,100">
<menubar name="menubar">
<menu text="File">
<menuitem name="miNewSubWindow" text="New Sub
Window"
Action="actionMailRegister" />
</menu>
</menubar>
<desktoppane id="desktopPane" />
</frame>
--------------------------------------
File:[xml/SubWindow.xml]
<internalframe size="600,480" title="Sub Window" />
--------------------------------------
--------------------------------------
Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com