From c0fc5cfb68b02fe04c508e8785f8571a6973b5c9 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Tue, 7 Feb 2023 00:24:42 +0100 Subject: [PATCH] Tic Tac Toe grid/buttons added and changed color of title textfield --- src/main/java/src/TicTacToeGame.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/src/TicTacToeGame.java b/src/main/java/src/TicTacToeGame.java index 41afa15..7e641fa 100644 --- a/src/main/java/src/TicTacToeGame.java +++ b/src/main/java/src/TicTacToeGame.java @@ -9,6 +9,7 @@ public class TicTacToeGame implements ActionListener { JPanel t_panel = new JPanel(); JPanel bt_panel = new JPanel(); JLabel textfield = new JLabel(); + JButton[] bton = new JButton[9]; // Creating class constructor @@ -22,8 +23,8 @@ public class TicTacToeGame implements ActionListener { frame.setLayout(new BorderLayout()); frame.setVisible(true); - textfield.setBackground(new Color(0,0,0)); - textfield.setForeground(new Color(255,0,0)); + textfield.setBackground(new Color(0, 0, 250)); + textfield.setForeground(new Color (100,100,255)); textfield.setFont(new Font("Serif", Font.BOLD, 25)); textfield.setHorizontalAlignment(JLabel.CENTER); textfield.setText("Tic Tac Toe"); @@ -34,7 +35,19 @@ public class TicTacToeGame implements ActionListener { bt_panel.setLayout(new GridLayout(3, 3)); bt_panel.setBackground(new Color(0, 0, 0)); - + for (int i = 0; i < 9; i++) + { + bton[i] = new JButton(); + bt_panel.add(bton[i]); + bton[i].setFont(new Font("Serif", Font.BOLD, 120)); + bton[i].setFocusable(false); + bton[i].addActionListener(this); + bton[i].setBackground(Color.cyan); + } + + t_panel.add(textfield); + frame.add(t_panel, BorderLayout.NORTH); + frame.add(bt_panel); }