Template Hwk9java package hwk9 import javaawtBorderLayout im

Template

Hwk9.java

package hwk9;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Component;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.IOException;

import javax.imageio.ImageIO;

import javax.swing.BoxLayout;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

@SuppressWarnings(\"serial\")

public class Hwk9 extends JFrame {

   Hwk9() {

       this.setTitle(\"Tic Tac Toe\");

       this.setBounds(0, 0, 600, 600);

       this.setDefaultCloseOperation(EXIT_ON_CLOSE);

   }

  

   public static void main(String[] args) throws IOException {

       // create a frame with border layout

       JFrame frame = new Hwk9();

       frame.setLayout(new BorderLayout());

      

       // create a panel with box layer aligned with y axis

       // TODO

      

       // create a new game button that is centered on x axis

       // TODO

      

       // add the new game button to the game panel

       // TODO

      

       // create a box panel with 3 x 3 grid layout

       // TODO

      

       // create an array of 9 buttons and add them to the box panel

       // TODO

      

       // instantiate a tic-tac-toe game object

       // TODO

      

       // add an action listener to the new-game buttom so that it clears the game on click.

       // TODO

      

       // add game panel (north) and box panel (center) to the frame and set it visible

       // TODO

      

   }

}

class TicTacToe {

   // this array holds flags for buttons

   // 0 means not clicked

   // 1 means X

   // 2 means O

   int[] data = new int[9];

   // array of buttons representing the grid cells of the game

   JButton[] buttons;

   // this means next move will be X if true and O if false

   boolean isX = true;

  

   // use this fields to hold image icons loaded from files

   ImageIcon icon_x, icon_o;

  

   // save buttons array

   // load icons

   // clear the grid (call the clear method)

   // add listener (call the addListener method)

   TicTacToe(JButton[] buttons) throws IOException {

       // TODO

   }

     

   // add action the same button listner to all buttons

   private void addListener() {

       // TODO

   }

   // create a button listener object directly from ActionListener interface

   // by overridding its actionPerformed method

   //

   // the actionPerformed method will find out

   // which button is clicked and

   // whether the click is successful and switch the player if so

   ActionListener buttonListener = new ActionListener() {

       @Override

       public void actionPerformed(ActionEvent e) {

           // TODO

       }

   };

  

   // set the background color to each button to white

   // remove icons by calling setIcon(null)

   // clear the data array to 0

   // reset isX to true

   void clear() {

       // TODO

   }

  

   // put X or O at the i\'th button

   // set the data array to 1 for X and 2 for O

   //

   // returns true if i\'th button is not already clicked

   private boolean play(int i, boolean isX) {

       // TODO

   }

}

Homework 9 November 5, 2016 1 Overview In this assignment, you will be creating a version of the Tic-Tac-Toe game from the Dean & Dean textbook (see Chapter 18.7, p. 830). This starter code is also available on D2L slides. 2 Requirements You may use the code in the book as a guide, but it will require some changes In particular, your game must add the following features/properties Marking a Cell The code in book just sets the text of a button to either X or O. Instead, we will be setting the icon of a button to be either an image of an X or an O. This w require a few change to the template (notably, checking if a cell has already been selected). Assuming there is a file called X.png in the same directory as the Java file, the following code will read an image from disk: ImageIcon icon ImageIcon(Image10. read (getClass().getResource ( \"X . png\"))); = new The above statement may throw a checked exception: IOException but you can avoid catching it by declaring it in method definition. You can set an icon image of a button with its setIcon method. You can remove an image from a button by setting the icon to null New Game Button You should add a new game button. This button will clear images and background color from all the buttons. No game is in progress when the frame is first created (before this button is pressed for the first time) If this button is pressed during a game, you should start a new game. 3 GUI You must make the frame conform to the following screenshot as closely as possible. My solution used several nested JPanel instances to get alignment to

Solution

#include<iostream>

#include<conio.h>

using namespace std;

// Class Declaration

class prime

{

//Member Varibale Declaration

int a,k,i;

public:

prime(int x)

{

a=x;

}

// Object Creation For Class

void calculate()

{

k=1;

{

for(i=2;i<=a/2;i++)

if(a%i==0)

{

k=0;

break;

}

else

{

k=1;

}

}

}

void show()

{

if(k==1)

cout<<\"\ \"<<a<<\" is Prime Number.\";

else

cout<<\"\ \"<<a<<\" is Not Prime Numbers.\";

}

};

//Main Function

int main()

{

int a;

cout<<\"Enter the Number:\";

cin>>a;

// Object Creation For Class

prime obj(a);

// Call Member Functions

obj.calculate();

obj.show();

getch();

return 0;

}

Template Hwk9.java package hwk9; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.GridLayout; import java.awt.eve
Template Hwk9.java package hwk9; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.GridLayout; import java.awt.eve
Template Hwk9.java package hwk9; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.GridLayout; import java.awt.eve
Template Hwk9.java package hwk9; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.GridLayout; import java.awt.eve
Template Hwk9.java package hwk9; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.GridLayout; import java.awt.eve
Template Hwk9.java package hwk9; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.GridLayout; import java.awt.eve

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site