0
我正在学习Java AWT来创建GUI应用程序。我正在处理下面的代码,我无法在框架内显示面板。这是我的代码:如何在Java AWT框架中显示面板?
import java.awt.*;
import java.awt.event.*;
/**
*
* @author kiran
*/
public class UserInterface
{
Frame UI;
private static double UIWidth, UIHeight;
/**
* Constructs User Interface
*/
public UserInterface()
{
UI = new Frame("frame");
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
UIWidth = screenSize.getWidth();
UIHeight = screenSize.getHeight();
buildFrame();
buildMessageInputArea();
}
/**
* returns the width of the UI
* @return returns the width of the UI
*/
public static double getUIWidth()
{
return UIWidth;
}
/**
* returns the width of the UI
* @return returns the width of the UI
*/
public static double getUIHeight()
{
return UIHeight;
}
/**
* Builds the frame
*/
private void buildFrame()
{
UI.setSize((int)UIWidth,(int)UIHeight*96/100);
UI.setVisible(true);
UI.setLayout(new FlowLayout());
UI.addWindowListener(new Actions());
}
private void buildMessageInputArea()
{
Panel current = new TextAreaPanel().getPanel();
current.setVisible(true);
UI.add(current);
}
}
class TextAreaPanel extends Frame
{
private Panel textAreaPanel;
TextArea msgInputArea;
public TextAreaPanel()
{
textAreaPanel = new Panel();
msgInputArea = new TextArea(1000,(int)UserInterface.getUIWidth() * 80/100);
}
private void addTextArea()
{
textAreaPanel.add(msgInputArea);
}
public Panel getPanel()
{
return textAreaPanel;
}
}
class Actions extends WindowAdapter
{
@Override
public void windowClosing(WindowEvent c)
{
System.exit(0);
}
}
我该如何让面板在框架内可见?
框架延伸或扩展的JFrame,AAAND文本区域或JTextArea中,面板或JPanel的,请使用摇摆,而不是老AWT – mKorbel
阅读从Swing教程中的部分上[如何使用文本区域(HTTP://文档.oracle.com/JavaSE的/教程/ uiswing /组件/ textarea.html)。 'TextDemo'代码将告诉你如何更好地构建你的代码。不需要所有扩展类或静态方法。从教程中的工作代码开始,并进行更改.. – camickr
@camickr他并不是在问Swing,他想知道如何用AWT做到这一点。 – CodingNinja