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

Timing sensitivity when displaying dialogs

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description

      The enclosed application has a frame with a menu bar which has
      a help menu. The help menu has an About entry which pops up
      a standard dialog containing strings previously given.

      Almost.

      It flashes up the dialog, but it disappears immediately,
      leaving a brief afterflow on the screen :-)

      Surprisingly, if I add in a printstatment between the calls of
      pack() and show() for the dialog, it displays correctly.

      There is a print statement in the code that prints "delay" ...
      try running the program with and without the comment characters.



      import java.awt.Dialog;
      import java.awt.Dimension;
      import java.awt.Event;
      import java.awt.Frame;
      import java.awt.GridBagConstraints;
      import java.awt.GridBagLayout;
      import java.awt.Label;
      import java.awt.Menu;
      import java.awt.MenuBar;
      import java.awt.MenuItem;
      import java.awt.Panel;
      import java.awt.Rectangle;

      public class Main extends Frame
      {
          public static void main(String[] args) {
      Main m = new Main();
      m.show();
          }

          Main() {
      super("DEMO");

      add("Center", new Label("DEMO"));

      MenuBar mb = new MenuBar();
      Menu helpMenu = new Menu("Help");
      helpMenu.add(new HelpAbout(this, "About", "DEMO", aboutInfo));
      mb.add(helpMenu);
      mb.setHelpMenu(helpMenu);
      setMenuBar(mb);

      pack();
          }


          static String[] aboutInfo = {
              "DEMO",
              "Jonathan Gibbons",
              "Copyright (C) 1996 Sun Microsystems, Inc."
          };
      }

      /**
       * HelpAbout is a MenuItem that displays an array of strings when activated.
       * It is intended to simpify the provision of an About... entry on a Help menu.
       *
       * @author Jonathan J Gibbons
       * @version %I% %G%
       */

      class HelpAbout extends MenuItem
      {
          public HelpAbout(Frame parent, String name, String dialogName, String[] info) {
      super(name);
      this.parent = parent;
      this.dialogName = dialogName;
      this.info = info;
          }

          public boolean postEvent(Event evt) {
      if (evt.id == Event.ACTION_EVENT && evt.target == this) {
      Dialog d = new HelpAboutDialog(parent, dialogName, info);
      Dimension s = d.size();
      Rectangle b = parent.bounds();
      d.move(b.x + (b.width - s.width)/2, b.y + (b.height - s.height)/2);
          //System.out.println("delay");
      d.show();
      return true;
      }
      return false;
          }

          private Frame parent;
          private String dialogName;
          private String[] info;
      }


      class HelpAboutDialog extends Dialog
      {
          HelpAboutDialog(Frame parent, String name, String[] info) {
      super(parent, name, false);
      setResizable(false);

      Panel p = new Panel();
      GridBagLayout gbl = new GridBagLayout();
      GridBagConstraints c = new GridBagConstraints();
      p.setLayout(gbl);
      c.gridwidth = GridBagConstraints.REMAINDER;
      c.anchor = GridBagConstraints.CENTER;
      c.insets.top = c.insets.bottom = c.insets.left = c.insets.right = 10;

      for (int i = 0; i < info.length; i++) {
      Label l = new Label(info[i]);
      gbl.setConstraints(l, c);
      p.add(l);
      }

      add ("Center", p);

      pack();
          }

          public boolean handleEvent(Event evt) {
      if (evt.id == Event.WINDOW_DESTROY && evt.target == this) {
      dispose();
      return true;
      }

      return false;
          }
      }

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: