3个回答
展开全部
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class MenuBarDemo extends JFrame {
JMenuBar menuBar;
JMenu file,edit,news;
JMenuItem newsFile,javaFile,open,exit;
JMenuItem undo,redo,copy,cut,paste,find,replace;
public static void main(String[] args) {
new MenuBarDemo().setMenuBar();
}
public void setMenuBar(){
menuBar = new JMenuBar();
this.setJMenuBar(menuBar);
file = new JMenu("文件");
news = new JMenu("新建");
newsFile = this.addItem("文件夹", news);
javaFile = this.addItem("java文件", news);
file.add(news);
open = this.addItem("打开", file);
exit = this.addItem("退出", file);
edit = new JMenu("编辑");
undo = this.addItem("撤销", edit);
redo = this.addItem("重做", edit);
cut = this.addItem("剪切", edit);
copy = this.addItem("拷贝", edit);
paste = this.addItem("粘贴", edit);
find = this.addItem("查找", edit);
replace = this.addItem("替换", edit);
menuBar.add(file);
menuBar.add(edit);
this.setBounds(200, 200, 300, 300);
this.setResizable(false);
this.setVisible(true);
}
public JMenuItem addItem(String name,JMenu menu){
JMenuItem temp = new JMenuItem(name);
menu.add(temp);
return temp;
}
}
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class MenuBarDemo extends JFrame {
JMenuBar menuBar;
JMenu file,edit,news;
JMenuItem newsFile,javaFile,open,exit;
JMenuItem undo,redo,copy,cut,paste,find,replace;
public static void main(String[] args) {
new MenuBarDemo().setMenuBar();
}
public void setMenuBar(){
menuBar = new JMenuBar();
this.setJMenuBar(menuBar);
file = new JMenu("文件");
news = new JMenu("新建");
newsFile = this.addItem("文件夹", news);
javaFile = this.addItem("java文件", news);
file.add(news);
open = this.addItem("打开", file);
exit = this.addItem("退出", file);
edit = new JMenu("编辑");
undo = this.addItem("撤销", edit);
redo = this.addItem("重做", edit);
cut = this.addItem("剪切", edit);
copy = this.addItem("拷贝", edit);
paste = this.addItem("粘贴", edit);
find = this.addItem("查找", edit);
replace = this.addItem("替换", edit);
menuBar.add(file);
menuBar.add(edit);
this.setBounds(200, 200, 300, 300);
this.setResizable(false);
this.setVisible(true);
}
public JMenuItem addItem(String name,JMenu menu){
JMenuItem temp = new JMenuItem(name);
menu.add(temp);
return temp;
}
}
追问
web项目
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询