我的菜单为什么显示不出来?

xiamin 2012-06-16 08:38:11
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;


public class mainFrame extends JFrame implements ActionListener{
JMenuItem priorgame ;
JMenuItem nextgame ;
JMenuItem undo ;
JMenuItem exit ;
JMenuBar menu;
MyPanel p;
public mainFrame() {
super("汽车IQ v2.0");
setSize(440, 440);
setVisible(true);
setResizable(false);
setLocation(300, 20);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cont = getContentPane();
cont.setLayout(null);
cont.setBackground(Color.black);

JMenu game = new JMenu("游戏");
priorgame = game.add("上一关");
nextgame = game.add("下一关");
undo = game.add("撤销");
exit = game.add("退出");
JMenu help = new JMenu("帮助");

JMenuBar menu = new JMenuBar();
menu.add(game);
menu.add(help);
setJMenuBar(menu);

priorgame.addActionListener(this);
nextgame.addActionListener(this);
undo.addActionListener(this);
exit.addActionListener(this);

p=new MyPanel(); //使用线程刷新,这引起的吗
add(p);
}
//菜单事件
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==nextgame)//下一关
{
p.nextGrade();
}
else if(e.getSource()==priorgame)//上一关
{
p.priorGrade();
}
else if(e.getSource()==undo)//撤销
{
p.undo();
}
else if(e.getSource()==exit)//退出
{
System.exit(0); // 退出程序
}
}
public static void main(String[] args) {
mainFrame frame = new mainFrame();
}
}
...全文
118 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Seanake 2012-06-16
  • 打赏
  • 举报
回复


少这个
import javax.swing.JPanel;

public class MyPanel extends JPanel {

public void nextGrade() {
// TODO Auto-generated method stub

}

public void priorGrade() {
// TODO Auto-generated method stub

}

public void undo() {
// TODO Auto-generated method stub

}

}


curbstone119 2012-06-16
  • 打赏
  • 举报
回复
看不到MyPanel,无法确定
我这里把MyPanel都注释掉,可以显示菜单
古市轩 2012-06-16
  • 打赏
  • 举报
回复
线程启动了吗?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧