我的程序哪里错了??在编译的时候会出现:
ceshi.java:28: 需要 <标识符>
Jmenuitem2.addActionListener(new ActionListener()
^
1 错误
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class JWindow extends JFrame
{
Qipan Q=new Qipan();
public JWindow(String str)
{
super(str);
add(Q);
}
public static void main(String[] args)
{
System.out.println("nihao");
JWindow jwindow=new JWindow("五子棋对战平台");
jwindow.setSize(400,350);
jwindow.setLocation(300,180);
jwindow.setVisible(true);
jwindow.setDefaultCloseOperation(jwindow.EXIT_ON_CLOSE);
}
class QiPan extends JPanel
{
JMenuBar Jmenubar=new JMenuBar();
JMenu Jmenu=new JMenu("操作");
JMenuItem Jmenuitem1=new JMenuItem("开始");
JMenuItem Jmenuitem2=new JMenuItem("退出");
Jmenuitem2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
}
}
----------------解决方案--------------------------------------------------------
有哪个大侠知道啊?不懂中....
----------------解决方案--------------------------------------------------------
两个错误:
1.Qipan Q=new Qipan();
改成:QiPan Q=new QiPan();
2.以下语句要放入函数,比如构造函数;
Jmenuitem2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
----------------解决方案--------------------------------------------------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class JWindow extends JFrame
{
Qipan Q=new Qipan();
public JWindow(String str)
{
super(str);
this.add(Q);
}
public static void main(String[] args)
{
System.out.println("nihao");
JWindow jwindow=new JWindow("五子棋对战平台");
jwindow.setSize(400,350);
jwindow.setLocation(300,180);
jwindow.setVisible(true);
jwindow.setDefaultCloseOperation(jwindow.EXIT_ON_CLOSE);
}
class Qipan extends JPanel
{
public Qipan(){
JMenuBar Jmenubar=new JMenuBar();
JMenu Jmenu=new JMenu("操作");
JMenuItem Jmenuitem1=new JMenuItem("开始");
JMenuItem Jmenuitem2=new JMenuItem("退出");
Jmenuitem2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
}
}
}
----------------解决方案--------------------------------------------------------
哦,我现在懂了,真的谢谢你哦!
----------------解决方案--------------------------------------------------------
----------------解决方案--------------------------------------------------------
我运行了一下,好象菜单还是没有出来啊,有谁知道怎么会事啊?谢谢
----------------解决方案--------------------------------------------------------