Java JFrame未显示,未显示任何内容

Java JFrame未显示,未显示任何内容,java,jframe,Java,Jframe,我不知道为什么我的JFrame没有显示出来,它真的让我很烦,我觉得我错过了一些简单的东西,只是看不到而已。所以,任何帮助都会很棒 代码如下: import java.awt.*; import java.awt.EventQueue; import javax.swing.*; import javax.swing.GroupLayout.*; public class Lorenzo_ChatClient_class extends JFrame { private JPanel cont

我不知道为什么我的
JFrame
没有显示出来,它真的让我很烦,我觉得我错过了一些简单的东西,只是看不到而已。所以,任何帮助都会很棒

代码如下:

import java.awt.*;
import java.awt.EventQueue;
import javax.swing.*;
import javax.swing.GroupLayout.*;

public class Lorenzo_ChatClient_class extends JFrame {

private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Lorenzo_ChatClient_class frame = new Lorenzo_ChatClient_class();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/** Create the frame. */
public Lorenzo_ChatClient_class() {
    //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    JFrame frame = new JFrame();
    frame.setSize(100,100);

    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    textField_1 = new JTextField();
    textField_1.setBounds(0, 244, 450, 34);
    contentPane.add(textField_1);
    textField_1.setColumns(10);

    JButton btnNewButton = new JButton("Send");
    btnNewButton.setBounds(351, 6, 99, 122);
    contentPane.add(btnNewButton);

    JButton btnNewButton_1 = new JButton("Quit");
    btnNewButton_1.setBounds(351, 124, 99, 122);
    contentPane.add(btnNewButton_1);

    JTextArea textArea_1 = new JTextArea();
    textArea_1.setBorder(UIManager.getBorder("EditorPane.border"));
    textArea_1.setBounds(6, 6, 345, 240);
    contentPane.add(textArea_1);

    JTextArea textArea = new JTextArea();

    textField = new JTextField();
    textField.setColumns(10);


}
}

显然,我读了你的代码太快了,因为你确实有Lorenzo_ChatClient_类扩展了JFrame。这彻底改变了解决方案

我认为你的主要方法看起来不错。您不应该在构造函数中调用可重写的方法;这会导致很多错误。尝试将代码更改为:

import java.awt.*;
import java.awt.EventQueue;
import javax.swing.*;
import javax.swing.GroupLayout.*;
import javax.swing.border.*;

class Lorenzo_ChatClient_class extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Lorenzo_ChatClient_class frame = new Lorenzo_ChatClient_class();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

public Lorenzo_ChatClient_class() {
    super();
    frameSetup();
    setVisible(true); // or just keep it in your main method
}

private void frameSetup() {
    this.setBounds(100, 100, 450, 300);
    this.setSize(100, 100);
    this.contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    textField_1 = new JTextField();
    textField_1.setBounds(0, 244, 450, 34);
    contentPane.add(textField_1);
    textField_1.setColumns(10);

    JButton btnNewButton = new JButton("Send");
    btnNewButton.setBounds(351, 6, 99, 122);
    contentPane.add(btnNewButton);

    JButton btnNewButton_1 = new JButton("Quit");
    btnNewButton_1.setBounds(351, 124, 99, 122);
    contentPane.add(btnNewButton_1);

    JTextArea textArea_1 = new JTextArea();
    textArea_1.setBorder(UIManager.getBorder("EditorPane.border"));
    textArea_1.setBounds(6, 6, 345, 240);
    contentPane.add(textArea_1);

    JTextArea textArea = new JTextArea();

    textField = new JTextField();
    textField.setColumns(10);
    }
}
我刚试过,这对我来说很有用,虽然它是一个小框架。不确定你的理由是什么,在
setbounds(100100450300)
之后紧接着
setSize(100100)
。将大小设置为450x300,然后立即将大小重置为100x100。我删除了
setSize(100100)
行,JFrame打开得更好。

在您的主要方法中

Lorenzo_ChatClient_class frame = new Lorenzo_ChatClient_class();
在构造函数中

setBounds(100, 100, 450, 300);
JFrame frame = new JFrame();
frame.setSize(100,100);

You have taken class reference and JFrame names are same "frame".

您可以将主要方法简化为以下行:
EventQueue.invokateLater(()->new Lorenzo_ChatClient_class().setVisible(true))
JFrame frame=newjframe();框架。设置尺寸(100100)此帧?您尚未添加到contentPane的内容?或者你没有添加的文本区域?我编辑了我的答案,因为我读了你的代码太快了。您正确地扩展了JFrame,但是您的构造函数有点不稳定。我将大部分代码移到了一个setup方法中,代码似乎可以正常工作。