源程序:package sanqing;
import java.awt.*;
public class TestFlow {
public TestFlow(){

}
Frame fr=null;
Button b1,b2,b3,b4,b5;
public static void main(String agrs){
TestFlow myflow = new TestFlow();
myflow.go();
}
public void go(){
fr=new Frame("测试");
fr.setLayout(new FlowLayout());
b1=new Button("按钮1");
b1.setVisible(true);
b2=new Button("按钮2");
b3=new Button("按钮3");
b4=new Button("按钮4");
b5=new Button("按钮5");
fr.add(b1);
fr.add(b2);
fr.add(b3);
fr.add(b4);
fr.add(b5);
fr.setSize(200,200);
fr.pack();
fr.setVisible(true);

}}

解决方案 »

  1.   

    运行时异常:Exception in thread "main" java.lang.NoSuchMethodError: main
    你的main函数的形参类型错误 main(String[] args)
      

  2.   

    直接把main参数修改成 main(String[] args)就可以了
      

  3.   

    伤不起啊,一看就是没有用编译器自己写的。
    楼主的代码我运行出来了,可以的。
    就是上面提示的错误。主函数打错了。
    另外给你提个建议,加上这句话
    fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    否则你点红叉关不掉的
      

  4.   

    主要问题就是主函数的参数问题,上面已经给你指出了,我想说的是go函数里面的东西应该写在类TestFlow的构造函数里,这样你声明一个对象的时候就直接调用了构造函数,还有b1.setVisible(true);这句没必要。关于窗体应用程序,你的类应该这样写public class TestFlow extends JFrame{........},这样在main函数中直接声明一个TestFlow对象就可以了。import java.awt.*;
    import javax.swing.*;
    public class TestFlow extends JFrame{
    JButton b1,b2,b3,b4,b5;
    JPanel panel;
    public TestFlow()
    {
    setSize(600,400);
    setTitle("测试");
    this.setLocation(300,200);
    b1=new JButton("按钮1");
    b2=new JButton("按钮2");
    b3=new JButton("按钮3");
    b4=new JButton("按钮4");
    b5=new JButton("按钮5");
    panel=new JPanel();
    panel.add(b1);
    panel.add(b2);
    panel.add(b3);
    panel.add(b4);
    panel.add(b5);
    getContentPane().add(panel,BorderLayout.SOUTH);

    }
    public static void main(String[] agrs)
    {
    TestFlow myflow = new TestFlow();
    myflow.setVisible(true);
    myflow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    }