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

ActionListener doesn't work for a modal dialog box

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs
    • x86
    • windows_95



      Name: jtC48319 Date: 06/23/98


      "actionPerformed" function is not called while
      using ActionListener Interface for a modal
      dialog box. Here is a sample code which works
      well for non-modal and doesn't for a modal.
      In this program, Clicking "Ok" should close
      the dialog box. It doesn't happens so, but
      the same happens well if it is a non-modal
      dialog box. I tried to debug it. The function
      actionPerformed was not called if it is a modal
      dialog box.

      import java.awt.*;
      import java.awt.event.*;

      class displayMsg extends Dialog implements WindowListener, ActionListener
      {
      String Message;
      private Dialog x;
      displayMsg( Frame frame, String Msg, String Title )
      {
      super( frame, Title, true ); // false works while true doesn't
      setLayout( new FlowLayout( FlowLayout.CENTER, 50, 50 ) );
      Button Ok;
      Message = new String( Msg );
      Ok = new Button( " Ok " );
      add( Ok );
      setSize( 300, 100 );
      setResizable( false );
      show();
      addWindowListener( this );
      Ok.addActionListener( this );
      x = this;
      }
      public void paint( Graphics g )
      {
      g.drawString( Message, 35, 50 );
      }
      public void windowClosing(WindowEvent x)
      {
      if( x.getID() == WindowEvent.WINDOW_CLOSING )
      dispose();
      }
      public void windowClosed(WindowEvent x){}
      public void windowDeactivated(WindowEvent x){}
              public void windowActivated(WindowEvent x){}
      public void windowDeiconified(WindowEvent x){}
      public void windowIconified(WindowEvent x){}
      public void windowOpened(WindowEvent y){}
      public void actionPerformed( ActionEvent e )
      {
      System.out.println( "Inside action" );
      if( e.getActionCommand().equals( " Ok " ) ) CmOk();
      }
      public void CmOk()
      {
      System.out.println( "Inside Ok" );
      x.dispose();
      }
      public static void main( String args[] )
      {
      Frame MyFrm = new Frame();
      MyFrm.setSize( 300, 300 );
      MyFrm.show();
      new displayMsg( MyFrm, "Check", "FYI" );
      }
      }
      (Review ID: 34058)
      ======================================================================

            ibdsunw Ibd Ibd (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: