[5138] in java-interest

home help back first fref pref prev next nref lref last post

method action()

daemon@ATHENA.MIT.EDU (Franck Lantres)
Tue Jan 30 01:51:36 1996

From: Franck Lantres <lantres@lome.seriat.fr>
Date: Mon, 29 Jan 96 16:32:11 GMT
To: java-interest@java.sun.com

I have a main class : MyWindow and a class which displays a dialog  
box with a button 'Ok'. The method action() is declared in both  
methods, just like that :

import java.awt.*;

class AboutDialog extends Dialog
{
  private static int H_SIZE=200;
  private static int V_SIZE=200;
  public AboutDialog(Frame parent)
  {
    super(parent, true);
    setBackground(Color.lightGray);
    setLayout(new BorderLayout());
    setTitle("About");
    Panel p=new Panel();
    Button b=new Button("Ok");
    p.add(b);
    add("South", p);
    b.requestFocus();
    resize(H_SIZE, V_SIZE);
  }
  public boolean action(Event evt, Object arg)
  {
    if ("Ok".equals(arg))
    {
      dispose();
      return true;
    }
    return false;
  }
}

class MyWindow extends Frame
{
  private static int H_SIZE=200;
  private static int V_SIZE=200;
  public MyWindow(String title)
  {
    MenuBar mbar;
    Menu    m;
    setTitle(title);
    mbar=new MenuBar();
    m=new Menu("&Fichier");
    m.addSeparator();
    m.add(new MenuItem("&Quitter"));
    mbar.add(m);
    m=new Menu("&Help");
    m.add(new MenuItem("&About"));
    mbar.add(m);
    setMenuBar(mbar);
    pack();
    resize(H_SIZE, V_SIZE);
    show();
  }
  public boolean action(Event evt, Object arg)
  {
    if ("&Quitter".equals(arg))
    {
      System.exit(0);
      return true;
    }
    if ("&About".equals(arg))
    {
      Dialog ab=new AboutDialog(this);
      ab.show();
      return true;
    }
  }
}

My question is very simple : why, when I press the Ok button, the  
action method of the class MyWindow is called, and not the action  
method of the class AboutDialog ?
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post