Im trying to make a game. I have a frame and insert jbutton jlabel jtextfield on the frame and the frame has a background. But now it doesnt appear. Why isnt buttons etc visible? Can you fix these codes?
public class NewPlayer extends JFrame {
public NewPlayer() {
JLabel backGround = new JLabel(new ImageIcon("images\\fiha2taban2.png"));
setTitle("FiHa");
setSize(750, 550);
getContentPane().add(backGround);
setLocationRelativeTo(null); // Center the frame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
setIconImage(Toolkit.getDefaultToolkit().getImage("images\\iconfh.png"));
Color renk=new Color(255,250,155);
// Create two labels and set their components
JLabel label1= new JLabel("NEW PLAYER !");
label1.setBounds(220,200,300,40);
this.add(label1);
label1.setFont(new Font("Times New Roman", Font.BOLD , 40));
JLabel label2= new JLabel("Please enter your name: ");
label2.setBounds(270,290,249,40);
this.add(label2);
label2.setFont(new Font("Times New Roman", Font.BOLD , 20));
// Create a text field and set its components
JTextField txtField = new JTextField("", 20);
txtField.setBounds(220,335,300,40);
this.add(txtField);
txtField.setFont(new Font("Times New Roman", Font.BOLD , 16));
// Create a button and set its components
JButton button1 = new JButton("OKAY");
button1.setBounds(315,396,110,40);
this.add(button1);
button1.setFont(new Font("Times New Roman", Font.BOLD , 16));
button1.setBackground(renk);
}
}
}