编译出错,不解?请高手指点。

kempguan 2002-03-19 09:56:55
源码:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class Undo
{
JFrame frame;
public void Undo(String str){
frame = new JFrame(str);
frame.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});
frame.getContentPane().setLayout(null);
frame.setSize(300,400);
frame.setVisible(true);
}
public static void main(String[] args)
{
Undo n=new Undo("Undo");
}
}

出错信息:constructor中的参数数量错误。
Undo n= new Undo("Undo");
^
...全文
39 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Whyin 2002-03-19
  • 打赏
  • 举报
回复
把:
public void Undo(String str){
中的void 去掉,因为Undo()是构造涵数,初始话,应该
public Undo(String str) 声明就可以了
jianghuxiaozi 2002-03-19
  • 打赏
  • 举报
回复
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class Undo
{
JFrame frame;
public Undo(String str){
frame = new JFrame(str);
frame.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});
frame.getContentPane().setLayout(null);
frame.setSize(300,400);
frame.setVisible(true);
}
public static void main(String[] args)
{
Undo n=new Undo("Undo");
}
}
kempguan 2002-03-19
  • 打赏
  • 举报
回复
谢谢,这点问题怎么没想到。
bdsc 2002-03-19
  • 打赏
  • 举报
回复
构造函数没有返回类型

23,405

社区成员

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

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