java操作菜单代码 运用java代码写一个菜单
java菜单怎么写?
希望有用吧
创新互联服务项目包括桥西网站建设、桥西网站制作、桥西网页制作以及桥西网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,桥西网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到桥西省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
package mm;
import java.io.*;
import java.awt.*;
import javax.swing.*;
public class HelloWorld {
public static void main(String[] args){
JFrame w=new JFrame("SKH");
Container con=w.getContentPane();
//Color
con.setBackground(Color.pink);
//Location
w.setBounds(60, 100, 388, 308);
//可见性
w.setVisible(true);
//单击右上角容器的行为
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//创建菜单项
JMenuBar menubar=new JMenuBar();
JMenu menu,submenu;
JMenuItem a,b;
menu=new JMenu("菜单");
submenu=new JMenu("子菜单");
a=new JMenuItem("菜单项1");
b=new JMenuItem("菜单项2");
menu.add(a);
//添加分割符;
menu.addSeparator();
menu.add(b);
menu.addSeparator();
menu.add(submenu);
submenu.add(new JMenuItem("QWQ"));
menubar.add(menu);
w.setJMenuBar(menubar);
}
}
用java编写一个菜单,要源代码
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);
}}
JAVA面向对象程序设计 菜单操作
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
public class TestMenu extends JFrame {
private JPopupMenu jPopupMenu;
public TestMenu(String title){
super(title);
}
public void init(){
JMenuBar bar = new JMenuBar();
JMenu menuFile = new JMenu("文件");
JMenuItem menuFile1 = new JMenuItem("新建");
JMenuItem menuFile2 = new JMenuItem("打开");
JMenuItem menuFile3 = new JMenuItem("关闭");
JMenuItem menuFile4 = new JMenuItem("保存");
menuFile.add(menuFile1);
menuFile.add(menuFile2);
menuFile.add(menuFile3);
menuFile.add(menuFile4);
JMenu helpMenu = new JMenu("帮助");
JMenuItem helpMenu1 = new JMenuItem("新建");
JMenuItem helpMenu2 = new JMenuItem("打开");
helpMenu.add(helpMenu1);
helpMenu.add(helpMenu2);
bar.add(menuFile);
bar.add(helpMenu);
this.setJMenuBar(bar);
jPopupMenu = new JPopupMenu();
JMenuItem jPopupMenu1 = new JMenuItem("显示图片");
JMenuItem jPopupMenu2 = new JMenuItem("显示缺省图片");
jPopupMenu.add(jPopupMenu1);
jPopupMenu.add(jPopupMenu2);
this.setBounds(200, 200, 500, 400);
this.setResizable(false);
this.setVisible(true);
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton()==MouseEvent.BUTTON3) {
//弹出右键菜单
jPopupMenu.show(TestMenu.this, e.getX(), e.getY());
}
}
});
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestMenu("测试菜单").init();
}
}
网页题目:java操作菜单代码 运用java代码写一个菜单
地址分享:http://scyanting.com/article/ddjcdhi.html