Running problem with NoughtsAndCrossesGame in blank
Hi i was having problem created NoughtsAndCrossesGame in end the it works but i runs the gui in blank. Its another way to solve it
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
* @author 000621812
*/
public class NoughtsAndCrossesGamev2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
NoughtsAndCrossesGameFrame noughtsAndCrossesGame;
noughtsAndCrossesGame = new NoughtsAndCrossesGameFrame();
noughtsAndCrossesGame.setVisible(true);
}
}
class NoughtsAndCrossesGameFrame extends JFrame {
NoughtsAndCrossesGamePanel gamePanel;
NoughtsAndCrossesButtonPanel buttonPanel;
private ButtonPlayActionHandle playHandler;
private ButtonExitActionHandler exitHandler;
private JButton playButton;
private JButton exitButton;
public NoughtsAndCrossesGameFrame() {
gamePanel = new NoughtsAndCrossesGamePanel();
buttonPanel = new NoughtsAndCrossesButtonPanel();
this.setLayout(new BorderLayout());
this.setLayout(new GridLayout(3, 0));
this.setSize(200, 200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Noughts and Crosses");
}
/**
* Asks the panel containing the game to reset the game.
*/
private void resetGame() {
//**
//* The button panel
//*/
}
class NoughtsAndCrossesButtonPanel extends JPanel {
/**
* The game panel
*
*/ public NoughtsAndCrossesButtonPanel() {
playButton=new JButton("Play");
playHandler=new ButtonPlayActionHandle();
playButton.addActionListener(playHandler);
exitButton =new JButton("Exit");
exitHandler=new ButtonExitActionHandler();
exitButton .addActionListener(exitHandler);
this.add(playButton);
this.add(exitButton);
}
}
}
class NoughtsAndCrossesGamePanel extends JPanel {
private int clickCount = 0;
private JButton[] btnKeypad = new JButton[9];
public NoughtsAndCrossesGamePanel() {
/**
* Resets the buttons and clicjCount ready for a new game
*/
HandlePlayerShot shotHandler = new HandlePlayerShot();
// Set some JFrame details
// NOTE - In grid layout you provide the number of
// rows and columns but columns are ignored and always set equal to rows
// unless the rows are zero.
//TODO
//this.setLayout(.....);
// Create the buttons and add them to the JFrame
for (int i = 0; i < 9; i++) {
btnKeypad[i] = new JButton(" ");
this.add(btnKeypad[i]);
btnKeypad[i].addActionListener(shotHandler);
//TODO
}
// Register the same listener for each button as the action needed is always the same.
// Note - this could have been done in the above loop but is shown separately here to make
// it clearer.
shotHandler = new HandlePlayerShot();
this.setSize(250, 250);
}
private void resetGame() {
/**
* Disables all the buttons when the game ends
*
*/
clickCount = 0;
for (int i = 0; i < 9; i++){
btnKeypad[i].setText("");
}
}
private void gameFinished() {
/**
* Inner class of NoughtsAndCrossesGamePanel to handle a players shot
* ie when a game button is pressed.
*/
}
class HandlePlayerShot implements ActionListener { //TODO implements ????
/**
* Inner class of NoughtsAndCrossesGameFrame to respond to the Exit Button being
* pressed. Dispose of the frame and exits the application
*/
@Override
/**
* Responds to the button press - ie player shot
*/
public void actionPerformed(ActionEvent e) {
JButton currentButton;
String winner;
clickCount++;
currentButton = (JButton) (e.getSource());
// If it is an odd click count (button press count) then it is "X"
// shot as "X" player always goes first
if (clickCount % 2 == 1) {
currentButton.setText("X");
} else {
currentButton.setText("0");
}
currentButton.setEnabled(false);
winner = checkForWinner();
if (winner != null) {
//Display a message showing who the winner is
//TODO
JOptionPane.showMessageDialog(null, "The winner is " + winner);
//NoughtsAndCrossesGamePanel.this.dispose();
} else {
// check that all possible shots have been had
if (clickCount == 9) {
//Display a message saying it is a drawn game
//TODO
JOptionPane.showMessageDialog(null, "Draw!");
//NoughtsAndCrossesGamePanel.this.dispose();
}
}
}
/**
* Checks if the button in btnKeypad array in positions i, j, k
* all have the same text.
* @param i - button number
* @param j - button number
* @param k - button number
* @return true if button i,j,k
*/
private boolean isAWinner(int i, int j, int k) {
return !btnKeypad[i].getText().equals(" ")
&& btnKeypad[i].getText().equals(btnKeypad[j].getText())
&& btnKeypad[i].getText().equals(btnKeypad[k].getText());
}
/**
* Checks for all possible winning scenarios
* @return null if there is no winner or the text on the button of the
* winner
*/
public String checkForWinner() {
/* Assumed mapping of button indexes to position in game is -
* 012
* 345
* 678
*/
int winner = -1; // -1 value means there was no winner
if (isAWinner(0, 1, 2)) {// Horizontal row 1
winner = 0;
} else if (isAWinner(3, 4, 5)) { // Horizontal row 2
winner = 3;
} else if (isAWinner(6, 7, 8)) { // Horizontal row 3
winner = 6;
} else if (isAWinner(0, 3, 6)) { // Vertical row 1
winner = 0;
} else if (isAWinner(1, 4, 7)) { // Vertical row 2
winner = 1;
} else if (isAWinner(2, 5, 8)) { // Vertical row 3
winner = 2;
} else if (isAWinner(0, 4, 8)) { // Diagonal 1
winner = 0;
} else if (isAWinner(2, 4, 6)) { // Diagonal 2
winner = 2;
}
if (winner != -1) {
return btnKeypad[winner].getText();
} else {
return null;
}
}
}
}
class ButtonExitActionHandler implements ActionListener {
/**
* Inner class of NoughtsAndCrossesGameFrame to respond to the Play Button being
* pressed. Asks the frame to reset the game by calling the frames resetGame
* method
*/
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
class ButtonPlayActionHandle implements ActionListener {
public void actionPerformed(ActionEvent e)
{
//resetGame();
}
}
View Answers
Related Tutorials/Questions & Answers:
Running problem with NoughtsAndCrossesGame in blankRunning problem with
NoughtsAndCrossesGame in blank Hi i was having
problem created
NoughtsAndCrossesGame in end the it works but i runs the gui in
blank. Its another way to solve it
/*
* To change this template, choose
problem running a servlet on tomcat.problem running a servlet on tomcat. i have followed the steps given... suppose that should mean that my tomcat server is up and
running.
but whn i try... be the
problem?
please help me out
Advertisements
PHP Prevent blank uploadPHP Prevent
blank upload In my small PHP application, i am posting a data to server using POST method in PHP, which is working fine. But the
problem is that it also accepts
blank data as well as duplicate value. Is there any way
UItextfield blankUItextfield blank Hi,
How I can check if UITextfield is
blank and then display error to the user?
ThanksADS_TO_REPLACE_1
Hi,
Following code can be used to validate the user input in iPhone and iPad applications
NoughtsAndCrossesGame play button doesn't work NoughtsAndCrossesGame play button doesn't work /*
* To change this template, choose Tools | Templates
* and open the template in the editor...
NoughtsAndCrossesGameFrame
noughtsAndCrossesGame;
noughtsAndCrossesGame = new
NoughtsAndCrossesGame play button doesn't work NoughtsAndCrossesGame play button doesn't work /*
* To change this template, choose Tools | Templates
* and open the template in the editor...
NoughtsAndCrossesGameFrame
noughtsAndCrossesGame;
noughtsAndCrossesGame = new
Struts2 blank application - StrutsStruts2
blank application Hi
I am new to struts2 and i am trying to run the strutsblank application by following the following Link;
http://www.roseindia.net/struts/struts2/index.shtml
As per the instructions given
Validaton(Checking Blank space) - SpringValidaton(Checking
Blank space) Hi i am using java springs .I am having
problem in doing validation.
I am just checking
blank space.
This is my controller. I named it salescontroller.
package controller;
import
Problem();
echoSocket.close();
}
}
this is my code,
compiled with no errors, but when
running giving... that the server (something like EchoServer) is up and
running.
Thanx i got the answer,
i just turned off the firewall & its
running fine
Problem with no errors, but when
running giving "java.net.connectexception connection...) is up and
running Running JUnitRunning JUnit Hi sir
How can we run JUnit or Run test case Using JUnit using command prompt or CMD?
Is there any alternate way of
running test cases?
ou can run JUnit test case by
running following command on CMD
Running JUnitRunning JUnit Hi sir
How can we run JUnit or Run test case Using JUnit using command prompt or CMD?
Is there any alternate way of
running test cases?
Hi friendADS_TO_REPLACE_1
You can run JUnit test case by
running MySQL Blank FieldMySQL
Blank Field
This example illustrates how to find
Blank field by the MySQL Query.
In the table 'example' two t_count fields are
blank and we find both field
which has some value by query 'select * from example where t_count
applet running but no display - Appletapplet
running but no display Hai,
Thanks for the post. I have applied the codebase url in the page and executed.
Now, when accessed the page from a client, the page appears with a
blank applet part (just whitescreen
Problem with loginbean.jspProblem with loginbean.jsp http://www.roseindia.net/jsp/loginbean.shtml
-
I am getting an error in loginbean.jsp.There... is login.java is accessed or executed while
running blank space in input field - Java Beginnersblank space in input field I retrieved the fields from my mysql table...If the field contains null value i want to display a
blank space in input field(text box)..but i am displaying null how to overcome this..
u r help
ModuleNotFoundError: No module named 'running'ModuleNotFoundError: No module named '
running' Hi,
My Python... '
running'
How to remove the ModuleNotFoundError: No module named '
running... to install padas library.
You can install
running python with following command
Running and deploying Tomcat ServerRunning and deploying Tomcat Server HI
Somebody has given the solution but it doesn't work out. kindly tell the solution for my
problem which i... the
problem to get the correct solution
Creating Blank DOM Document Creating
Blank DOM Document
This tutorial shows you how to create
blank DOM
document. JAXP... DocumentBuilder is
used to create a
blank document. The newDocument() method
About running the Tomcat Server About
running the Tomcat Server HI
I want to run a simple program on servlet and the application is a simple program Hello world... is not there
SO kindly tell me why it so happened and rectify the
problem to get
stop the running hidden serverstop the
running hidden server Port 8080 required by Tomcat v6.0 Server at localhost is already in use. The server may already be
running in another process, or a system process may be using the port. To start this server you
Running Java Applications as software Running Java Applications as software Please tell me what to do if you want your java application to run like a real software,eg a java GUI application that connects to the database(Mysql)
running on the computer like any other
Server running Button - Java BeginnersServer
running Button Hi there,
I have a created a GUI using NetBeans IDE 6.1. The aim of this interface is to display the messages that have....
The
problem is with the display , when I run the GUI and click on the play button
running java with classpath in cygwinrunning java with classpath in cygwin The following command works in cmd.exe but failts in cygwin shell.
java -cp .;oracle.jar;mysql.jar Executecmd query value;
how should i alter the command to run in the bash shell?thanks
Find the Running time in sql***Find the
Running time in sql*** I have 10 backend jobs in sql which...:00ADS_TO_REPLACE_1
I want to find the
running time of both the jobs. (i.e when i run the query it should show me how long job has been
running)
Eg:- Lets consider
program is not running in Eclipse.... - WebSevicesprogram is not
running in Eclipse.... Hi i following the tutorial for eclips in roseindia. I am able to creat the simple java application but when i am clicking windows->show view->console then i am getting the console
About running the Applet ProgramAbout
running the Applet Program Hi
I have composed an Applet Program and compiled the program, until that it is fine but how to run the Applet program(compiling i typed as javac AppletDemo.java)?
Is compiling
About running the Applet ProgramAbout
running the Applet Program Hi
I have composed an Applet Program and compiled the program, until that it is fine but how to run the Applet program(compiling i typed as javac AppletDemo.java)?
Is compiling
Running core java programRunning core java program I am jayesh raval. I am going to make simplae program and at the time of runnint that program I found class not found exception. I have clear source of that program and that is right in the syntax. so
While running jspWhile
running jsp I found this error when i run the client.jsp can anyone help me
javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://localhost:8080/WebService1/MyWebService?wsdl. It failed with: http
tomcat server problem placing a
problem with tomcat5.5 server.
when i am trying to execute my project I... login page of the project and when i entered the username and password the
blank page is appeared.
please resolve my
problem as soon as possible.
thanking you
Running threads in servlet only once - JSP-ServletRunning threads in servlet only once Hi All,
I am developing... process while mail thread is
running. these two separate threads has to run... them self immediately. how can resolve this
problem.
Thanks
app crashed in ipad 2 running iOS 5.0.1app crashed in ipad 2
running iOS 5.0.1 i developed a universal... in ipad 2
running iOS 5.0.1, witch is not in compliance with the App Store Review Guidelines."
Can anyone tell me how to solve this
problem?.. or do i need iPad
Error running webserviceError
running webservice Hi,
I am getting following error:
05/10 12:45:46 ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error