日期:2014-05-20  浏览次数:20681 次

一段代码提示错误
Java code

package cn.puruidong.Test;
import java.awt.*;
public class Gui{
     private Frame f;
    private Button b1;
    private Button b2;
public static void main(String args[]){

    Gui that = new Gui();
    that.go();
}
    public void go(){ //这个地方编译器不通过
        f = new Frame("GUI example");
            f.setLayout(new FlowLayout()); 
              //设置布局管理器为FlowLayout            
    b1 = new Button("Press Me"); //按钮上显示字符"Press Me"            
    b2 = new Button("Don't Press Me");
    f.add(b1);
    f.add(b2);
    f.pack();//紧凑排列,其作用相当于setSize(),即让窗口尽量小,小到刚刚能够包容住b1、b2两个按钮            
    f.setVisible(true);
    }   
}



求高手解答。。

------解决方案--------------------
Java code

   private Frame f;
     private Button b1;
     private Button b2;
 
     public void go(){ //这个地方编译器不通过
         f = new Frame("GUI example");
             f.setLayout(new FlowLayout()); 
               //设置布局管理器为FlowLayout            
     b1 = new Button("Press Me"); //按钮上显示字符"Press Me"            
     b2 = new Button("Don't Press Me");
     f.add(b1);
     f.add(b2);
     f.pack();//紧凑排列,其作用相当于setSize(),即让窗口尽量小,小到刚刚能够包容住b1、b2两个按钮            
     f.setVisible(true);
     }
    public static void main(String[] args) {
Test test = new Test() ;
test.go() ;
    }

------解决方案--------------------
}后面多余的字符删除
f.setVisible(true);
}