import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;public class frame extends JFrame{
private JMenuBar createMenuBar() {
// 实例化一个JMenuBar的对象
JMenuBar jmb = new JMenuBar();
// 菜单项的数组
String[] arrayMenu = {"让我们再一次处理文件吧", "让我们再一次编辑颜色吧", "HELP这种事情想都不要想"};
// 菜单子项的数组
String[][] arrayMenuItem = {{"所以你不打算要之前的东西了?", "你连画都不画你保存个毛", "你干过啥你就想打开", "话都不花完你就想走?"}, {"这里没有你想要的颜色"},
{"这个其实就是我瞎写的", "这种垃圾程序你也要代码?","如果我是你的话我就不会手贱点开它"}};
// 根据数据循环来创建菜单栏
for (int i = 0; i < arrayMenu.length; i++) {
// 实例化一个JMenu的对象
JMenu menu = new JMenu(arrayMenu[i]);
// 将menu添加到jmb对象中
jmb.add(menu);
for (int j = 0; j < arrayMenuItem[i].length; j++) {
// 实例化JMenuItem的对象
JMenuItem jmi = new JMenuItem(arrayMenuItem[i][j]);
// 将jmi对象添加到menu中
menu.add(jmi);
}
}
return jmb;
} public static void main(String[] arg){
frame f=new frame();
f.initUI();
}
public void initUI(){
this.setTitle("对对对没错又是这个石乐志的我和这个石乐志的辣鸡JAVA");
this.setSize(1000,800); this.setLocationRelativeTo(null);
this.setLayout(new FlowLayout());
listener l=new listener();
String []array={"Line","Rect","Oval","Pencil","Spary"};
JPanel panel=new JPanel(); for(int i=0;i<array.length;i++){
JButton button=new JButton(array[i]);
button.addActionListener(l);
button.setPreferredSize(new Dimension(100,30));
panel.add(button);
}
this.add(panel,BorderLayout.WEST);
panel.setVisible(true);
this.setResizable(false);
this.setVisible(true);
this.addMouseListener(l);
JMenuBar jmb = createMenuBar();
jmb.setVisible(true);
this.setJMenuBar(jmb);
l.setGraphics(this.getGraphics());
}
}
不知道怎么就加不上……
import java.awt.*;
import java.awt.event.*;
import java.util.Random;public class frame extends JFrame{
private JMenuBar createMenuBar() {
// 实例化一个JMenuBar的对象
JMenuBar jmb = new JMenuBar();
// 菜单项的数组
String[] arrayMenu = {"让我们再一次处理文件吧", "让我们再一次编辑颜色吧", "HELP这种事情想都不要想"};
// 菜单子项的数组
String[][] arrayMenuItem = {{"所以你不打算要之前的东西了?", "你连画都不画你保存个毛", "你干过啥你就想打开", "话都不花完你就想走?"}, {"这里没有你想要的颜色"},
{"这个其实就是我瞎写的", "这种垃圾程序你也要代码?","如果我是你的话我就不会手贱点开它"}};
// 根据数据循环来创建菜单栏
for (int i = 0; i < arrayMenu.length; i++) {
// 实例化一个JMenu的对象
JMenu menu = new JMenu(arrayMenu[i]);
// 将menu添加到jmb对象中
jmb.add(menu);
for (int j = 0; j < arrayMenuItem[i].length; j++) {
// 实例化JMenuItem的对象
JMenuItem jmi = new JMenuItem(arrayMenuItem[i][j]);
// 将jmi对象添加到menu中
menu.add(jmi);
}
}
return jmb;
} public static void main(String[] arg){
frame f=new frame();
f.initUI();
}
public void initUI(){
this.setTitle("对对对没错又是这个石乐志的我和这个石乐志的辣鸡JAVA");
this.setSize(1000,800); this.setLocationRelativeTo(null);
this.setLayout(new FlowLayout());
listener l=new listener();
String []array={"Line","Rect","Oval","Pencil","Spary"};
JPanel panel=new JPanel(); for(int i=0;i<array.length;i++){
JButton button=new JButton(array[i]);
button.addActionListener(l);
button.setPreferredSize(new Dimension(100,30));
panel.add(button);
}
this.add(panel,BorderLayout.WEST);
panel.setVisible(true);
this.setResizable(false);
this.setVisible(true);
this.addMouseListener(l);
JMenuBar jmb = createMenuBar();
jmb.setVisible(true);
this.setJMenuBar(jmb);
l.setGraphics(this.getGraphics());
}
}
不知道怎么就加不上……
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货