有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

用户界面Java Gui内容不会出现

我有这段代码,但当我运行它时,只有黑色的窗口背景出现,但其他所有东西都没有

这是我运行它时显示的内容:

This is what appears when I run it.

当我运行IDE时,它也会在控制台中给我这个消息,但这些行没有什么问题:

My IDE also gives me this message in the console when i run it but there is nothing wrong with those lines

import javax.swing.*;
import java.awt.*;
import java.util.*;

public class Main{
    JFrame window;
    Container container;
    JPanel titleNamePanel;
    JPanel startButtonPanel;
    JLabel titleNameLabel;
    Font titleFont = new Font("Times New Roman", Font.BOLD, 90);
    Font normalFont = new Font("Times New Roman", Font.PLAIN, 40);
    JButton startButton;

    public static void main(String [] args){
        //Variables
        Scanner myScanner = new Scanner(System.in);

        new Main();

    }
    public Main(){
        window = new JFrame();
        window.setSize(1500, 1500);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.getContentPane().setBackground(Color.BLACK);
        window.setLayout(null);
        window.setVisible(true);
        window.setResizable(true);
        container = window.getContentPane();

        titleNamePanel = new JPanel();
        titleNamePanel.setBounds(100, 100, 1000, 150);
        titleNamePanel.setBackground(Color.BLACK);
        titleNameLabel = new JLabel("ADVENTURE CAVE");
        titleNameLabel.setForeground(Color.white);
        titleNameLabel.setFont(titleFont);


        startButtonPanel = new JPanel();
        startButtonPanel.setBounds(500, 400, 200, 100);
        startButtonPanel.setBackground(Color.BLUE);
        startButton.setFont(normalFont);

        startButton = new JButton("START");
        startButton.setBackground(Color.BLACK);
        startButton.setForeground(Color.RED);

        container.add(titleNamePanel);
        titleNamePanel.add(titleNameLabel);
        container.add(startButtonPanel);
        startButtonPanel.add(startButton);
    }
}

共 (0) 个答案