java中菜单界面显示不出来?
importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;importjavax.swing.JCompon...
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.JComponent;
import java.applet.*;
public class demo{
public static void main(String args[]){
Wuziqiframe wuzidemo=new Wuziqiframe();
}
}
class Wuziqiframe extends JFrame {
JMenuBar mbar=new JMenuBar();
JMenu gameMenu=new JMenu();
JMenuItem kaiju=new JMenuItem("开局",KeyEvent.VK_A);
JMenuItem qipan=new JMenuItem("棋盘",KeyEvent.VK_S);
JMenuItem tuichu=new JMenuItem("退出",KeyEvent.VK_D);
public Wuziqiframe(){
addmenu();
}
public void addmenu()
{
JFrame f=new JFrame(" sd");
f.setJMenuBar(mbar);
gameMenu.add(kaiju);
gameMenu.add(qipan);
gameMenu.add(tuichu);
mbar.add(gameMenu);
f.setVisible(true);
f.setBounds(10,10,400,300);
}} 展开
import javax.swing.*;
import java.awt.event.*;
import javax.swing.JComponent;
import java.applet.*;
public class demo{
public static void main(String args[]){
Wuziqiframe wuzidemo=new Wuziqiframe();
}
}
class Wuziqiframe extends JFrame {
JMenuBar mbar=new JMenuBar();
JMenu gameMenu=new JMenu();
JMenuItem kaiju=new JMenuItem("开局",KeyEvent.VK_A);
JMenuItem qipan=new JMenuItem("棋盘",KeyEvent.VK_S);
JMenuItem tuichu=new JMenuItem("退出",KeyEvent.VK_D);
public Wuziqiframe(){
addmenu();
}
public void addmenu()
{
JFrame f=new JFrame(" sd");
f.setJMenuBar(mbar);
gameMenu.add(kaiju);
gameMenu.add(qipan);
gameMenu.add(tuichu);
mbar.add(gameMenu);
f.setVisible(true);
f.setBounds(10,10,400,300);
}} 展开
1个回答
展开全部
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.JComponent;
import java.applet.*;
public class Demo {
public static void main(String args[]) {
Wuziqiframe wuzidemo = new Wuziqiframe();
}
}
class Wuziqiframe extends JFrame {
JMenuBar mbar = new JMenuBar();
JMenu gameMenu = new JMenu("菜单"); //这里要给菜单添加一个名字,否则就像是没显示一样
JMenuItem kaiju = new JMenuItem("开局", KeyEvent.VK_A);
JMenuItem qipan = new JMenuItem("棋盘", KeyEvent.VK_S);
JMenuItem tuichu = new JMenuItem("退出", KeyEvent.VK_D);
public Wuziqiframe() {
addmenu();
}
public void addmenu()
{
//JFrame f=new JFrame(" sd");
//Wuziqiframe既然已经继承JFrame了,就不要再创建JFrame了
gameMenu.add(kaiju);
gameMenu.add(qipan);
gameMenu.add(tuichu);
mbar.add(gameMenu);
this.setJMenuBar(mbar);
this.validate();
this.setVisible(true);
this.setBounds(10, 10, 400, 300);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询