Question: import java.awt.event.ActionListener; import javax.swing.JButton; public class TicTacToeGame implements java.awt.event.ActionListener { private WsuWindow win; JButton[] buttons; public TicTacToeGame() { win = new WsuWindow(10, 10, 235, 280);

import java.awt.event.ActionListener; import javax.swing.JButton;

public class TicTacToeGame implements java.awt.event.ActionListener { private WsuWindow win; JButton[] buttons;

public TicTacToeGame() { win = new WsuWindow(10, 10, 235, 280); win.setTitle("Tic-Tac-Toe."); JButton[] buttons = new JButton[9];

} } public void actionPerformed(java.awt.event.ActionEvent e) { for (int i = 0; i < 9; i++) { buttons [i] = new JButton(); win.add(buttons[i]); win.repaint(); // Add ActionListener } } public static void main(String[] args) { new TicTacToeGame(); } }

Please help! I am trying to make a Tic Tac Toe Board, and I need to use a loop to create 9 instances of JButton to fill the array and set the size of the buttons to be 50x50 pixels.

The tic-tac-toe board will "start" (the upper-left corner) at (30, 30). Between the rows and the columns there is a 5-pixel space. So the second column will start at (85, 30). That's the left-edge of the board (30), plus the width of a square (50), plus the blank space between columns (5). Similarly, the right-most column will start at (140, 30). The upper-left corner of the middle square is (85, 85); the upper-left corner of the lower-right square is (140, 140); etc. Note, you can use some algebra to create a formula for the location (x- and y-coordinates) rather than needing to hard-code the 9 locations in your source code.

add the TicTacToe class as the action listener for the buttons.

add the buttons to the window.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!