主题:有一个小问题
我在尝试用JAVA编写记事本程序,现在正处于最基础的画边框的阶段,但是在为菜单项2设置快捷键的时候 那条语句总是报错 ,请问有没有哪位大虾能够帮我看看 我到底错到哪里 那条语句是
itme2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
这个程序语句为
import javax.swing.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
class FirstWindow extends JFrame{
JMenuBar MenuBar;
JMenu Menu,subMenu;
JMenuItem item1,item2;
FirstWindow(String s){
super(s);
setSize(160,170);
setLocation(120,120);
setVisible(true);
MenuBar = new JMenuBar();
Menu = new JMenu("菜单");
subMenu = new JMenu("子菜单");
item1 = new JMenuItem("菜单项1");
item2 = new JMenuItem("菜单项2");
item1.setAccelerator(KeyStroke.getKeyStroke('A'));
//itme2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
Menu.add(item1);
Menu.addSeparator();
Menu.add(item2);
Menu.add(subMenu);
subMenu.add(new JMenuItem("子菜单里的菜单项"));
MenuBar.add(Menu);
setJMenuBar(MenuBar);
validate();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
public class WritingBook{
public static void main(String args[]){
FirstWindow win = new FirstWindow("带菜单的窗口");
}
}
itme2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
这个程序语句为
import javax.swing.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
class FirstWindow extends JFrame{
JMenuBar MenuBar;
JMenu Menu,subMenu;
JMenuItem item1,item2;
FirstWindow(String s){
super(s);
setSize(160,170);
setLocation(120,120);
setVisible(true);
MenuBar = new JMenuBar();
Menu = new JMenu("菜单");
subMenu = new JMenu("子菜单");
item1 = new JMenuItem("菜单项1");
item2 = new JMenuItem("菜单项2");
item1.setAccelerator(KeyStroke.getKeyStroke('A'));
//itme2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
Menu.add(item1);
Menu.addSeparator();
Menu.add(item2);
Menu.add(subMenu);
subMenu.add(new JMenuItem("子菜单里的菜单项"));
MenuBar.add(Menu);
setJMenuBar(MenuBar);
validate();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
public class WritingBook{
public static void main(String args[]){
FirstWindow win = new FirstWindow("带菜单的窗口");
}
}