Topic: 关于一个awt程序问题

  Print this page

1.关于一个awt程序问题 Copy to clipboard
Posted by: wanqiufeng
Posted on: 2007-12-02 17:29

程序如下:
import java.awt.*;
import java.awt.event.*;
class My extends Button implements ActionListener{
  String name;
  TextField text;
  Container con;
  My(String s,Container con){
    superMoon;
    this.con=con;
    text=new TextFieldMusical Note;
    text.addActionListener(this);
    this.addActionListener(this);
    con.add(text);
    con.add(this);
  }
  public void actionPerformed(ActionEvent e){
    name=text.getText();
    this.setLabel(name);
    con.validate();
  }
}
class Win extends Frame{
  My button;
  Win(){
    setLayout(new FlowLayout());
    button=new My("确定",this);
    setBounds(100,200,300,400);
    add(button);//为什么此处不加这句话也可以?
    setVisible(true);
    validate();
  }
}
public class Example6{
  public static void main(String df[]){
    Win win=new Win();
  }
}
说明:我自己已经调试过了,程序中的win类中若不要:add(button);这句依然正确,这是为什么呀;
谢谢解答;

2.Re:关于一个awt程序问题 [Re: wanqiufeng] Copy to clipboard
Posted by: kapianzhe
Posted on: 2008-01-10 22:26

哪个button是由你的con.add(this)Add进去的

3.Re:关于一个awt程序问题 [Re: wanqiufeng] Copy to clipboard
Posted by: JiafanZhou
Posted on: 2008-01-16 22:12

Should move your topic to GUI.

4.Re:关于一个awt程序问题 [Re: wanqiufeng] Copy to clipboard
Posted by: wanqiufeng
Posted on: 2008-01-20 19:53

多谢各位朋友的解答,由于粗心所以当初没发现错误,现在恍然大悟。真的很感谢。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923