源码:
import java.applet.*; import javax.swing.*;
class MyPanel extends JPanel
{
JButton button1,button2;
JLabel label;
MyPanel(String s1,String s2,String s3)
{//Panel对象初始化为有两个按钮和一个文本框。
button1 = new JButton(s1); button2 = new JButton(s2);
label = new JLabel(s3);
add(button1); add(button2);add(label);
}
}public class Example5_4 extends Applet
{
MyPanel panel1,panel2;
JButton button;
public void main(String [] args)
{
panel1 = new MyPanel("确定","取消","标签,我们在面板1中");
panel2 = new MyPanel("确定","取消","标签,我们在面板2中");
add(panel1);add(panel2);add(button);
setSize(300,200);
}
}执行时提示:F:\JavaExercise>java Example5_4
Exception in thread "main" java.lang.NoSuchMethodError: main

解决方案 »

  1.   

    public static void main(String [] args) 
      

  2.   

    修改后编译不出错,可能也能运行,但是不是你想要的
    public void main(String [] args) 
    >>>>>>
    public void init()  在这个方法里面做你的对象创建mian 函数 中创建 Example5_4  对象 并显示
      

  3.   


    /*
    <APPLET code=Example5_4.class width=400 height=400></APPLET>
    */ 
    import java.applet.*; import javax.swing.*;
    class MyPanel extends JPanel 
    {
    JButton button1,button2;
    JLabel label;
    MyPanel(String s1,String s2,String s3) 
    {
    //Panel对象初始化为有两个按钮和一个文本框。
    button1 = new JButton(s1); 
    button2 = new JButton(s2);
    label = new JLabel(s3);
    add(button1); 
    add(button2);
    add(label);
    }
    }public class Example5_4 extends Applet 
    {
    MyPanel panel1,panel2;
    //JButton button;
    public void init() 
    {
    panel1 = new MyPanel("确定","取消","标签,我们在面板1中");
    panel2 = new MyPanel("确定","取消","标签,我们在面板2中");

    add(panel1);
    add(panel2);
    //add(button);
    setSize(300,200);
    }

    public static void main(String [] args) 
    {
    JFrame f = new JFrame();
    f.add(new Example5_4());
    f.setSize(300,200);

    f.setVisible(true);
    }
    }
    不记得怎么直接创建applet执行了,本例可以用appletviewer Example5_4.java 执行
      

  4.   

    异常提示main方法错误。缺少main方法。查看main方法可知
    public void main(String [] args) 
    {
    少static
      

  5.   


    public class Example5_4 extends Applet 
    {
    MyPanel panel1,panel2;
    //JButton button;
    public Example5_4()
    {
    init();
    }


    public void init() 
    {
    panel1 = new MyPanel("确定","取消","标签,我们在面板1中");
    panel2 = new MyPanel("确定","取消","标签,我们在面板2中");

    add(panel1);
    add(panel2);
    //add(button);
    setSize(300,200);
    }

    public static void main(String [] args) 
    {
    JFrame frame = new JFrame("FrameDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.add(new Example5_4(), BorderLayout.CENTER);        //Display the window.
            frame.pack();
            frame.setVisible(true);
    }
    }
    支持 java Example5_4
      

  6.   

    在main方法上加上static
    public static void main(String [] args) 
      

  7.   

    小伙,UE、记事本等写java,doc下运行,用一段时间,了解一下原理就可以了。
    你改用个IDE如eclipse高级点的东西了!
      

  8.   

    Applet啊,顶6楼的,记得是用init来着
      

  9.   

    j2se  是 
     public static void main
    applet 
     init()方法...
    楼主要记住