为什么这个小程序不起作用?
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class MenuDemo extends Applet implements ActionListener
{
private TextField myTextField;
private Frame myFrame;
@Override
public void init()
{
myFrame = new Frame();
myFrame.addWindowListener(new Terminator());
myTextField = new TextField(20);
add(myTextField);
myFrame.setBounds(200,200,300,300);
// place myMenuBar at top of myFrame
MenuBar myMenuBar = new MenuBar();
myFrame.setMenuBar(myMenuBar);
Menu fileMenu = new Menu("File");
myMenuBar.add(fileMenu);
Menu editMenu = new Menu("Edit");
myMenuBar.add(editMenu);
MenuItem myMenuItem;
myMenuItem = new MenuItem("Open");
myMenuItem.addActionListener(this);
fileMenu.add(myMenuItem);
myMenuItem = new MenuItem("Close");
myMenuItem.addActionListener(this);
fileMenu.add(myMenuItem);
myMenuItem = new MenuItem("Undo");
myMenuItem.addActionListener(this);
editMenu.add(myMenuItem);
myFrame.show();
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() instanceof MenuItem)
myTextField.setText("Your Choice: "+ e.getActionCommand());
}
public class Terminator extends WindowAdapter
{
@Override
public void windowClosing(WindowEvent e)
{
myFrame.dispose();
// use System.exit(0) for applications
}
}
}