So Im making a game with a start screen followed by my game. I have a button centered but Im having a hard time displaying my label. Do you all have any options? Here's my code:
import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JFrame; public class TitleScreen extends JPanel implements ActionListener{ private String name = "Breakout"; private Container c; private JFrame menuscreen; private JButton startbutton; private JLabel label; public TitleScreen(){ menuscreen = new JFrame("Breakout Menu Screen"); label = new JLabel("Breakout"); menuscreen.add(label); startbutton = new JButton("Start"); startbutton.setPreferredSize(new Dimension (200,200)); startbutton.setBounds(110, 120, 100, 100); startbutton.addActionListener(this); menuscreen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); c = menuscreen.getContentPane(); this.setLayout(null); this.add(startbutton); c.add(this); this.setPreferredSize(new Dimension(300,300)); menuscreen.pack(); menuscreen.setLocationRelativeTo(null); menuscreen.setVisible(true); } public void paintComponents(Graphics g){ Font font1 = new Font("Arial", Font.BOLD, 70); g.setFont(new Font (name,10, 18)); g.setColor(Color.red); //g.drawString(name,120, 20); g.drawString("Breakout", 125, 250); } public static void main(String[] args){ new TitleScreen(); } public void actionPerformed(ActionEvent ae){ Object a = ae.getSource(); if(a == startbutton){ new Main(); this.menuscreen.dispose(); new Main(); } } }