Buy New Penn Foster 402598

$3.99

Buy New Penn Foster 402598

 

In NetBeans, create a new Java Application project
named
TicTacToeGUIGame.
2. Copy the
games. board
package from the Lesson 3 project-
ect named
BoardGameTester.
Right-click on the
game. board
package in the
BoardGameTester
project of the
Projects
pane
panel.
Choose the
Copy
option from the context menu or
use the keyboard shortcut
CTRL+C.
Paste it in the
TicTacToeGUIGame
project using the
Paste
option in the context menu or the keyboard
shortcut
CTRL+V.
Make sure to copy and paste the package in the
Source
Packages
folder.
3. In the
Cell.java
file, have the
Cell
class extend the
JButton
class. This action will ensure that each cell on
the board has the look and feel of a standard Java button.
4. Override the
paintComponent
method in the
Cell
class
as follows:
public void paintComponent(Graphics g) {
//paint the basic button first
super.paintComponent(g);
int offset = 5;
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(5));
switch(content) {
case NOUGHT:
g2.setColor(Color.RED);
//Draw O

Graded Project
197
Note:
This code uses the enhanced
Graphics2D
class
to set the stroke thickness to more than one pixel. The
Oracle documentation provides more guidance on creat-
ing complex geometric shapes using the
Graphics2D
class at
http://docs.oracle.com/javase/tutorial/2d/
geometry/index.html.
Remember to import the
java. awt
and
java. swing
packages!
5. In the
Board.java
file, have the
Board
class extend the
JPanel
class. This action will ensure that the board can
layout each cell and process its UI events.
6. Make the following modifications to the
Board
constructor:
These changes will add each cell to the UI and assign an
ActionListener
object to each cell.
Note: Remember to import the
java.awt, java.awt.event,
and java.swing
packages.
7. In the
TicTacToeGUIGame.java
file, have the
TicTacToeGUIGame
class extend
JFrame.
This action
will ensure that the game is hosted in a Java window.
8. Import the
games. board, java. awt,
and
java.swing
packages.
g2.drawLine(offset, offset, this.getWidth() – offset , this.get eight() – offset );
g2.drawLine(this.getWidth() – offset, offset , offset, this.get eight()- offset);
break;
}
}
public Board(int rows, int columns, ActionListener ah) {
cells = new Cell[rows][columns];
this.setLayout(new GridLayout());
for( int r = 0; r cells.length; r++ ) {
for (int c = 0; c cells[r].length; c++) {
cells[r][c] = new Cell(r,c);
this.add(cells[r][c]);
cells[r][c].addActionListener(ah);
}
}
}
. Add the following code to the
main
method:
SwingUtilities.invokeLater( new Runnable () {
public void run() { new TicTacToeGUIGame(); }
});
10. Declare the following instance variables in
TicTacToeGUIGame:
private Board GB;
private int turn;
11. Add the following method to handle each turn:
private void takeTurn(Cell c) {
Mark curMark = (turn++ % 2 == 0)? Mark.NOUGHT
: Mark.CROSS;
gb.setCell(curMark, c.getRow(), c.getColumn());
}
12. Define the following constructor to create the board,
provide the event listener, and display the board in
the window:
private TicTacToeGUIGame() {
GB = new Board(3, 3, new ActionListener() {
public void actionPerformed(ActionEvent
a) {
Cell c = (Cell) ae.getSource();
take turn(c);
}
});
this.add(gb);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setTitle(“TIC-TAC-TOE”);
this.setSize(300, 300);
this.setVisible(true);
}
13.
Compile and run the project. Test to make sure each
the button displays a naught or crosses when clicked

 

Want to Buy Penn Foster?

Are you looking for online test preparation assistance? You can avoid all the worries associated with taking online examinations by using our take my online exam expertise. As you prepare for your online exam, our exam helper will provide you with the most exact solution. We encourage you to ask our online exam help for advice to determine the best course of action for passing your take-a-look. Many university students in well-known international locations like the United States, Canada, Australia, and the United Kingdom have benefited from our group’s online exam assistance, and they have all received respectable grades as a result. What then are you prepared for? Seize this chance to shine on your examination. Talk to us right now!

Scott Belmont from NYC, USA
Hired a tutor to take programming class and final exam
40 minutes ago
Ebony Nicole from Bronx, USA
Hired a tutor to take history and algebra final exams
2 hours ago
Randy Wells from Texas, USA
Hired an expert to take chemistry proctored exam
1 hour ago
Kurt LeBlanc from Iowa, USA
Hired an expert to take statistics online exam
1 hour ago