jasonpogi1669

Tic Tac Toe GUI Java NetBeans

Mar 26th, 2021
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package main;
  7.  
  8. /**
  9.  *
  10.  * @author markjasongalang
  11.  */
  12. import java.awt.BorderLayout;
  13. import java.awt.Color;
  14. import java.awt.Font;
  15. import java.awt.GridLayout;
  16. import java.awt.event.ActionEvent;
  17. import java.awt.event.ActionListener;
  18. import java.util.Random;
  19. import javax.swing.JButton;
  20. import javax.swing.JFrame;
  21. import javax.swing.JLabel;
  22. import javax.swing.JPanel;
  23.  
  24. class TicTacToe implements ActionListener {
  25.    
  26.     Random random = new Random();
  27.     JFrame frame = new JFrame();
  28.     JPanel title_panel = new JPanel();
  29.     JPanel button_panel = new JPanel();
  30.     JLabel textfield = new JLabel();
  31.     JButton[] buttons = new JButton[9];
  32.     boolean player1_turn;
  33.     boolean player2_turn;
  34.    
  35.     TicTacToe() {
  36.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  37.         frame.setSize(800, 800);
  38.         frame.getContentPane().setBackground(new Color(50, 50, 50));
  39.         frame.setLayout(new BorderLayout());
  40.         frame.setVisible(true);
  41.        
  42.         textfield.setBackground(new Color(25, 25, 25));
  43.         textfield.setForeground(new Color(25, 255, 0));
  44.         textfield.setFont(new Font("Arial", Font.BOLD, 75));
  45.         textfield.setHorizontalAlignment(JLabel.CENTER);
  46.         textfield.setText("Tic-Tac-Toe");
  47.         textfield.setOpaque(true);
  48.        
  49.         title_panel.setLayout(new BorderLayout());
  50.         title_panel.setBounds(0, 0, 800, 100);
  51.        
  52.         button_panel.setLayout(new GridLayout(3, 3));
  53.         button_panel.setBackground(new Color(150, 150, 150));
  54.        
  55.         for (int i = 0; i < 9; i++) {
  56.             buttons[i] = new JButton();
  57.             button_panel.add(buttons[i]);
  58.             buttons[i].setFont(new Font("Arial", Font.BOLD, 120));
  59.             buttons[i].setFocusable(false);
  60.             buttons[i].addActionListener(this);
  61.         }
  62.        
  63.         title_panel.add(textfield);
  64.         frame.add(title_panel, BorderLayout.NORTH);
  65.         frame.add(button_panel);
  66.     }
  67.    
  68.     public void actionPerformed(ActionEvent e) {
  69.        
  70.     }
  71. }
  72.  
  73. public class Main {
  74.     public static void main(String[] args) {
  75.         TicTacToe game = new TicTacToe();
  76.     }
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment