A second window from an applet?

I want to add a second window with a frame in it to my applet but only popup when a button is hit. I do know that is the actionperformed deal but not anything about adding this second window.

BaffyOfDaffyA wrote:
Run this any time before the button is visible
....I hope this helpsI doubt whether the OP really wants a JFrame and a JApplet together, though I could be wrong. The standard way to do what he wants (I believe ) is with a JDialog. Here's a trivial example of what I mean:
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Window;
import java.awt.Dialog.ModalityType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.InvocationTargetException;
import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class FuJApplet extends JApplet
    public void init()
        try
            SwingUtilities.invokeAndWait(new Runnable()
                public void run()
                    // create a JPanel with JButton that goes into the
                    // JApplet's contentPane
                    JButton newDialogBtn = new JButton("New Dialog");
                    newDialogBtn.addActionListener(new ActionListener()
                        public void actionPerformed(ActionEvent arg0)
                            openNewDialog();
                    JPanel btnPanel = new JPanel();
                    btnPanel.add(newDialogBtn);
                    getContentPane().add(btnPanel);
        catch (InterruptedException e)
            e.printStackTrace();
        catch (InvocationTargetException e)
            e.printStackTrace();
    // method to create and show a new JDialog
    private void openNewDialog()
        // first create a JPanel and components that goes in the JDialog
        JLabel titleLbl = new JLabel("My New Dialog");
        titleLbl.setFont(titleLbl.getFont().deriveFont(Font.BOLD, 48));
        JButton exitBtn = new JButton("Exit");
        exitBtn.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                Window dialogWindow = SwingUtilities
                    .getWindowAncestor((JButton) e.getSource());
                dialogWindow.dispose();
        JPanel exitBtnPanel = new JPanel();
        exitBtnPanel.add(exitBtn);
        JPanel dialogPanel = new JPanel(new GridLayout(0, 1, 10, 10));
        dialogPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
        dialogPanel.add(titleLbl);
        dialogPanel.add(exitBtnPanel);
        // then create the JDialog and add the JPanel above, pack it, show it
        JDialog dialog = new JDialog(
            (Window) SwingUtilities.getWindowAncestor(this),
            "New Dialog",
            ModalityType.APPLICATION_MODAL);
        dialog.getContentPane().add(dialogPanel);
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
}

Similar Messages

  • Closing browser window from an Applet?

    I've written a series of applets that perform different functions. I placed a button on each applet with the purpose to close the window in which that applet is running. However I don't even know where to start looking to find out how to make my applet close it's own browser window. I know how to open a new browser window from an applet but not vice versa.
    Can anyone help please?
    Mark.

    Right, I sort of tracked down some code that uses getMethods to allow me to invoke a Javascript command. It is not pretty and took a little bit of editing to get to work but it does the job without putting JS stuff into my HTML.
    However it is causing some problems. If I open one of my other applets it will only let me close that window and the previous applets ceases to respond at all. I think this may be because the invoke gets the JSObject which is the window and somehow having more than one applet open in different windows is causing it to get confused and is locking the first window and only responding to the second.
    I have seen a much simpler method that uses:
    import netscape.javascript.*;
    and JSObject to get the window but my compiler complains about the import. Any further suggestions or an example would be welcome as my current solution is a bit limited as you can effectively only have one window open at a time which doesn't suit my needs.
    Many thanks.
    Mark.

  • Open a second window from the first one

    Hi,
    The problem of my application is loosing control when I open the second window, so I know that the problem is the run of the sub VI but I don't find an other possibility to open a second window from the first one knowing that the first sends its vales to the second one. In an other way I want to open two windows simutaneously.
    NB: I attached  a simple verssion of my application.
    Can someone help me please.
    Attachments:
    The main VI.vi ‏21 KB
    The su b VI.vi ‏28 KB

    Hi Basile,
    why do you open a new thread again? Didn't the older one provide a solution?
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Creating a popup browser window from an applet

    Hi, in a java applet that I am developing i use AppletContext.showDocument to load a web-page. The thing is i want this window to be a popup, devoid of toolbar and statusbar, etc. do you have any idea on how i could accomplish this?
    I tried to do it with javascript, but i could only create new pop-up child windows of the html file that contained the method for opening pop-ups, i could not change the parent window itself to become a popup.
    If you have any idea on how to either create a pop-up type window from an applet, or make the current window into a popup i would be grateful to hear it.

    The only way I can think of is to use JSObject to call JavaScript on the current page & have JavaScript do a window.open
    http://forum.java.sun.com/thread.jsp?forum=31&thread=295808

  • Problem in Closing Browser window from an Applet.

    I have wriiten a small Applet progarm that calls a Javascript function in the opening window, to close the window in which it is loaded.The Applet window is a PopUp window from one of my application's window.
    First time I start my application and load that Applet and then close the frame window,it works fine that the browser window will close, when the frame window is closed.It calls the window closing event in that applet stop method is called and In stop methd a closeLaunchedBrowser method will called this has a Javascript method and the Method closes the window using the self.close() method.
    But now if I continue this process of launching applet and then closing frame window, initial 1 or 2 steps it has know problem when I continue this, after 3 or 4 steps, it result in browser hang/crash.
    I am using java version 1.4.2_01 or higher and IE or Firefox(any other NetScape based) browser to load applet.It works fine with IE but getting problem in case of Firefox(any other NetScape based).
    The error dialog information and related event log generated is shown below :
    The dialog which is displayed before crashing of firefox has information :
    "firefox.exe has generated errors and it will closed by windows.you will need to restart the program.
    An error log is being created."
    The error log information :
    Source : Browser Event ID: 8032
    "The browser service has failed to retrieve the backup list too many times on transport \Device\NetBT_Tcpip_{611A64A2-8F4B-409E-9AB2-0D9BF741E791}. The backup browser is stopping.
    The code related to this is given below.
    import javax.swing.JApplet;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import netscape.javascript.JSObject;
    public class TestApplet extends JApplet {
    protected JSObject win = null;
    private JFrame frame = null;
    private boolean alreadyClosed = false;
    public void init(){
    this.win = JSObject.getWindow(this);
    frame = new JFrame("Test Frame");
    frame.setSize(300, 400);
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.out.println("windowClosing");
    TestApplet.this.stop();
    frame.show();
    public void stop() {
    if (!alreadyClosed) {
    alreadyClosed = true;
    closeLaunchedBrowser();
    System.gc();
    System.runFinalization();
    private void closeLaunchedBrowser() {
    final TestApplet thisObject = this;
    Runnable r = new Runnable() {
    public void run() {
    try {
    JSObject win = (JSObject)JSObject.getWindow(thisObject);
    if (win != null && win.toString() != null) {
    //win.eval("top.opener=self;self.close();");
    //win.call("close", null);
    win.eval("self.close();");
    } catch (Exception e) {
    Thread t = new Thread(r);
    t.start();
    }If any one know solution regarding how to aviod this crash of browser please let me know. I will be very thankful to you.
    Thanks.

    Right, I sort of tracked down some code that uses getMethods to allow me to invoke a Javascript command. It is not pretty and took a little bit of editing to get to work but it does the job without putting JS stuff into my HTML.
    However it is causing some problems. If I open one of my other applets it will only let me close that window and the previous applets ceases to respond at all. I think this may be because the invoke gets the JSObject which is the window and somehow having more than one applet open in different windows is causing it to get confused and is locking the first window and only responding to the second.
    I have seen a much simpler method that uses:
    import netscape.javascript.*;
    and JSObject to get the window but my compiler complains about the import. Any further suggestions or an example would be welcome as my current solution is a bit limited as you can effectively only have one window open at a time which doesn't suit my needs.
    Many thanks.
    Mark.

  • I attempt to open a second window from the icon but it does not open then when firefox is closed it will not reopen because it is still running in processes but no window displayed until you kill the process and then restart firefox.

    I attempted to open a new window from the Firefox icon but nothing happens. I then went on browsing and closed Firefox but was later unable to open it. I checked processes and it was already running but there was no window displayed. I am running Windows 7 Professional.
    This is repeated any time I already have the browser open and wish to open a second instance.

    '''<u>Open a second window (not a second tab, that is different) when Firefox is already running and displayed on the monitor</u>'''
    *Firefox button > New Tab > New Window
    *CTRL+N
    *'''''If using the Menu Bar''''': File > New Window
    **To '''''temporarily''''' display and make choices from the Menu Bar press the ALT key or the F10 key
    **Also see: https://support.mozilla.com/en-US/kb/Menu%20bar%20is%20missing
    '''<u>Firefox "hang on exit"</u>'''
    #Stop the Firefox process:
    #*[http://kb.mozillazine.org/Kill_application Mozillazine - Kill application]
    #*Windows 7 users click [http://www.techrepublic.com/blog/window-on-windows/reap-the-benefits-of-windows-7s-task-manager/2576 here]
    #Why Firefox may hang:
    #*[http://support.mozilla.com/en-US/kb/Firefox+hangs Firefox hangs] (see Hang at exit)
    #*[http://kb.mozillazine.org/Firefox_hangs Firefox hangs (Mozillazine)] (see Hang at exit and Closing Firefox properly)
    #*[https://support.mozilla.com/en-US/kb/Firefox+is+already+running+but+is+not+responding Firefox is already running but is not responding]
    #Use Firefox Safe Mode to find a problem with an Extension or Plugin:
    #*Don't check anything when entering Safe Mode, just continue
    #*If the problem does not occur in Safe Mode it is probably and Extension or Plugin causing the problem
    #*See:
    #**[[Safe Mode]] and [http://kb.mozillazine.org/Safe_Mode Safe Mode (Mozillazine)]
    #**[http://support.mozilla.com/en-US/kb/Troubleshooting+extensions+and+themes Troubleshooting extensions and themes]
    #**[http://support.mozilla.com/en-US/kb/Troubleshooting+plugins Troubleshooting plugins]
    #**[http://support.mozilla.com/en-US/kb/Basic+Troubleshooting Basic Troubleshooting]
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''

  • How do I create a window from an applet?

    I am trying to create a window application from an applet. The window that I need should meet the following criteria:
    1. The window application will be created when I click on one of the buttons in the applet.
    2. If I close the applet from the browser, the window application should not be affected.
    3. I should be able to close the window by clicking the X icon on the upper right corner.
    4. The window application works by itself. It does not need to interact with the applet any more.
    Is there any example similar to what I am looking for available?

    1. Easy.
    Button myButton = new Button( "a button" ) ;
    myButton.addActionListener( new ActionListener()
    public void actionPerformed( ActionEvent e )
    Frame myFrame = new Frame( "a frame" ) ;
    myFrame.show() ;
    add( myButton ) ;2. Short answer, can't be done. Long answer, I think it can be done with something called "Java WebReady", but I don't how. (needs JDK 1.4, I think)
    3. Easy. You just have to add a window listener to the frame.
    class closeWindowListener extends WindowAdapter
         private Frame myFrame ;
         closeWindowListener( Frame myFrame )
              this.myFrame = myFrame ;
         public void windowClosing( WindowEvent e )
              myFrame.dispose() ;
    myFrame.addWindowListener( new closeWindowListener( myFrame ) ) ;
    myFrame.show() ;4. Fine with me, but keep in mind the difficulty of #2.

  • Open new browser window from an Applet

    I have an applet that needs to initiate a new browser window to open and go to a specified URL. Can anyone help me with this?? Thanks in advance.

    http://developer.java.sun.com/developer/qow/archive/48/index.html

  • Is it possible to open a browser window from an applet?

    Hi,
    this might seem a simple beginners question to you, but to me it is more like a nightmare.
    Is it possible to have a link in an Applet that opens up a new browser
    window with a fixed address??
    If yes, can anybody tell me how? or where can I find documentation about it?
    Please help me.
    Thanks.
    dunja

    myApplet.getAppletContext().showDocument(URL url, String target);
    TARGET:
    "_self" Show in the window and frame that contain the applet.
    "_parent" Show in the applet's parent frame. If the applet's frame has no parent frame, acts the same as "_self".
    "_top" Show in the top-level frame of the applet's window. If the applet's frame is the top-level frame, acts the same as "_self".
    "_blank" Show in a new, unnamed top-level window.
    name Show in the frame or window named name. If a target named name does not already exist, a new top-level window with the specified name is created, and the document is shown there.

  • Open a new Window from Applet --- beginner

    Hi all,
    I need to open a browser window from an applet and control the window properties (width, height .. etc). Can anyone please give a code example for this
    thank you.

    hi
    First, thank you for your reply.
    Second, I need to know how could I found this Netscape calss to can be abelto import it.
    And I want to know if it will work on (IE) browsers or it is just working on Netscape Browser.
    Thank you again :)

  • Remove "Java Applet Window" from the window

    Hi, can anyone tell me how to remove the word "Java Applet Window" from a applet/frame/dialog running on the browser? Thank you very much.
    yunhe

    You have to sign your applet. Make a search on how to do that. It's not that easy and you need a certificate.

  • Opening and closing a frame from an applet security problem

    can I open a frame or a window from an applet and close the frame by using
    System.exit(0) for the frame or will it throw a security problem.

    I am using system.exit(0) to exit the JVM.
    dispose()
    Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.
    If this frame have to be close and open again don't use dispose.
    there is no check whether a frame is active? what you can do is set the the new frame to null (frame = null) and also when you dispose it, this will let you know if the frame is active or not.
    Noah

  • Can i open a page in Browser from an applet

    i want to open a web site in a new browser window from an applet.
    Is it possible. if posible then send me some links or codes
    thank you

    Do you know how to use applet to link to another webpage? set the target = _blank
    public class App extends Applet {
    getAppletContext().showDocument(new URL("http://java.sun.com"),"_blank");
    }

  • How can I open two windows from one submit?

    Is there a way to open two browser windows from one click of a button to submit a form? I have a button on a screen that does some processing of the data and then generates a PDF file with the output. I would also like it to run a report and show the output of that in a separate window. I realize that using regular HTML with a target of "_blank" on the form, you can have the results show in a new window, but how can I launch a second window from a single button click, if possible?
    Thanks!

    It can be possible using two different popUps instead windows. Onclick on the button just make vissible true of those two popup in the event method, before making visible true, do the business operation to show on the popups. So simple :)
    Note: Popup has modal=false attribute
    Edited by: man_ish on Jan 12, 2010 10:13 AM

  • Can not copy dll to system 32 in windows 7 while applet loading

    I am using the jniwarapper to access registry information in windows from my applet. The applet i signed. In windows xp, able to copy the jniwrap.dll from server path to the system 32 on the client computer. But from windows 7 , not able to copy though having the administrator previleges.
    Is it purely windows 7 specific or do i have any other option to copy the dll files to the system 32 folder on windows 7?

    HI,
    I used the below jnlp file
    <?xml version="1.0" encoding="UTF-8"?>
    <jnlp href="java2d.jnlp">
    <information>
    <title>Java2D Demo</title>
    <vendor>My Company, Inc.</vendor>
    <offline-allowed />
    </information>
    <resources>
    <j2se version="1.4+" href="http://java.sun.com/products/autodl/j2se" />
    <jar href="myapplet.jar" main="true" />
    <nativelib href="mydlls.jar"/>
    </resources>
    <applet-desc name="MyFileAccess" main-class="com.applet.MyFileAccess" width="710" height="540">
    </applet-desc>
    </jnlp>
    mydlls.jar contain the jniwrap.dll file. i have copied the jniwrap.lic to META-INF folder of myaaplet.jar file.
    The dll is recognized by JVM and also license verification is success.
    But got the below error still, i have the b.class in the applet jar itself.
    Exception in thread "thread applet-ge.indsys.applet.MyFileAccess-1" java.lang.NoClassDefFoundError: com/jniwrapper/b (wrong name: com/jniwrapper/B)
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(Unknown Source)
         at java.security.SecureClassLoader.defineClass(Unknown Source)
         at java.net.URLClassLoader.defineClass(Unknown Source)
         at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.defineClassHelper(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.access$400(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
         at sun.plugin2.applet.JNLP2ClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
         at com.jniwrapper.Pointer$Void.<init>(SourceFile:491)
         at com.jniwrapper.Pointer$Void.<init>(SourceFile:482)
         at com.jniwrapper.win32.Handle.<init>(SourceFile:17)
         at com.jniwrapper.win32.registry.RegistryKey.<init>(SourceFile:100)
         at com.jniwrapper.win32.registry.RegistryKey.<clinit>(SourceFile:20)
         at com.applet.MyFileAccess.addIE8Key(MyFileAccess.java:1096)
         at com.applet.MyFileAccess.init(MyFileAccess.java:3794)
         at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    copied the class files to mydlls.jar also, same exception. Please suggest.
    Edited by: user13722950 on Feb 22, 2011 12:35 AM

Maybe you are looking for

  • Fixed Asset conversion :Transaction AS100

    Hi guys, Have any one used AS100 for fixed asset conversion. Is this option  better than LSMW. How the excel file is sorted to special format. Thanks. Saeed

  • Urgent:Upgrade JRE 1.1.7 to 1.3 for Weblogic 4.5.1

    Hi! I have Weblogic 4.5.1 running on JRE 1.1.7,SPARC Solaris 2.6 platform.I need to upgrade the JRE to 1.3.I am given to understand that there are no issues about this w.r.t Weblogic(see http://www.weblogic.com/platforms/index.html#solaris).But I hav

  • I can't use edit in BC admin

    I can not edit my pages in Edit mode in BC admin. I got an error that some javascript is missing and page is not working correctly. Also error message said I should empty browsers cache but it did not help. Kind regards, Susi

  • IPad slow in re-connecting to a known WiFi network

    Hi all, I have noticed that my iPad is sometimes slow in re-connecting to a known wi-fi network (my home network). I have been doing some online research and it seems like it's an issue apple acknowledged. Normally it connects right away, other times

  • Questions Re: Logging In/Out

    I'm going to use a software program to copy my hard drive to an external hard drive before I upgrade to Leopard. The instructions suggest I log out of my account, then log back in with the shift key held down. Before I do that, I want to know exactly