写了一个这么样的applet的GUI,但是死活运行不出来。难道applet的container不能嵌入panel么?import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;public class GUIGenerator extends JApplet{
private JTextField inputField;
private JLabel promptID;
private JLabel promptResponse;
private JButton sendButton;
private JButton clearButton;
private final int FIELD_WIDTH = 20;
private final int AREA_ROWS = 20;
private final int AREA_COLUMNS = 5;
private JPanel centerPanel;
JPanel bottomPanel;
public void init(){
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
createCenterPanel();
createBottomPanel();
promptID = new JLabel("Please input a prompt ID: ");
contentPane.add(promptID,BorderLayout.NORTH);
contentPane.add(centerPanel,BorderLayout.CENTER);
contentPane.add(bottomPanel,BorderLayout.SOUTH);
}
public void createCenterPanel(){
centerPanel = new JPanel();
centerPanel.setLayout(new GridLayout(1,2));
inputField = new JTextField(FIELD_WIDTH);
centerPanel.add(inputField);
sendButton = new JButton("Send");
centerPanel.add(sendButton);
}
public void createBottomPanel(){
bottomPanel = new JPanel();
bottomPanel.setLayout(new GridLayout(3,1));
promptResponse= new JLabel("Server Response: ");
bottomPanel.add(promptResponse);
final JTextArea textArea = new JTextArea(AREA_ROWS, AREA_COLUMNS);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
bottomPanel.add(scrollPane);
clearButton = new JButton("Clear");
bottomPanel.add(clearButton);
}
}
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;public class GUIGenerator extends JApplet{
private JTextField inputField;
private JLabel promptID;
private JLabel promptResponse;
private JButton sendButton;
private JButton clearButton;
private final int FIELD_WIDTH = 20;
private final int AREA_ROWS = 20;
private final int AREA_COLUMNS = 5;
private JPanel centerPanel;
JPanel bottomPanel;
public void init(){
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
createCenterPanel();
createBottomPanel();
promptID = new JLabel("Please input a prompt ID: ");
contentPane.add(promptID,BorderLayout.NORTH);
contentPane.add(centerPanel,BorderLayout.CENTER);
contentPane.add(bottomPanel,BorderLayout.SOUTH);
}
public void createCenterPanel(){
centerPanel = new JPanel();
centerPanel.setLayout(new GridLayout(1,2));
inputField = new JTextField(FIELD_WIDTH);
centerPanel.add(inputField);
sendButton = new JButton("Send");
centerPanel.add(sendButton);
}
public void createBottomPanel(){
bottomPanel = new JPanel();
bottomPanel.setLayout(new GridLayout(3,1));
promptResponse= new JLabel("Server Response: ");
bottomPanel.add(promptResponse);
final JTextArea textArea = new JTextArea(AREA_ROWS, AREA_COLUMNS);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
bottomPanel.add(scrollPane);
clearButton = new JButton("Clear");
bottomPanel.add(clearButton);
}
}
什么意思,什么现象--------------------------
来上海吧
http://topic.csdn.net/u/20080429/18/2ef7e7f7-7a00-4838-b4a7-ed8104b756ed.html?seed=1556996959