I am trying to make a simple text adventure game in Java (with a GUI) by following this tutorial: https://www.youtube.com/watchv=RcvABhflOkI&list=PL_QPQmz5C6WUMB0xEMZosWbyQo_Kil0Fb&index=2
This is my code thus far (for reference):
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Game {
JFrame window;
JPanel titleNamePanel, startButtonPanel;
JLabel titleNameLabel, startButtonLabel;
JButton startButton;
Font titleFont = new Font("Times New Roman", Font.PLAIN, 90);
Font normalFont = new Font("Times New Roman", Font.PLAIN, 30);
public static void main(String[] args) {
new Game();
}
public Game() {
window = new JFrame();
window.setSize(900,600);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().setBackground(Color.black);
window.setLayout(null);
titleNamePanel = new JPanel();
titleNamePanel.setBounds(100,100,700,150);
titleNamePanel.setBackground(Color.black);
titleNameLabel = new JLabel("Town of Stratham");
titleNameLabel.setForeground(Color.white);
titleNameLabel.setFont(titleFont);
startButtonPanel = new JPanel();
startButtonPanel.setBounds(400,400,100,50);
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);
window.add(titleNamePanel);
window.add(startButtonPanel);
window.setVisible(true);
}
}
However, I come across some issues when I tried to make a Jbutton. I have a MacBook air and when I run the program above my button doesn't even appear. I want my button to look black and the text to be white like in the tutorial video (timestep- 22:10). I asked one of my friends who had windows to run the code and it looks exactly like what I want it to look like.
It runs this on my Max OS: Button not showing up:
This is what runs on my friend's window OS (exact same code): Button shows up fine:
So my question is how can I fix this? Is there a fix for this & why does this happen?