Study Guide Template Graphical User Interface OVERVIEW Now you’ll develop a graphical user interface for the TicTacToe game. This project will assess your understanding of AWT, Swing, and event...

1 answer below »
my next assignment needed number 5 out of 6


Study Guide Template Graphical User Interface OVERVIEW Now you’ll develop a graphical user interface for the TicTacToe game. This project will assess your understanding of AWT, Swing, and event handling. Make sure that you follow all directions completely and verify your results before submitting the project. Remember to include all required components in your solution. YOUR PROJECT In this project, you’ll create the GUI front-end for the TicTacToe game. This application will leverage the classes you wrote in the graded project for Lesson 3. You’ll copy code from Graded Project 3 for this project. Figure 20 is a guide for the completed user interface. G ra d e d P ro je c t G ra d e d P ro je c t INSTRUCTIONS 1. In NetBeans, create a new Java Application project named TicTacToeGUIGame. 2. Copy the games.board package from the Lesson 3 proj- 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 g2.drawOval(offset, offset, this.getWidth() - offset * 2, this.getHeight() - offset * 2); break; case CROSS: g2.setColor(Color.BLACK); //Draw X This code uses the enhanced Graphics2D class to set the stroke thickness to more than one pixel. The Oracle documentation provides more guidance on creating com- plex geometric shapes using the Graphics2D class at http://docs.oracle.com/javase/tutorial/2d/ geometry/index.html. Remember to import the java.awt and javax.swing packages! 5. In the Board.java file, have the Board class extend the JPanel class. This action will ensure that the board can lay out 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 javax.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 javax.swing packages. g2.drawLine(offset, offset, this.getWidth() - offset , this.getHeight() - offset ); g2.drawLine(this.getWidth() - offset, offset , offset, this.getHeight()- 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); } } } 9. 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 ae) { cell c = (cell) ae.getsource(); taketurn(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. how did you do? test to make sure that each button displays a nought or cross when clicked. submission guidelines to submit your project, you should submit the final jar file: tictactoeguigame.jar to ensure the jar file is built, you should click the build button or hit the f11 key. to find the jar file with netbeans, go to the tictactoeguigame project folder. to determine this folder, right-click on tictactoeguigame project in the projects panel. copy the value for the project folder textbox using the keyboard shortcut ctrl+c. in windows explorer, paste the project folder path and hit the enter key. copy the tictactoeguigame.jar file to your desktop or any other temporary location. follow this procedure to submit your project online: 1. log on to the penn foster website and go to student portal. 2. click take exam. 3. attach your file as follows: a. click on the browse box. b. locate the file you wish to attach. c. double-click on the file. d. click upload file. 4. enter your email address in the box provided. (note: this information is required for online submissions.) 5. if you wish to tell your instructor anything specific regarding this assignment, enter it in the message box. 6. click submit file. grading criteria your instructor will use the following guidelines to grade your project. the game window displays correctly 40 points the buttons behave correctly when clicked 40 points jar file is provided: 20 points total 100 points self-check 1 1. procedural programming languages use step-by-step instructions, while object-oriented programming (oop) languages model real-world structures and relationships. procedural programming languages separate data and instructions, but object-oriented languages combine them into fields and methods of objects. 2. a java application that’s written and compiled can run on any platform with the java virtual machine (jvm) installed. the developer doesn’t need to write code for a specific cpu, motherboard, chipset, or operating system. self-check 2 1. java micro edition (me) is a configurable subset of java se (standard edition), because it must support smaller, embedded devices that can’t store all class libraries found in se. 2. the jdk (java development kit) is required to write applications, because it includes the compiler and other developer tools. the jdk isn’t required to run java applications—only the jre (java runtime environment) is needed. the jre includes the jvm (java virtual machine), runtime commands and applications, and essential class libraries. self-check 3 1. the extension of a source code file is .java and the command that compiles it is javac. 2. the extension of a bytecode file is .class and the com- mand that runs it is java or javaw. a n s w e r s a n s w e r s cells[r].length;="" c++)="" {="" cells[r][c]="new" cell(r,c);="" this.add(cells[r][c]);="" cells[r][c].addactionlistener(ah);="" }="" }="" }="" 9.="" 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="" ae)="" {="" cell="" c="(Cell)" ae.getsource();="" taketurn(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.="" how="" did="" you="" do?="" test="" to="" make="" sure="" that="" each="" button="" displays="" a="" nought="" or="" cross="" when="" clicked.="" submission="" guidelines="" to="" submit="" your="" project,="" you="" should="" submit="" the="" final="" jar="" file:="" tictactoeguigame.jar="" to="" ensure="" the="" jar="" file="" is="" built,="" you="" should="" click="" the="" build="" button="" or="" hit="" the="" f11="" key.="" to="" find="" the="" jar="" file="" with="" netbeans,="" go="" to="" the="" tictactoeguigame="" project="" folder.="" to="" determine="" this="" folder,="" right-click="" on="" tictactoeguigame="" project="" in="" the="" projects="" panel.="" copy="" the="" value="" for="" the="" project="" folder="" textbox="" using="" the="" keyboard="" shortcut="" ctrl+c.="" in="" windows="" explorer,="" paste="" the="" project="" folder="" path="" and="" hit="" the="" enter="" key.="" copy="" the="" tictactoeguigame.jar="" file="" to="" your="" desktop="" or="" any="" other="" temporary="" location.="" follow="" this="" procedure="" to="" submit="" your="" project="" online:="" 1.="" log="" on="" to="" the="" penn="" foster="" website="" and="" go="" to="" student="" portal.="" 2.="" click="" take="" exam.="" 3.="" attach="" your="" file="" as="" follows:="" a.="" click="" on="" the="" browse="" box.="" b.="" locate="" the="" file="" you="" wish="" to="" attach.="" c.="" double-click="" on="" the="" file.="" d.="" click="" upload="" file.="" 4.="" enter="" your="" email="" address="" in="" the="" box="" provided.="" (note:="" this="" information="" is="" required="" for="" online="" submissions.)="" 5.="" if="" you="" wish="" to="" tell="" your="" instructor="" anything="" specific="" regarding="" this="" assignment,="" enter="" it="" in="" the="" message="" box.="" 6.="" click="" submit="" file.="" grading="" criteria="" your="" instructor="" will="" use="" the="" following="" guidelines="" to="" grade="" your="" project.="" the="" game="" window="" displays="" correctly="" 40="" points="" the="" buttons="" behave="" correctly="" when="" clicked="" 40="" points="" jar="" file="" is="" provided:="" 20="" points="" total="" 100="" points="" self-check="" 1="" 1.="" procedural="" programming="" languages="" use="" step-by-step="" instructions,="" while="" object-oriented="" programming="" (oop)="" languages="" model="" real-world="" structures="" and="" relationships.="" procedural="" programming="" languages="" separate="" data="" and="" instructions,="" but="" object-oriented="" languages="" combine="" them="" into="" fields="" and="" methods="" of="" objects.="" 2.="" a="" java="" application="" that’s="" written="" and="" compiled="" can="" run="" on="" any="" platform="" with="" the="" java="" virtual="" machine="" (jvm)="" installed.="" the="" developer="" doesn’t="" need="" to="" write="" code="" for="" a="" specific="" cpu,="" motherboard,="" chipset,="" or="" operating="" system.="" self-check="" 2="" 1.="" java="" micro="" edition="" (me)="" is="" a="" configurable="" subset="" of="" java="" se="" (standard="" edition),="" because="" it="" must="" support="" smaller,="" embedded="" devices="" that="" can’t="" store="" all="" class="" libraries="" found="" in="" se.="" 2.="" the="" jdk="" (java="" development="" kit)="" is="" required="" to="" write="" applications,="" because="" it="" includes="" the="" compiler="" and="" other="" developer="" tools.="" the="" jdk="" isn’t="" required="" to="" run="" java="" applications—only="" the="" jre="" (java="" runtime="" environment)="" is="" needed.="" the="" jre="" includes="" the="" jvm="" (java="" virtual="" machine),="" runtime="" commands="" and="" applications,="" and="" essential="" class="" libraries.="" self-check="" 3="" 1.="" the="" extension="" of="" a="" source="" code="" file="" is="" .java="" and="" the="" command="" that="" compiles="" it="" is="" javac.="" 2.="" the="" extension="" of="" a="" bytecode="" file="" is="" .class="" and="" the="" com-="" mand="" that="" runs="" it="" is="" java="" or="" javaw.="" a="" n="" s="" w="" e="" r="" s="" a="" n="" s="" w="" e="" r="">
Answered Same DayMar 11, 2021

Answer To: Study Guide Template Graphical User Interface OVERVIEW Now you’ll develop a graphical user interface...

Pratik answered on Mar 13 2021
162 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here