Results 1 to 6 of 6
  1. #1
    bentley4 is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default opening applet in seperate window vs in the page.

    Hi guys,

    What is the difference in java code between opening an applet in a seperate window and loading it into the html page?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Can you give us more information? What do you mean by opening in a "separate window"? as in using a JDialog?

  3. #3
    bentley4 is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    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.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Or an application (not an Applet) launched via WebStart.
    Lesson: Java Web Start (The Java™ Tutorials > Deployment)

    db

  6. #6
    pseeburger is offline Member
    Join Date
    Jan 2012
    Posts
    14
    Rep Power
    0

    Default 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:
    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);
    
        }
    }
    Here is the code for appletBox:

    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);
        }
    }
    Let me know if this is useful!

    Paul

Similar Threads

  1. Oracle Forms Opening in single Java window
    By jav786 in forum Java Applets
    Replies: 0
    Last Post: 03-31-2011, 10:53 AM
  2. mysql (Basic opening page operation using database)
    By efozdel in forum New To Java
    Replies: 7
    Last Post: 08-03-2010, 08:23 AM
  3. opening default browser window in invisible mode
    By robby14 in forum Advanced Java
    Replies: 1
    Last Post: 02-20-2010, 01:50 AM
  4. Opening applet with .html file
    By Atriamax in forum New To Java
    Replies: 12
    Last Post: 09-13-2009, 06:26 AM
  5. Opening frame/page options
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-10-2008, 02:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •