编程中出现的错误:
1.variable keyEvent 错误K大写;new Menushortcut();
2.import java.awt.event.KeyEvent;必须
import java.awt.*;
import java.awt.event.KeyEvent;
public class A
{
public static void main(String args[])
{
Frame f=new Frame("checkbox");
MenuBar mb=new MenuBar();
Menu m_file=new Menu("文件");
Menu m_edit=new Menu("编辑");
MenuItem mi_new=new MenuItem("新建",new MenuShortcut(KeyEvent.VK_N));
MenuItem mi_open=new MenuItem("打开",new MenuShortcut(KeyEvent.VK_O));
MenuItem mi_exit=new MenuItem("退出",new MenuShortcut(KeyEvent.VK_X));
m_file.add(mi_new);
m_file.add(mi_open);
m_file.addSeparator(); //插入分割线
m_file.add(mi_exit);
mb.add(m_file);
mb.add(m_edit);
f.setMenuBar(mb); //标题栏(setMenuBar)不同于其他(add)
f.setSize(200,300);
f.setVisible(true);
}
}
阅读(563) | 评论(0) | 转发(0) |