Hey I need some help with my java game Im making.
I wont to have an menu with 4 options, startgame, highscore, option and quit.

They quit button is easy I just setVisible(false) but when i click on the other buttons I wont to remove the buttons and include new layouts.

Ive tried to use removeALL(); to clear the container and add() a new panel to the container but it doesnt work and Im not sure I can do it that way.

Anyone have some tips or ideas how to make an menu so please share maby Im thinking all wrong I dont know..?

if you do things like removeAll() on a JFrame or JPanel, then after adding new panels, you might need to call revalidate() or validate(). I've told people that before and they've reported back success, so go try it and let me know. If that doesn't work, post all of your code so that I can run it and I'll help.

Ive tried to use validate() but I cant se any difference, I probably did something wrong but this is my code Im kinda new to java so the code is what it is and parts like design and the number generator are far from finish.

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Spel extends JFrame implements KeyListener,ActionListener{
	Label label = new Label();
	private Container c;
	private JButton Start, Highscore, Option, quit;
	private Panel Home = new Panel();
	private Panel Game = new Panel();
	private Dimension Button_size = new Dimension(80,30);
	private JLabel L[];
	private JLabel test;

	public Spel(){
		c = getContentPane();
		c.setLayout(new BorderLayout());
		Game.setLayout(new GridLayout(label.getRows(), label.getColumn()));
		Home.setLayout(new FlowLayout());
 	    c.add(Home, BorderLayout.NORTH);
        Start = new JButton("Start Game");
 	    Home.add(Start, BorderLayout.LINE_END);
 	    Highscore = new JButton("Highscore");
 	 	Home.add(Highscore, BorderLayout.SOUTH);
 	    Option = new JButton("Option");
 	   	Home.add(Option, BorderLayout.SOUTH);
 	    quit = new JButton("Quit");
 	    Home.add(quit, BorderLayout.SOUTH);
 		    addKeyListener (this) ; 
			addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){

	public void keyPressed(KeyEvent arg0) {

	public void keyReleased(KeyEvent arg0) {

	public void keyTyped(KeyEvent arg0) {

	public void actionPerformed(ActionEvent e) {
		String s = e.getActionCommand();
		if (s.equals("start")){
			c.remove(Home);			// This is were Im trying to remove Home and add the Game layout
			c.add(Game, BorderLayout.CENTER);
			Start.setText("Reset game");
		if (s.equals("highscore")){
		if (s.equals("option")){
		if (s.equals("quit")){
		if (s.equals("reset")){
	private void startGame(){

		int size = label.getColumn() * label.getRows();
		L = new JLabel[size];
		int c = 0;
		int r = 0;

		for (int i = 1; i < size; i++){
			L[i] = new JLabel();
			L[i].setText(""+label.getLabel(r, c));
			if (c == label.getColumn()){
				c = 1;
	public static void main (String[]args ){  
		new Spel();

import java.util.Random;

public class Label {
	Random rand = new Random();
	private int column = 4;
	private int rows = 4;
	private static int[][] labels;	
	public Label(){
		labels = new int[5][5];
		labels[4][4] = 16;
	public int test(){
		return labels[4][4];
	public void setsize(int c, int r){
		column = c;
		rows = r;
	public int getHight(){
		int hight = rows * 100;
		return hight;
	public int getWidth(){
		int width = column * 100;
		return width;
	public int getColumn(){
		return column;
	public int getRows(){
		return rows;
	public void labelSize(){
		labels = new int[rows][column];
	public void labelFill(){
		int x = 0;
		int r = 0;
		int c = 0;
		int b = 0;
		int size = column * rows;
		int temp[] = new int[size];
		for(int i = 1; i < size; i++){
			while( b < 5 ){
			x = rand.nextInt(16) + 1;
				if ( temp[x] != x ){
					temp[x] = x;
					b = 10;
			labels[r][c] = x;
			if (r == column){
				r = 1;
	public int getLabel(int c, int r){
		return labels[r][c];


Move the validate() call down after you add the "Game" component

c.add(Game, BorderLayout.CENTER);