hey everyone,
i have been struggling with 2 frames.
the question here is, how can you let a frame disappear and let another one appear.
im making a game and when i click on start it needs to show another frame.
can someone help me with this?
got the whole code here:
import java.awt.Color; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class RushhourStart { public static void main(String [] args) { JFrame frame = new JFrame(); frame.setSize(700, 700); frame.setTitle("Rushhour"); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); frame.setVisible(true); makegame(frame); } public static void makegame(JFrame frame) { JFrame gameframe = new JFrame(); gameframe.setSize(700, 700); gameframe.setLocationRelativeTo(null); gameframe.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); makeBord panel = new makeBord(); panel.setLayout(null); panel.setBackground(Color.black); frame.add(panel); JButton Start = new JButton("START SPEL"); Start.setBounds(250, 100, 200, 50); panel.add(Start); Start.addMouseListener(panel); JButton Highscore = new JButton("HIGHSCORES"); Highscore.setBounds(250, 180, 200, 50); panel.add(Highscore); JButton Exit = new JButton("Exit"); Exit.setBounds(250, 260, 200, 50); panel.add(Exit); } } // second class: import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JPanel; public class makeBord extends JPanel implements MouseListener { @Override public void mouseClicked(MouseEvent arg0) { } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub } }