0

I've made a board for a sudoku game but this one thing has got me stumped. It's late where i'm at and i've been working for a while and i cant find my problem. Would be nice if someone could point it out, thanks!

   import java.awt.GridLayout;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;
   import javax.swing.JFrame;
   import javax.swing.JMenu;
   import javax.swing.JMenuBar;
   import javax.swing.JPanel;

   public class SudokuPanel extends JFrame {

       public final int SQUARE_COUNT = 9;
       public Squares [] squares = new Squares[SQUARE_COUNT];

       public SudokuPanel(){

           super("Sudoku");
           setSize(600,600);
           setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           setLayout(new GridLayout(1,1));
           setVisible(true);
           setLocationRelativeTo(null);

           JPanel panel = new JPanel(new GridLayout(3,3));
           for(int i=0; i<SQUARE_COUNT; i++){
               squares[i] = new Squares();
               panel.add(squares[i]);
           }

           add(panel);

           JMenuBar menuBar = new JMenuBar();
           setJMenuBar(menuBar);

           JMenu reset = new JMenu();
           menuBar.add(reset);

           JMenu help = new JMenu();
           menuBar.add(help);

           JMenu newPuzzle = new JMenu();
           menuBar.add(newPuzzle);

           JMenu exit = new JMenu();
           menuBar.add(exit);

           class exitaction implements ActionListener{
               public void actionPerformed (ActionEvent e){
                   System.exit(0);
                    }
           }

           exit.addActionListener(new exitaction());



       }




   }
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366

3 Answers3

1

Invoke the setVisible(true) method AFTER adding all the components tot he frame.

camickr
  • 321,443
  • 19
  • 166
  • 288
1

You set the GUI visible before adding the menus.

Also, when you create your JMenus, you didn't name them. Try JMenu reset = new JMenu("Reset"); instead of JMenu reset = new JMenu(BLANK);

Honinbo Shusaku
  • 1,411
  • 2
  • 27
  • 45
1

Please put text for Menu. In Your code please try with the below code

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu reset = new JMenu("Reset");
    menuBar.add(reset);

    JMenu help = new JMenu("Help");
    menuBar.add(help);

    JMenu newPuzzle = new JMenu("New Puzzle");
    menuBar.add(newPuzzle);

    JMenu exit = new JMenu("Exit");
    menuBar.add(exit);
A Stranger
  • 551
  • 2
  • 11