java 的awt中事件监听问题
菜单事件怎样处理
==============================
我想通过获取菜单项的字符串来实现对菜单的监听,但是,老是不出现预想的结果,敬请指教!
=========================================================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
class z_intferface extends WindowAdapter
implements ActionListener{
Frame f;
MenuBar z_mb;
Menu z_Exit;
TextArea z_t;
MenuItem z_mExit;
z_intferface(){
Frame f = new Frame( "登陆 ");
MenuBar z_mb = new MenuBar();
TextArea z_t =new TextArea();
Menu z_Exit = new Menu( "退出 ");
MenuItem z_mExit=
new MenuItem( "退出 ",new MenuShortcut(KeyEvent.VK_T));
z_Exit.add(z_mExit);
//
z_mb.add(z_Exit);
f.setMenuBar(z_mb);
f.add(z_t);
z_mExit.addActionListener(this);
/*z_mExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}
});*///若用内部类可以实现
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
f.pack();
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){//有问题
if(e.getActionCommand().equals(z_mExit.getLabel()) ){
System.exit(0);
}
}
}
public class test{
public static void main(String[] args) {