子类调用父类构造方法

tmhk123 2010-05-26 03:27:24
import java.awt.*;
import java.awt.event.*;
public class MPlus
{
public static void main(String[] args)
{
MyFrame f1=new MyFrame();
f1.launch();
}
}
class MyFrame extends Frame
{
super("Plus");
TextField t1;
TextField t2;
TextField t3;
public void launch(){
setLayout(new FlowLayout());
t1 = new TextField(10);
Label l1 = new Label("+");
t2 = new TextField(10);
Button b1 = new Button("=");
t3 = new TextField(15);
b1.addActionListener(new Monitor(this));
add(t1);
add(l1);
add(t2);
add(b1);
add(t3);
pack();
setVisible(true);

}
}
class Monitor implements ActionListener
{
MyFrame f1 = null;
public Monitor(MyFrame f2){
f1 = f2;
}
public void actionPerformed(ActionEvent e){
int n1 = Integer.parseInt(f1.t1.getText());
int n2 = Integer.parseInt(f1.t2.getText());
f1.t3.setText(""+(n1+n2));
}
}
...全文
131 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gegewozai 2010-05-27
  • 打赏
  • 举报
回复
貌似 没有 Frame 类
tmhk123 2010-05-26
  • 打赏
  • 举报
回复
4楼你再看看Frame有没有 有参的构造方法
tmhk123 2010-05-26
  • 打赏
  • 举报
回复
哦 晓得了 各位见笑。。
gegewozai 2010-05-26
  • 打赏
  • 举报
回复
你这写的都是什么啊
父类都没有 有参的构造方法
你怎么调用啊
zhuzhusany 2010-05-26
  • 打赏
  • 举报
回复
只有构造器才能调用父类构造器或其他构造方法
kaynezhang 2010-05-26
  • 打赏
  • 举报
回复
class MyFrame extends Frame
{
super("Plus");
TextField t1;
TextField t2;
TextField t3;
public void launch(){
setLayout(new FlowLayout());
t1 = new TextField(10);


你这些的是啥啊???
class MyFrame extends Frame
{
public MyFrame(){
super("Plus");
}

TextField t1;
TextField t2;
TextField t3;
public void launch(){
setLayout(new FlowLayout());
t1 = new TextField(10);
tmhk123 2010-05-26
  • 打赏
  • 举报
回复
MyFrame调用Frame的构造方法 ,传递一个字符串的参数 为什么编译报错?我看了API觉得不该错啊?

62,614

社区成员

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

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