你应该是这样调用吧
FlowLayoutTest applet51 = new FlowLayoutTest();
JFrame frame = new JFrame("Applet1c");
frame.getContentPane().add(applet51);
frame.setSize(500,500);
applet51.init();
applet51.start();
frame.setVisible(true);试试,应该回成功
FlowLayoutTest applet51 = new FlowLayoutTest();
JFrame frame = new JFrame("Applet1c");
frame.getContentPane().add(applet51);
frame.setSize(500,500);
applet51.init();
applet51.start();
frame.setVisible(true);试试,应该回成功
import java.awt.*;
import java.applet.*;
import javax.swing.*;
public class FlowLayoutTest extends Applet
{
public void init()
{
setLayout(new FlowLayout());
for(int i=0;i<10;i++)
{
add(new Button("button"+i));
validate();
setVisible(true);
try
{
Thread.sleep(500);
}
catch(Exception e){}
}
}
public static void main(String args[])
{
FlowLayoutTest applet51 = new FlowLayoutTest();
JFrame frame = new JFrame("Applet1c");
frame.getContentPane().add(applet51);
frame.setSize(500,500);
applet51.init();
applet51.start();
frame.setVisible(true);
}
}
你編譯出錯的代碼是"FlowLayoutTest mGUI = new init();"
他确实把main写到外面去了,只要看一下main后面{ 减去}的个数为0,就知道了