Вот базовая реализация с использованием менеджеров компоновки, позволяющая избежать плохой практики нулевого менеджера компоновки.Это не оптимальный вариант, но вам стоит начать:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class Yeet {
JFrame epicOfYeet;
Container con;
JPanel titleNamePanel, startButtonPanel, mainTextPanel, choiceButtonPanel;
JLabel titleNameLabel;
Font titleFont = new Font("Times New Roman", Font.PLAIN, 90);
Font normalFont = new Font ("Times New Roman", Font.PLAIN, 55);
JButton startButton, coice1, choice2, choice3, choice4;
JTextArea mainTextArea;
TitleScreenHandler tsHandler = new TitleScreenHandler();
public static void main(String[] args) {
SwingUtilities.invokeLater(()->new Yeet());
}
public Yeet() {
epicOfYeet = new JFrame();
//epicOfYeet.setSize(1200, 1000); // do not set size. let layout manager calcualte it
epicOfYeet.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
epicOfYeet.getContentPane().setBackground(Color.black);
//epicOfYeet.setLayout(null); //aviod null layouts Jframe uses BorderLayout by default
con = epicOfYeet.getContentPane();
titleNamePanel = new JPanel();
//titleNamePanel.setBounds(190, 100, 800, 230);
titleNamePanel.setPreferredSize(new Dimension(800, 230));//set preferred size to be used by layout manager
titleNamePanel.setBackground(Color.black);
titleNameLabel = new JLabel("EPIC OF YEET");
titleNameLabel.setForeground(Color.red);
titleNameLabel.setFont(titleFont);
startButtonPanel = new JPanel();
//startButtonPanel.setBounds(400, 500, 400, 100);
startButtonPanel.setPreferredSize(new Dimension(400, 100));
startButtonPanel.setBackground(Color.black);
startButton = new JButton("START");
startButton.setBackground(Color.black);
startButton.setForeground(Color.white);
startButton.setFont(normalFont);
startButton.addActionListener(tsHandler);
startButton.setFocusPainted(false);
titleNamePanel.add(titleNameLabel);
startButtonPanel.add(startButton);
con.add(titleNamePanel, BorderLayout.PAGE_START); //set to top
con.add(startButtonPanel, BorderLayout.PAGE_END); //set to bottom
epicOfYeet.pack();
epicOfYeet.setVisible(true);
}
public void createGameScreen(){
//titleNamePanel.setVisible(false);
//startButtonPanel.setVisible(false);
con.remove(titleNamePanel);
con.remove(startButtonPanel);
mainTextPanel = new JPanel();
//mainTextPanel.setBounds(100, 100, 1000, 400);
mainTextPanel.setBackground(Color.green);
con.add(mainTextPanel); // added to center position of the BorderLayout (the default)
mainTextArea = new JTextArea(10, 20); //size in rows, cols
mainTextArea.setText("You come to your senses again.\nThe dewy grass you're laying on is gleaming with moonlight.\nYour body aches as you get up and catch a \nglimpse of your surroundings.\n");
//mainTextArea.setBounds(100, 100, 1000, 250);
mainTextArea.setBackground(Color.blue);
mainTextArea.setForeground(Color.white);
mainTextArea.setFont(normalFont);
mainTextArea.setLineWrap(true);
mainTextPanel.add(mainTextArea);
choiceButtonPanel = new JPanel();
//choiceButtonPanel.setBounds(300, 500, 600, 550);
choiceButtonPanel.setPreferredSize(new Dimension(600, 550));
choiceButtonPanel.setBackground(Color.red);
con.add(choiceButtonPanel, BorderLayout.PAGE_END);//add to bottom
epicOfYeet.pack();
}
public class TitleScreenHandler implements ActionListener{
@Override
public void actionPerformed(ActionEvent event) {
createGameScreen();
}
}
}