Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.FlowLayout;
  3. import java.awt.GridLayout;
  4.  
  5. import javax.swing.JButton;
  6. import javax.swing.JFrame;
  7. import javax.swing.JLabel;
  8. import javax.swing.JPanel;
  9.  
  10. public class View extends JFrame{
  11.  
  12. /**
  13. *
  14. */
  15. private static final long serialVersionUID = 1L;
  16.  
  17. private JButton btn[][],save,load;
  18. private JLabel playerTurn;
  19.  
  20. public View(){
  21. super("Tic Tac Toe");
  22. setLocationRelativeTo(null);
  23. btn = new JButton[3][3];
  24. save = new JButton("Save");
  25. load = new JButton("Load");
  26. playerTurn = new JLabel("j");
  27. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28. //populate();
  29.  
  30. }
  31.  
  32. public void populate(){
  33. setResizable(false);
  34. JPanel gridPanel = new JPanel(new GridLayout(3,3));
  35. JPanel menuPanel = new JPanel(new FlowLayout());
  36. JPanel showTurn = new JPanel(new FlowLayout());
  37. setSize(600,600);
  38. menuPanel.add(save);
  39. menuPanel.add(load);
  40. add(menuPanel,BorderLayout.PAGE_START);
  41. showTurn.add(playerTurn);
  42. add(showTurn,BorderLayout.PAGE_END);
  43. for(int i = 0;i < 3;i++){
  44. for(int j = 0;j < 3;j++){
  45. btn[i][j] = new JButton("");
  46. gridPanel.add(btn[i][j]);
  47. }
  48. }
  49. add(gridPanel,BorderLayout.CENTER);
  50. setLocationRelativeTo(null);
  51. setVisible(true);
  52.  
  53. }
  54.  
  55.  
  56.  
  57. public static void main(String[] args) {
  58. View v = new View();
  59. v.populate();
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement