Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.lang.Math;
- public class Board {
- public static void main(String[] args){
- JFrame Board = new JFrame("Tic Tac Toe");
- Board.setSize(300,300);
- Board.setLocationRelativeTo(null);
- Board.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Board.setVisible(true);
- Board.setLayout(new GridLayout(3,3,0,0));
- //I did not find a number found with Math.random from 0-2 random enough
- //so I made it 0-30.
- String k;
- for(int i=1; i<10; i++){
- int j = (int)(Math.random()*30);
- if (j<11){THIS WILL BE X ICON}
- else if(j > 10 && j < 21){THIS WILL BE O ICON}
- else {}
- k = Double.toString(j);
- }
- JLabel B1 = new JLabel(k);
- JLabel B2 = new JLabel(k);
- JLabel B3 = new JLabel(k);
- JLabel B4 = new JLabel(k);
- JLabel B5 = new JLabel(k);
- JLabel B6 = new JLabel(k);
- JLabel B7 = new JLabel(k);
- JLabel B8 = new JLabel(k);
- JLabel B9 = new JLabel(k);
- Board.add(B1);
- Board.add(B2);
- Board.add(B3);
- Board.add(B4);
- Board.add(B5);
- Board.add(B6);
- Board.add(B7);
- Board.add(B8);
- Board.add(B9);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement