Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.lang.Math;
  4.  
  5. public class Board extends JFrame{
  6.  
  7. public static void main(String[] args){
  8. JFrame Board = new JFrame("Tic Tac Toe");
  9. Board.setSize(300,300);
  10. Board.setLocationRelativeTo(null);
  11. Board.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  12. Board.setVisible(true);
  13. Board.setLayout(new GridLayout(3,3,0,0));
  14.  
  15. //I did not find a number found with Math.random from 0-2 random enough
  16. //so I made it 0-30.
  17.  
  18. for(int i=1; i<10; i++){
  19. int j = (int)(Math.random()*31);
  20. if (j<11){Component k = Board.add(new JLabel(new ImageIcon("X.png")));}
  21. else if(j > 10 && j < 21){Component k = Board.add(new JLabel(new ImageIcon("O.jpg")));}
  22. else {Board.add(new JLabel());}
  23. }
  24. JLabel B1 = new JLabel(new ImageIcon("O.JPG"));
  25. JLabel B2 = new JLabel();
  26. JLabel B3 = new JLabel();
  27. JLabel B4 = new JLabel();
  28. JLabel B5 = new JLabel();
  29. JLabel B6 = new JLabel();
  30. JLabel B7 = new JLabel();
  31. JLabel B8 = new JLabel();
  32. JLabel B9 = new JLabel();
  33. Board.add(B1);
  34. Board.add(B2);
  35. Board.add(B3);
  36. Board.add(B4);
  37. Board.add(B5);
  38. Board.add(B6);
  39. Board.add(B7);
  40. Board.add(B8);
  41. Board.add(B9);
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement