Good Day...
the problem is that the Jbutton is not displaying in my Jpanel.
can you help me, this will help me a lot, Thanks Here's the code
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class GameBoard extends JPanel implements ActionListener {
JButton start = new JButton("START");
JButton controls = new JButton("CONTROLS");
JButton credit = new JButton("CREDITS");
JButton exit = new JButton("EXIT");
public GameBoard() {
JFrame frame = new JFrame("The Palace");
frame.setSize(800,600);
frame.setResizable(false);
frame.setVisible(true);
}
public void initComponents() {
//to detect button clicks
start.addActionListener(this);
controls.addActionListener(this);
credit.addActionListener(this);
exit.addActionListener(this);
add(start);
add(controls);
add(credit);
add(exit);
}
public void actionPerformed (ActionEvent e) {
JButton press = (JButton)e.getSource();
if (press.equals(this.start)) {
new start();
setVisible(false);
}
if (press.equals(this.controls)) {
new controls();
setVisible(false);
}
if (press.equals(this.credit)) {
new credit();
setVisible(false);
}
if (press.equals(this.exit)) {
int response = JOptionPane.showConfirmDialog(null, "Do you want \nto continue the Game?", "Exit Game", 0, 3);
if (response == 0)
System.exit(0);
}
}
public void playLoop(String filename)
{
try {
URL url = getClass().getResource(filename);
}
catch (Exception e) {
}
}
public static void main(String[] args) {
new GameBoard();
}
}