下面的JAVA代码不能运行,错在哪?怎么改 5

importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.prin... import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.print.DocFlavor.URL;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class Abcc extends JFrame implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String[] args){
Abcc menuframe=new Abcc();
menuframe.setVisible(true);
}
public Abcc(){
super();
setTitle("创建菜单");
setBounds(100,100,240,160);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menubar=new JMenuBar();
JMenu file=new JMenu("文件");
java.net.URL url=getClass().getResource("file.png");
ImageIcon icon=new ImageIcon("url");
JMenuItem open=new JMenuItem("文件",icon);
JMenuItem exit=new JMenuItem("退出");
exit.addActionListener(new addActionListener(){
public void actionPerformed(final ActionEvent arg0){
System.exit(0);
}
});
file.add(open);
file.addSeparator();
file.add(exit);
menubar.add(file);
setJMenuBar(menubar);
}
}
展开
 我来答
yugi111
2015-10-13 · TA获得超过8.1万个赞
知道大有可为答主
回答量:5.1万
采纳率:70%
帮助的人:1.4亿
展开全部
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

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

public class Abcc extends JFrame
{
private static final long serialVersionUID = 1L;

public static void main(String[] args)
{
Abcc menuframe = new Abcc();
menuframe.setVisible(true);
}

public Abcc()
{
super();
setTitle("创建菜单");
setBounds(100, 100, 240, 160);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menubar = new JMenuBar();
JMenu file = new JMenu("文件");
java.net.URL url = getClass().getResource("file.png");
ImageIcon icon = new ImageIcon("url");
JMenuItem open = new JMenuItem("文件", icon);
JMenuItem exit = new JMenuItem("退出");
exit.addActionListener(new ActionListener()
{
public void actionPerformed(final ActionEvent arg0)
{
System.exit(0);
}
});
file.add(open);
file.addSeparator();
file.add(exit);
menubar.add(file);
setJMenuBar(menubar);
}
}
追问
不需要继承ActionListener接口吗?
追答
你有内部继承

exit.addActionListener(new ActionListener()
{
public void actionPerformed(final ActionEvent arg0)
{
System.exit(0);
}
});
hyt0302
2015-10-13 · TA获得超过113个赞
知道小有建树答主
回答量:81
采纳率:100%
帮助的人:34.1万
展开全部
private static final long serialVersionUID = 1L;
public static void main(String[] args){
Abcc menuframe=new Abcc();//Abcc是一个类,要创建对象,但是你下面的Abcc并没有class修饰
menuframe.setVisible(true);
}
public Abcc(){//这是一个函数体结构
super();
setTitle("创建菜单");
setBounds(100,100,240,160);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menubar=new JMenuBar();
JMenu file=new JMenu("文件");
java.net.URL url=getClass().getResource("file.png");
ImageIcon icon=new ImageIcon("url");
JMenuItem open=new JMenuItem("文件",icon);
JMenuItem exit=new JMenuItem("退出");
exit.addActionListener(new addActionListener(){
public void actionPerformed(final ActionEvent arg0){
System.exit(0);
}
});
file.add(open);
file.addSeparator();
file.add(exit);
menubar.add(file);
setJMenuBar(menubar);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
北风那个抽啊
2015-10-13 · 超过21用户采纳过TA的回答
知道答主
回答量:46
采纳率:0%
帮助的人:19万
展开全部
报的错呢?
追问
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (new addActionListener(){})
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式