u/ResearcherThese8675

Some help with code

Hello! I finally decided to do the push into trying to make a simple game on Java, starting with a simple text game. I do have some programming knowledge, and I'm using this game making to help me learn more about the language. I've been following a tutorial on how to make a game, and it has been going good so far execept for one thing. When making the main menu, everything went well on adding the main text and button, but, for some reason, while changing the size of the text of the button something broke on the code, and text has disappeared from the title panel. The button that was there previously is now also gone. Anyone can elighten me on what's wrong?

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class Game {
    JFrame window;
    Container con;
    JPanel titleNamePanel, startButtonPanel;
    JLabel titleNameLabel;
    Font titleFont = new Font("Times New Roman", Font.PLAIN, 80);
    Font normalFont = new Font("Times New Roman", Font.PLAIN, 28);
    JButton startButton;  
    public static void main(String[] args) {
         new Game();
    }
    public Game() {
        window = new JFrame();
        window.setSize(800, 600);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.getContentPane().setBackground(Color.darkGray);
        window.setLayout(null);
        window.setVisible(true);
        con = window.getContentPane();


        titleNamePanel = new JPanel();
        titleNamePanel.setBounds(85, 100, 600, 100);
        titleNamePanel.setBackground(Color.black);
        titleNameLabel = new JLabel("WIZARD GAME");
        titleNameLabel.setForeground(Color.white);
        titleNameLabel.setFont(titleFont);


        startButtonPanel = new JPanel();
        startButtonPanel.setBounds(300, 400, 200, 100);
        startButtonPanel.setBackground(Color.black);


        startButton = new JButton("START");
        startButton.setBackground(Color.black);
        startButton.setForeground(Color.white);
        startButton.setFont(normalFont);


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


}
reddit.com
u/ResearcherThese8675 — 2 days ago