Applet排版布局问题

paradisense 2008-04-03 09:44:27
写了一个这么样的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);


}


}
...全文
107 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fool_leave 2008-04-30
  • 打赏
  • 举报
回复
运行不起来?
什么意思,什么现象

--------------------------
来上海吧
http://topic.csdn.net/u/20080429/18/2ef7e7f7-7a00-4838-b4a7-ed8104b756ed.html?seed=1556996959
贝壳鱼 2008-04-03
  • 打赏
  • 举报
回复
可以加panel
assdust110 2008-04-03
  • 打赏
  • 举报
回复
Applet标签里面只能够嵌入继承于Applet的类吧

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧