JTextArea在您选择之前不会显示



我的代码创建了一个基本的注册屏幕,但JTextArea objTE1在您选择文本所在位置之前不会显示。

import java.awt.*;
import javax.swing.*;
public class SignUpScreen extends Frame
{
    SignUpScreen()
    {
        super("No Layout Manager");
        setLayout(null);
        setTitle("Sign Up");
        setSize(400,700);
        show();
    }
    public static void main(String[] args)
    {
        Frame objFrame;
        JTextArea objTE1;
        JCheckBox objCheckMail;
        JCheckBox objCheckEmail;
        JCheckBox objCheckPhone;
        Button objButtonFinish;
        Button objButtonCancel;
        TextField objEnterEmail;
        TextField objEnterAdress;
        TextField objEnterPhone;
        TextField objEnterUsername;
        TextField objEnterPassword;
        TextField objConfirmPassword;

        objFrame = new SignUpScreen();
        objTE1 = new JTextArea();
        objCheckMail = new JCheckBox("Mail Notifications");
        objCheckEmail = new JCheckBox("Email Notifications");
        objCheckPhone = new JCheckBox("Text Notifications");
        objButtonFinish = new Button("Sign Up");
        objButtonCancel = new Button("Cancel");
        objEnterEmail = new TextField("Enter Email",0);
        objEnterAdress = new TextField("Enter Adress",0);
        objEnterPhone = new TextField("Enter Phone Number",0);
        objEnterUsername = new TextField("Enter Username",0);
        objEnterPassword = new TextField("Enter Password",0);
        objConfirmPassword = new TextField("Confirm Password",0);
        Font pagehead = new Font("Verdana", Font.BOLD, 24);
        objTE1.setFont(pagehead);
        objTE1.setForeground(Color.BLUE);
        objTE1.setText("     Sign up for thenWatermelone Mail List");
        objTE1.setEditable(false);
            objTE1.setVisible(true);

        objTE1.setBounds(50, 75, 300, 70);
        objCheckMail.setBounds(100,450,200,50);
        objCheckEmail.setBounds(100,500,200,50);
        objCheckPhone.setBounds(100,550,200,50);
        objEnterEmail.setBounds(100,150,150,20);
        objEnterAdress.setBounds(100,200,200,20);
        objEnterPhone.setBounds(100,250,200,20);
        objEnterUsername.setBounds(100,300,200,20);
        objEnterPassword.setBounds(100,350,200,20);
        objConfirmPassword.setBounds(100,400,200,20);
        objButtonFinish.setBounds(50,600,120,60);
        objButtonCancel.setBounds(220,600,120,60);

        objFrame.add(objTE1);
        objFrame.add(objEnterEmail);
        objFrame.add(objButtonFinish);
        objFrame.add(objButtonCancel);
        objFrame.add(objEnterUsername);
        objFrame.add(objEnterPassword);
        objFrame.add(objConfirmPassword);
        objFrame.add(objEnterAdress);
        objFrame.add(objEnterPhone);
        objFrame.add(objCheckMail);
        objFrame.add(objCheckPhone);
        objFrame.add(objCheckEmail);
    }
}
  1. 不要使用"空布局"。Swing设计用于布局管理器
  2. 创建文本区域时使用new JTextArea(5, 30);。即指定文本区域的行/列
  3. 不要在Swing应用程序中使用AWT组件。Swing组件以"J"、JButton、JTextField、JFrame开头
  4. 不要使用show()。正确的方法是setVisible(true)
  5. Event Dispatch Thread (EDT)上创建GUI组件
  6. setVisible(true)需要在所有组件都已添加到帧之后完成

我建议您阅读Swing教程中关于使用布局管理器的部分,了解使用布局管理程序的一些示例以及使用EDT的示例。

相关内容

  • 没有找到相关文章

最新更新