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

dependent window won't close, causing hang

    XMLWordPrintable

Details

    • sparc
    • generic

    Description


         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

              duke J. Duke
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: