@Override public void mouseClicked(MouseEvent event) { Object obj = event.getSource(); if (obj instanceof JButton) { JButton clickedButton = (JButton) obj; if (clickedButton.equals(one)) { this.clearPanel(); Game next = new Game(this.frame, 1, this.bc); next.setBounds(0, 0, this.getWidth(), this.getHeight()); this.frame.setContentPane(next); this.revalidate(); this.repaint(); } if (clickedButton.equals(two)) { this.clearPanel(); Game next = new Game(this.frame, 2, this.bc); next.setBounds(0, 0, this.getWidth(), this.getHeight()); this.frame.setContentPane(next); this.revalidate(); this.repaint(); } if (clickedButton.equals(three)) { this.clearPanel(); Game next = new Game(this.frame, 3, this.bc); next.setBounds(0, 0, this.frame.getWidth(), this.frame.getHeight()); this.frame.setContentPane(next); this.revalidate(); this.repaint(); } if (clickedButton.equals(four)) { this.clearPanel(); Game next = new Game(this.frame, 4, this.bc); next.setBounds(0, 0, this.frame.getWidth(), this.frame.getHeight()); // this.frame.setContentPane(next); this.frame.add(next); this.revalidate(); this.repaint(); } if (clickedButton.equals(back)) { this.clearPanel(); HomePanel next = new HomePanel(this.frame, bc); next.setBounds(0, 0, this.getWidth(), this.getHeight()); // this.frame.setContentPane(next); this.frame.add(next); this.revalidate(); this.repaint(); } } }