Hey. Im having problems adding my Jmenubar to my board. It compiles fine just wont display. Any advice really appreciated. Thanks, Pd
import java.awt.*;
import javax.swing.*;
import javax.swing.KeyStroke;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.awt.Font;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.border.BevelBorder;
import javax.swing.WindowConstants;
import javax.swing.ImageIcon;
import javax.swing.Icon;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.ButtonGroup;
public class Board extends JFrame
{
public JPanel[][] squares;
public JFrame boardFrame;
public Container container;
public Board()
{
boardFrame = new JFrame("MyDraughts");
setJMenuBar(MyMenu());
container = boardFrame.getContentPane();
container.setLayout(new GridLayout(8,8));
create_squares();
boardFrame.setSize(400,450);
boardFrame.setVisible(true);
}
public void create_squares()
{
squares = new JPanel[8][8];
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
{
JPanel p = new JPanel();
p.setBackground(setColor(i,j));
squares[i][j]=p;
container.add(p);
}
}
}
public Color setColor(int x, int y)
{
if((x+y)%2 == 0)
return Color.WHITE;
else
return Color.BLACK;
}
private JMenuBar MyMenu()
{
// Create a menu Bar
JMenuBar MyMenuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
//Declare Menu Items and add them to the first menu
JMenuItem newMenuItem = new JMenuItem ("New Game");
fileMenu.add(newMenuItem);
//fileMenu.addSeparator();
//ButtonGroup myButtonGroup = new ButtonGroup();
MyMenuBar.add(fileMenu);
return MyMenuBar;
}
}