import java.awt.*;
import java.awt.event.*;class aa extends Frame implements ActionListener{
TextField t;
Button b,bn;
static int num=0;
bb bframe;
aa(){
t=new TextField(10);
b=new Button("确定");
bn=new Button("另一窗口");
bframe=new bb();
setLayout(new FlowLayout());
add(t);
add(b);
add(bn);
setBounds(100,100,300,400);
setVisible(true);
validate();
b.addActionListener(this);
bn.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b)
num=Integer.parseInt(t.getText());
else
bframe.setVisible(true);
}
}class bb extends Frame{
TextField t;
bb(){
t=new TextField(10);
setLayout(new FlowLayout());
add(t);
t.setText(""+aa.num);
setBounds(200,200,200,200);
setVisible(false);
validate();
}
}public class test{
public static void main(String args[]){
new aa();
new bb();
}
}
本意是想让类aa中的num传到类bb中,但实现不了.
why?

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【dir541541】截止到2008-07-10 18:32:19的历史汇总数据(不包括此帖):
    发帖的总数量:1                        发帖的总分数:0                        每贴平均分数:0                        
    回帖的总数量:0                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:1                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:100.00%               结分的百分比:---------------------
    无满意结贴率:0.00  %               无满意结分率:---------------------
    敬礼!
      

  2.   

    static int num=0;   这个吗静态的不用传  直接aa.num用就是了
      

  3.   

      public void actionPerformed(ActionEvent e) {
        if (e.getSource() == b)
          bframe.t.setText(t.getText()); // 这里调整一下就行了
        else
          bframe.setVisible(true);
      }
      

  4.   

    本以为在一个类中定义一个static int型变量
    在另一个类中直接用 类名.int型变量名 就可以访问
    但程序却不能传值.另一个类中一直得到的都是0
      

  5.   


    //你的代码结构有问题//bframe=new bb();    这句去掉 
    public void actionPerformed(ActionEvent e){ 
    if(e.getSource()==b) 
    num=Integer.parseInt(t.getText()); 
    else 
    new bb().setVisible(true);  //这么改,点另一窗口时,才new bb()
                                //你提前把 bb new出来的话,你怎么弄显示的都是0
                                //不要在构造函数里做那么多操作。楼主自己再好好想想吧} 

    public class test{ 
    public static void main(String args[]){ 
    new aa(); 
    //new bb();   这里去掉 ,创建bb对象