有没有java设计菜单
1个回答
展开全部
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.MenuShortcut;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;public class Test_11 extends Frame implements ActionListener{ /**
* @param args
*/
MenuBar mb = null;
Menu m = null;
MenuItem mi = null; public Test_11() {
this.setBounds(100, 100, 400, 300);
this.setVisible(true);
mb = new MenuBar();
m = new Menu("文件");
mi = new MenuItem("打开");
mi.setShortcut(new MenuShortcut(KeyEvent.VK_O));
m.add(mi);
mb.add(m);
setMenuBar(mb);
mi.addActionListener(this);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
} public static void main(String[] args) {
// TODO Auto-generated method stub
new Test_11();
} @Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}}
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.MenuShortcut;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;public class Test_11 extends Frame implements ActionListener{ /**
* @param args
*/
MenuBar mb = null;
Menu m = null;
MenuItem mi = null; public Test_11() {
this.setBounds(100, 100, 400, 300);
this.setVisible(true);
mb = new MenuBar();
m = new Menu("文件");
mi = new MenuItem("打开");
mi.setShortcut(new MenuShortcut(KeyEvent.VK_O));
m.add(mi);
mb.add(m);
setMenuBar(mb);
mi.addActionListener(this);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
} public static void main(String[] args) {
// TODO Auto-generated method stub
new Test_11();
} @Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询