GUI 응용 프로그램을 작성하기 위해 Java AWT를 연구 중입니다. 프레임 안의 패널을 볼 수없는 아래의 코드를 작업 중입니다. 여기 내 코드는 다음과 같습니다.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을 확장, [텍스트 영역을 사용하는 방법 (HTTP에 스윙 튜토리얼에서 섹션을 읽어 – mKorbel
된 AWT보다는 스윙을 사용하시기 바랍니다 : // 문서 .oracle.com/javase/tutorial/uiswing/components/textarea.html). 'TextDemo' 코드는 코드를 더 잘 구조화하는 방법을 보여줍니다. 모든 확장 클래스 나 정적 메소드가 필요하지 않습니다. 자습서의 작업 코드로 시작하여 변경하십시오. – camickr
@camickr 그는 Swing에 대해 묻지 않습니다. AWT로 어떻게하는지 알고 싶어합니다. – CodingNinja