我在一个程序中添加了菜单条但他却显示不出来;也不知道自己错在哪希望各位大侠能看一看因为太长所以只添加部分publicclassMazelp/*extendsJFrame*/implementsActionListener{private...
我在一个程序中添加了菜单条但他却显示不出来;也不知道自己错在哪希望各位大侠能看一看因为太长所以只添加部分
public class Mazelp /*extends JFrame*/ implements ActionListener{
private static final int wid = 10;
private static final int hei = 10;
JFrame jf;
JButton jb1,jb2;
JButton jb[];
JPanel p1,p2;
private Stack stack = new Stack();//Stack 类表示后进先出(LIFO)的对象堆栈。
JMenuBar menu;
JMenu file;
JMenuItem closeMenu;
public Mazelp() {
jf=new JFrame("迷宫");//申请内存空间设置标题
jf.setBounds(300,240,500,500); //调整迷宫出现的位置(300,240)及大小(500,500)
jf.setResizable(false);//窗体不可拉伸
menu = new JMenuBar();//设置菜单条
file = new JMenu("文件");//设置菜单栏
closeMenu = new JMenuItem("关闭");//设置菜单项
closeMenu.addActionListener(this);//添加监听对菜单项
p1=new JPanel();
jf.add(menu);
menu.add(file);//将菜单栏添加到菜单条上
file.add(closeMenu);//将菜单项添加到菜单栏
jf.getContentPane().add(p1);
p1.setLayout(new GridLayout(10,10)); //p1用网格布局,10行10列
jb=new JButton[100];//作为迷宫的墙和路
for(int i=0;i
jb[i]=new JButton(Integer.toString(i));//创建按键的名字,Integer型的名字为i的字符串
if((i>=0&&i<=9)||(i>=90&&i<=99)||i%10==0||i%10==9||i==13||i==17||i==23||i==27||i==35||i==36||i==42||i==43||i==44||i==54||i==62||i==66||i==72||i==73||i==74||i==76||i==77||i==81){
jb[i].setBackground(Color.red);//将墙涂色
}
else {
jb[i].setBackground(Color.yellow);
}
jb[i].setSize(10,10);
p1.add(jb[i]);
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE); //声明点“X”图标后结束窗体所在的应用程序
jf.setVisible(true); //表明以上创建的所有窗体、按键等组件都是可见
}
}
如果想要看源程序的话和call me 谢谢!!! 如果添加两个button在顶上的花如何添加
展开