Guest User

Untitled

a guest
Mar 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. JPanel panelCont=new JPanel(); // container
  2. JPanel panelFirst=new JPanel(); // first interface
  3. JPanel panelSecond=new GamePanel(); // seconde interface
  4.  
  5. JButton buttonOne=new JButton("New Game");
  6. JButton buttonSecond=new JButton("Score");
  7. JButton buttonThird=new JButton("Quit");
  8.  
  9. CardLayout cl=new CardLayout();
  10.  
  11.  
  12. public CLayout() {
  13.  
  14. panelCont.setLayout(cl);
  15. // ajouter les buttons dans la premire interface
  16. panelFirst.add(buttonOne);
  17. panelFirst.add(buttonSecond);
  18. panelFirst.add(buttonThird);
  19. panelFirst.setBackground(Color.BLUE);
  20. //panelSecond.setBackground(Color.red);
  21. panelCont.add(panelFirst,"1");
  22. panelCont.add(panelSecond, "2");
  23. cl.show(panelCont, "1");
  24. buttonOne.addActionListener(new ActionListener(){
  25.  
  26. @Override
  27. public void actionPerformed(ActionEvent arg0) {
  28. // TODO Auto-generated method stub
  29. cl.show(panelCont,"2"); // sends you to the seconde panel
  30. }
  31. });
  32. frame.add(panelCont);
  33. frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  34. frame.pack();
  35. frame.setVisible(true);
  36. }
  37. public static void main(String [] args) {
  38. SwingUtilities.invokeLater(new Runnable() {
  39. public void run() {
  40. new CLayout();
  41. }
  42. });
  43. }
Add Comment
Please, Sign In to add comment