Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Name : Kyle Blanchard
- * Due Date : 2/14/2014
- * Course : CSCI - 211
- * Problem No. : 12.7
- * Description : Create and fill in a TicTacToe Board
- * Email : Kwblanchard@student.stcc.edu
- */
- package guiBasics;
- import java.awt.*;
- import javax.swing.*;
- public class TicTacToe extends JFrame {
- // Assigns the two images to the variables x and o.
- private ImageIcon x ;
- private ImageIcon o ;
- public static void main(String[] args) {
- // Creates the Frame.
- TicTacToe frame = new TicTacToe("TicTacToe");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(200, 200);
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
- // Constructer
- public TicTacToe(String title) {
- super(title);
- // Create board layout.
- setLayout(new GridLayout(3, 3));
- x = new ImageIcon(getClass().getResource("/image/x.gif"));
- o = new ImageIcon(getClass().getResource("/image/o.gif"));
- // Places an x or an o image in each board slot.
- for (int i = 0; i < 9; i++) {
- int randomizer = (int) (Math.random() * 2);
- if (randomizer == 1)
- add(new JLabel(this.x));
- else if (randomizer == 0)
- add(new JLabel(this.o));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement