package jules.flappybirdpoles;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.*;
public class TitleScreen extends JPanel {
private static final long serialVersionUID = 1L;
JButton startButton = new JButton();
JLabel gameLabel = new JLabel();
protected TitleScreen() {
this.setBackground(Color.blue);
this.setPreferredSize(new Dimension(GamePanel.screenWidth, GamePanel.screenHeight));
this.setLayout(null);
//start button code
startButton.setSize(400, 50);
startButton.setLocation(GamePanel.screenWidth / 2 - 200, 400);
startButton.setText("Start Game");
this.add(startButton);
//game label
gameLabel.setFont(new Font("Arial", Font.BOLD, 80));
gameLabel.setVisible(true);
gameLabel.setText("FLAPPY BIRD");
gameLabel.setLayout(null);
gameLabel.setLocation(500, 80);
this.add(gameLabel);
this.setVisible(true);
}
}
#Java Scwing JLabel not showing
1 messages · Page 1 of 1 (latest)
Detected code, here are some useful tools:
<@&987246487241105418> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
nsion(JFrame) {
private JLabel titleLabel;
public TitleScreen() {
// Set up the title label
titleLabel = new JLabel("Flappy Bird");
titleLabel.setFont(new Font("Arial", Font.BOLD, 48));
titleLabel.setForeground(Color.WHITE);
titleLabel.setHorizontalAlignment(JLabel.CENTER);
// Set up the frame
this.getContentPane().setBackground(Color.BLACK);
this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
this.setPreferredSize(new Dimension(400, 600));
// Add components to the frame
this.add(Box.createVerticalGlue());
this.add(titleLabel);
this.add(Box.createVerticalGlue());
// Set up the frame properties
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
TitleScreen titleScreen = new TitleScreen();
titleScreen.setVisible(true);
});
}
}
I am trying to program a small title screen for a flappy bird clone i´m making, but the jlabel with the game Title wont show
Closed the thread due to inactivity.
If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍
Reopening message goes here