Advertisement
Guest User

GameGUI

a guest
Sep 14th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6. public class TicTac {
  7.  
  8. JPanel windowGame;
  9. Button[] squares = new Button[9];
  10. Button newGameButton;
  11. JLabel wonScore;
  12. JLabel loseScore;
  13. JLabel score;
  14. JPanel panel1;
  15. JPanel panel2;
  16. JPanel panel3;
  17. int emptySquaresLeft=9;
  18. int won = 0;
  19. int lose = 0;
  20.  
  21. public void init() {
  22. JPanel windowGame = new JPanel();
  23. BorderLayout bl = new BorderLayout();
  24. windowGame.setLayout(bl);
  25. JLabel wonScore = new JLabel();
  26. JLabel loseScore = new JLabel();
  27. JPanel panel1 = new JPanel();
  28. windowGame.add("North", panel1);
  29. Button newGameButton = new Button();
  30. newGameButton.setBackground(Color.GREEN);
  31.  
  32. wonScore = new JLabel ("Побед: 0");
  33. loseScore = new JLabel ("Поражений: 0");
  34.  
  35. panel1.setLayout(bl);
  36. panel1.add(newGameButton);
  37. panel1.add(wonScore);
  38. panel1.add(loseScore);
  39.  
  40. JLabel score = new JLabel ("Твой ход человек!");
  41. windowGame.add(score, "South");
  42.  
  43. JPanel panel2 = new JPanel();
  44. windowGame.add("Center", panel2);
  45. Button[] squares = new Button[9];
  46.  
  47. JFrame frame = new JFrame();
  48. frame.setContentPane(windowGame);
  49. frame.pack();
  50. frame.setVisible(true);
  51.  
  52. TicTacEngine TicTacEngine = new TicTacEngine(this);
  53. for (int i=0; i<10; i++) {
  54. squares[i] = new Button (""+i);
  55. squares[i].addActionListener(TicTacEngine); /* Cant be resolved to a variable */
  56. squares[i].setBackground(Color.ORANGE);
  57. panel2.add(squares[i]);
  58. }
  59. }
  60.  
  61. public static void main (String[] args) {
  62. TicTac TicTacGame = new TicTac();
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement