我做了一个小程序。我曾经JPanel
设置小程序的内容,我在init()
方法中做,在start()
我做其他事情。当我在不包含所有内容的情况下运行小程序时,start()
一切正常并显示内容,但如果我添加了该start()
方法,小程序不会显示内容。
这是为什么?
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JApplet;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
public class Server extends JApplet {
final static int port = 4444;
ServerSocket listen;
JEditorPane message;
JPanel content;
public void init(){
message = new JEditorPane();
message.setText("Listening...");
message.setEditable(false);
message.setVisible(true);
content = new JPanel();
content.setLayout(new BorderLayout());
content.add(message, BorderLayout.NORTH);
setContentPane(content);
}
public void start(){
try {
listen = new ServerSocket(port);
while(true){
Socket client = listen.accept();
HandleConnection hc= new HandleConnection(client);
}
} catch (IOException e) {
System.out.println("Couldn't listen on port "+port);
}
}
public void stop(){}
public void destroy(){}
}