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

Win32: pressing OK or cancel in File Browser dialog box, crashes

XMLWordPrintable

    • 1.0beta2
    • x86
    • windows_nt
    • Verified

      Win32 only: Pressing OK, or Cancel in File Browser Dialog crashes.

      Steps to reproduce
      Compile and run the following code
      Select File | Save from the menu
      Press <Cancel>
      // Note: or enter a file name and press OK

      /* File Save Test
       * @author Kevin A. Smith
       */

      import java.awt.*;

      class FileSaveTest extends AppFrame
      {

          public String sFileName = "";

          public static void main(String args[])
          {
             Frame f = new FileSaveTest("File Save test");
             f.show();
          }

          FileSaveTest(String name)
          {
             super(name);
             MenuBar menuBar = new MenuBar();
             Menu fileMenu = new Menu("File");
             fileMenu.add(new MenuItem("Save"));
             fileMenu.addSeparator();
             fileMenu.add(new MenuItem("Exit"));
             menuBar.add(fileMenu);
             setMenuBar(menuBar);

             resize(200, 200);
          }
          
          public boolean action(Event evt, Object obj)
          {
             if(evt.target instanceof MenuItem)
                return menuEvent(evt, obj);
             else
                return super.action(evt, obj);
          }

          public boolean menuEvent(Event evt, Object obj)
          {
             String label = obj.toString();

             if (label.equals("Save") )
             {
                FileDialog saveFD = new FileDialog(this,
                                                   "File Save As",
                                                   FileDialog.SAVE);
                saveFD.show();
                //sFileName = saveFD.getFile();
                repaint();
                return true;
             }
             else if( label.equals("Exit") )
             {
                postEvent(new Event(this, Event.WINDOW_DESTROY, null) );
                return true;
             }

             else
                return false;

          } // end menuEvent()

          public void paint(Graphics g)
          {
             Rectangle bounds = bounds();
             FontMetrics fm = g.getFontMetrics( g.getFont() );
             g.drawString(sFileName,
                          ( ( bounds.width - fm.stringWidth(sFileName) ) / 2),
                          ( ( bounds.height - fm.getHeight() ) / 2 ) );
          }
      }

      /* Generic Application Frame
       * @(#)AppFrame.java 1.2 08 Nov 1995 10:00:20
       * @author Kevin A. Smith
       */

      import java.awt.Frame;
      import java.awt.Event;

      // Application Frame window
      class AppFrame extends Frame
      {
          // constructor needed to pass window title to class Frame
          public AppFrame(String name)
          {
             // call java.awt.Frame(String) constructor
             super(name);
          }

          // needed to allow window close
          public boolean handleEvent(Event e)
          {
             // Window Destroy event
             if (e.id == Event.WINDOW_DESTROY)
             {
                // exit the program
                System.exit(0);
                return true;
             }
             
             // it's good form to let the super class look at any
             // unhandled events
             return super.handleEvent(e);

          } // end handleEvent()
      }

            tballsunw Tom Ball (Inactive)
            kasmithsunw Kevin Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: