Results 1 to 6 of 6
- 06-04-2011, 03:50 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 6
- Rep Power
- 0
-
Can you give us more information? What do you mean by opening in a "separate window"? as in using a JDialog?
- 06-04-2011, 04:43 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 6
- Rep Power
- 0
I mean such as in this example:
2-D Vector Field Simulation
I don't know which part of the java code is responsible for that behaviour. It certainly isn't html, I've checked.
-
It has the source code on that site and in it you'll see that they're creating one or several Frame objects which are likely what is being displayed. I recommend using Swing instead of AWT meaning using JApplets and perhaps JDialogs to show separate stand-alone windows.
- 06-04-2011, 08:23 PM #5
Or an application (not an Applet) launched via WebStart.
Lesson: Java Web Start (The Java™ Tutorials > Deployment)
db
- 01-21-2012, 05:43 AM #6
Member
- Join Date
- Jan 2012
- Posts
- 14
- Rep Power
- 0
Re: opening applet in seperate window vs in the page.
Hopefully this reply is useful to someone. I realize that the discussion began last summer, but I actually have a good answer to this question, and I have benefited so often from forums like these in the past, I wanted to give something back.
I've just implemented this option with my applet. That is, the applet can be either opened as usual to appear in the browser webpage, or it can be opened to display in a separate JFrame.
I have implemented it using three separate classes. The first I call the Launcher and it resides in the webpage as a normal JApplet. I also place a button on it that will bring up the applet in the JFrame when it loses the focus.
The second is a JApplet that extends the applet that I want to display in the separate frame. I call is the appletBox.
Its job is to override the basic applet commands that are used in my JApplet and relay them to the Launcher applet (called myBaseApplet in the appletBox). It also creates the JFrame that displays the applet. This part could have been done in the Launcher applet, but the overriding applet i/o calls would have been difficult. See the code for this also below.
Code for the Launcher applet is here:
Here is the code for appletBox:Java Code:public class Launcher extends JApplet { appletBox box; public void init() { //Execute a job on the event-dispatching thread: //creating this applet's GUI. try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { createGUI(); } }); } catch (Exception e) { System.err.println("createGUI didn't successfully complete"); System.out.println("\r\nError Log:"+e.toString()); System.out.println("\r\n"); e.printStackTrace(); } } public void createGUI() { JButton button = new JButton("Click to use the Applet!"); button.setFont(new Font("Serif", Font.BOLD, 20)); Container cp = getContentPane(); cp.setLayout(new GridLayout(3, 1)); cp.add(new JPanel()); JPanel jp = new JPanel(new FlowLayout()); jp.add(button); cp.add(jp); button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { box.show(); } }); box = new appletBox(this); } }
Let me know if this is useful!Java Code:public class appletBox extends myApplet { JApplet myBaseApplet; JFrame window; /** Creates a new instance of appletBox */ public appletBox(JApplet applet) { myBaseApplet = applet; createGUI(); } public void show() { window.setVisible(true); window.setExtendedState(Frame.NORMAL); plot.requestFocus(); } public void destroy() { super.destroy(); window.dispose(); } public void createGUI() { super.createGUI(); //... Create a window (JFrame) and make applet the content pane. window = new JFrame("Have Fun!"); window.setContentPane(this); window.pack(); // Arrange the components. // window.setSize(900, 700); // setSize(900, 650);//800, 550); // if (myBaseApplet.getToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH)) { // window.setExtendedState(window.getExtendedState()|JFrame.MAXIMIZED_BOTH); // System.out.println(" extended state supported!"); // } // else { Dimension D = myBaseApplet.getToolkit().getScreenSize(); D.height=(int)(D.height*.95); window.setSize(D); // } Dimension d = window.getSize(); window.setSize((int)(d.width*.8), (int)(d.height)); super.start(); window.setVisible(true); // Make the window visible. super.Resized(); window.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); } public java.applet.AppletContext getAppletContext() { return myBaseApplet.getAppletContext(); } public java.net.URL getDocumentBase() { return myBaseApplet.getDocumentBase(); } public java.net.URL getCodeBase() { return myBaseApplet.getCodeBase(); } public Image getImage(java.net.URL url, String name) { return myBaseApplet.getImage(url, name); } public String getParameter(String arg) { return myBaseApplet.getParameter(arg); } }
Paul
Similar Threads
-
Oracle Forms Opening in single Java window
By jav786 in forum Java AppletsReplies: 0Last Post: 03-31-2011, 10:53 AM -
mysql (Basic opening page operation using database)
By efozdel in forum New To JavaReplies: 7Last Post: 08-03-2010, 08:23 AM -
opening default browser window in invisible mode
By robby14 in forum Advanced JavaReplies: 1Last Post: 02-20-2010, 01:50 AM -
Opening applet with .html file
By Atriamax in forum New To JavaReplies: 12Last Post: 09-13-2009, 06:26 AM -
Opening frame/page options
By Java Tip in forum Java TipReplies: 0Last Post: 03-10-2008, 02:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks