Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1233410

calling hide() on a showing dialog will stop the applet

    Details

    • Subcomponent:
    • Resolved In Build:
      1.0.2
    • CPU:
      sparc
    • OS:
      generic, solaris_2.4, solaris_2.5
    • Verification:
      Verified

      Backports

        Description

        If you call hide() on a showing dialog, it causes the entire applet to stop!

        (note: this is not a problem with applicatiions, only applets)


        -------------------------------------------------------------
        import java.awt.*;

        class DialogButton extends Button {
            Window targetDialog;

            public DialogButton(String label, Window target) {
        super(label);
        targetDialog = target;
            }
            public boolean action(Event event, Object obj) {
        if (!targetDialog.isShowing()) {
        targetDialog.show();
        } else
        targetDialog.toFront();
        return true;
            }
        }

        class SampleDialog extends Dialog {
            public SampleDialog(Frame parent) {
        super(parent, "Sample Dialog", false);
        setLayout(new BorderLayout());
        add("North", new Label("This is a Simple dialog", Label.CENTER));
        Panel panel = new Panel();
        panel.setLayout(new FlowLayout());
        panel.add(new Button("OK"));
        add("South", panel);
        pack();
            }
            public boolean action(Event event, Object obj) {
        hide();
        return true;
            }
            public boolean handleEvent(Event event) {
        switch(event.id) {
        case Event.WINDOW_DESTROY:
        hide();
        return true;
        }
          return super.handleEvent(event);
            }
        }

        public class DialogControlPanel extends Panel {
            public DialogControlPanel(Frame frame) {
        setLayout(new FlowLayout());
        SampleDialog dialog = new SampleDialog(frame);
        add(new DialogButton("Show Dialog", dialog));
        FileDialog fdialog = new FileDialog(frame, "Sample File Dialog");
        add(new DialogButton("Show File Dialog", fdialog));
            }
        }

        public class DialogApplet extends java.applet.Applet {

            public Frame getFrame() {
        Component parent = getParent();
        while (!(parent instanceof Frame))
        parent = parent.getParent();
        return (Frame)parent;
            }
            public void init() {
        System.out.println(">> init'd");
        setLayout(new FlowLayout());
        add(new DialogControlPanel(getFrame()));
        show();
            }
            public void start() {
        System.out.println(">> started");
            }
            public void stop() {
        System.out.println(">> stopped");
            }
            public void destroy() {
        System.out.println(">> unloading");
            }
        }

        The description field as copied from bug report 1237658 follows:

        If an applet uses a popup dialog to display some tranisent info, such
        as an error message, when that popup is dismissed ... perhaps by calling
        hide() or dispose() on the popup, then an unexoected side effect is that
        the applet itself gets stopped.

        What appears to happen is that down in awt_Dialog.c, the Dialog_event_handler
        gets an UnmapNotify event, and this is propogated upwards as handleIconify
        on the peer. (This is confusing, for a start, because hide and destroy don't iconify
        the dialog, they unmap it.) However, the upcall continues and becomes
        a WINDOW_ICONIFY event on the dialog. If not trapped and thrown away,
        it is passed all the way up to the AppletPanel, which decides to stop the applet
        there and then.

        Ideally, the applet should not mind about windows other than itself getting WINDOW_ICONIFY events.

        Whatever, the current behaviour is highly non-intuitive!!

        The description field as copied from bug report 1258539 follows:


           a dependent window does not close and causes the entire application to
           hang, when the "hide" method is called.

           reproduce the error with the supplied code:

         run the Hugh program, press Help - About.
           when pressing the "OK" button in the dependent window, any further
           action fails.

           the application works correctly with Win95 x86, with jdk 1.0.2.


        >From: ###@###.### ( Andreas Froehlich (J. Zedler))
        // source code for file Hugh.java follows
        //
        // presumed position where bug occurs is marked as follows:
        // SITE OF BUG
        //

        import java.awt.*;

        public class Hugh extends Frame {

            Panel guiPanel,
                  buttonPanel;

            Choice paraFormat;

            Button boldBtn,
                   italBtn;

            TextArea textArea;

            Menu menuFile,
                 menuEdit,
                 menuFormat,
                 menuHelp;

            MenuItem itemOpen,
                     itemSaveAs,
                     itemExit,
                     itemAbout;

            public Hugh() {

                super("Hugh ");

                MenuBar menuBar;
                Menu menu;


             menuBar = new MenuBar();

                menuFile = new Menu("&File");
                menuFile.add(new MenuItem("&New"));
                menuFile.add(itemOpen = new MenuItem("&Open..."));
                menuFile.add(new MenuItem("&Save"));
                menuFile.add(itemSaveAs = new MenuItem("Save &As..."));
                menuFile.addSeparator();
                menuFile.add(itemExit = new MenuItem("E&xit"));
                menuBar.add(menuFile);

                menuEdit = new Menu("&Edit");
                menuEdit.add(new MenuItem("&Undo"));
                menuEdit.addSeparator();
                menuEdit.add(new MenuItem("Cu&t"));
                menuEdit.add(new MenuItem("&Copy"));
                menuEdit.add(new MenuItem("&Paste"));
                menuBar.add(menuEdit);

                menuFormat = new Menu("F&ormat");
                menuFormat.add(new MenuItem("&Font"));
                menuFormat.add(new MenuItem("&Paragraph"));
                menuBar.add(menuFormat);

                menuHelp = new Menu("&Help");
                menuHelp.add(itemAbout = new MenuItem("&About..."));
                menuBar.add(menuHelp);

                setLayout(new BorderLayout());

                guiPanel = new Panel();
                guiPanel.setLayout(new BorderLayout());


                buttonPanel = new Panel();
                GridBagLayout gbl = new GridBagLayout();
                GridBagConstraints c = new GridBagConstraints();


                buttonPanel.setLayout(new GridBagLayout());

                setLayout(gbl);

                c.fill = GridBagConstraints.BOTH;
                c.weightx = 1.0;

                paraFormat = new Choice();
                  paraFormat.addItem("Headline");
                  paraFormat.addItem("Sub-Headline");
                  paraFormat.addItem("numbered");
                  paraFormat.addItem("bulleted");
                paraFormat.addItem("regular");
                gbl.setConstraints(paraFormat, c);
                add(paraFormat);

                italBtn = new Button ("Italic");
                gbl.setConstraints(italBtn, c);
                add(italBtn);


                boldBtn = new Button ("Bold");
                c.gridwidth = GridBagConstraints.REMAINDER;
                gbl.setConstraints(boldBtn, c);
                add(boldBtn);

                textArea = new TextArea();

                c.weightx = 0.0;
                c.fill = GridBagConstraints.VERTICAL;
                c.gridwidth = GridBagConstraints.REMAINDER;
                gbl.setConstraints(textArea, c);
                add(textArea);

                setMenuBar(menuBar);

                move(200,200);
                resize(400,300);

             show();
            } // public hugh

            public boolean action(Event event, Object arg)
            {
             if (event.target instanceof MenuItem) {
             MenuItem menuItem = (MenuItem)event.target;
             Menu menuParent = (Menu)(menuItem.getParent());

             if (menuParent == menuFile) {
        if (menuItem == itemOpen)
        (new FileDialog(this, "Open...")).show();

                        else if (menuItem == itemSaveAs)
                            (new FileDialog(this, "Save As...")).show();

             else if (menuItem == itemExit)
        (new QuitDialog(this)).show();

             } else if (menuParent == menuHelp) {
        if (menuItem == itemAbout)
             (new AboutDialog(this)).show();
             }
            }

                return true;
            }

            public boolean handleEvent(Event event) {
             if (event.id == Event.WINDOW_DESTROY)
             {
              //(new QuitDialog(this)).show();
             System.out.println("Hugh:Window_destroy");
             System.exit(0);
             }

             return super.handleEvent(event);
            }

            public static void main(String args[]) {
                new Hugh();
            }
        }

        // import java.awt.*;

        //
        // In dieser Klasse AboutDialog
        // steckt der ?Fehler?
        // m.e. in der handleEvent - methode
        //


        class AboutDialog extends Dialog {

            public AboutDialog(Frame parent) {
        super(parent, "About", true);

        setLayout(new FlowLayout());

                add("Center", new Label("Hugh "
                                      , Label.CENTER));
             add("South", new Button("OK"));

             reshape(30, 30, 200, 90);

             setResizable(false);
            }

            public synchronized void show() {
             Rectangle bounds = getParent().bounds();
             Rectangle abounds = bounds();

             move(bounds.x + (bounds.width - abounds.width)/ 2,
             bounds.y + (bounds.height - abounds.height)/2);

             super.show();
            }

            public synchronized void wakeUp() {
             notify();
            }

            public boolean handleEvent(Event e) {
             if (e.id == Event.WINDOW_DESTROY) {

        // SITE OF BUG

             hide(); // SITE OF BUG

        // SITE OF BUG

             return true;
             } else
             return super.handleEvent(e);
            }

            public boolean action(Event e, Object arg) {
             if (((String)arg).equals("OK"))
             hide();

             return true;
            }
        } //class AboutDialog


        class QuitDialog extends Dialog {

            public QuitDialog(Frame parent) {
             super(parent, "Quit Application?", true);
             setLayout(new FlowLayout());

             add(new Button("Yes"));
             add(new Button("No"));

             reshape(30, 30, 200, 60);

             setResizable(false);
            }

            public synchronized void show() {
             Rectangle bounds = getParent().bounds();
             Rectangle abounds = bounds();

             move(bounds.x + (bounds.width - abounds.width)/ 2,
                    bounds.y + (bounds.height - abounds.height)/2);

             super.show();
            }

            public synchronized void wakeUp() {
             notify();
            }

            public boolean handleEvent(Event e) {
        if (e.id == Event.WINDOW_DESTROY) {
        hide();

        return true;

        } else
        return super.handleEvent(e);
            }

        /*
            public boolean handleEvent(Event e) {
        if (e.id == Event.WINDOW_DESTROY)
        {
        hide();
        System.out.println("Hide");

        // return true;
        return super.handleEvent(e);
        }
        else
        {
        System.out.println("super.handleEvent");
        return super.handleEvent(e);
        }
            }
        */

            public boolean action(Event e, Object arg) {
             String label = (String)arg;

             if (label.equals("Yes"))
             System.exit(0);

             else if (label.equals("No"))
             hide();

             return true;
            }
        } // class QuitDialog

        // end of source code Hugh.java



        class QuitDialog extends Dialog {

            public QuitDialog(Frame parent) {
             super(parent, "Quit Application?", true);
             setLayout(new FlowLayout());

             add(new Button("Yes"));
             add(new Button("No"));

             reshape(30, 30, 200, 60);

             setResizable(false);
            }

            public synchronized void show() {
             Rectangle bounds = getParent().bounds();
             Rectangle abounds = bounds();

             move(bounds.x + (bounds.width - abounds.width)/ 2,
                    bounds.y + (bounds.height - abounds.height)/2);

             super.show();
            }

           public synchronized void wakeUp() {
             notify();
            }

            public boolean handleEvent(Event e) {
        if (e.id == Event.WINDOW_DESTROY) {
        hide();

        return true;

        } else
        return super.handleEvent(e);
            }

        /*
            public boolean handleEvent(Event e) {
        if (e.id == Event.WINDOW_DESTROY)
        {
        hide();
        System.out.println("Hide");

        // return true;
        return super.handleEvent(e);
        }
        else
        {
        System.out.println("super.handleEvent");
        return super.handleEvent(e);
        }
            }
        */

            public boolean action(Event e, Object arg) {
             String label = (String)arg;

             if (label.equals("Yes"))
             System.exit(0);

             else if (label.equals("No"))
             hide();

             return true;
            }
        } // class QuitDialog

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  amfowler Anne Fowler (Inactive)
                  Reporter:
                  amfowler Anne Fowler (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: