用户界面Java Gui内容不会出现
我有这段代码,但当我运行它时,只有黑色的窗口背景出现,但其他所有东西都没有
这是我运行它时显示的内容:
当我运行IDE时,它也会在控制台中给我这个消息,但这些行没有什么问题:
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) 个答案