SEARCH YOUR SOLUTION HERE  

Dice Game

everyone. I'm a grad student in an accelerated Java class and so it is understandably a little bit hard for me. I've never used Java in my life. I'm using a custom textbook from my school that has all of the examples in the book as source code snippet on a CD. Unluckily I purchased a used book with out a CD so I'm stuck and I can't complete my Program. The difficulties are outlined given below:
Part 1:
* Write a Java class called Die (as in the singular of Dice) that represents one die with faces displaying values b/w 1 and 6. It should contain :
--one integer instance variable faceValue, that represents the current face value of the die, an integer constant (MAX) that represents the maximum face value of the die.
--a constructor
--and five regular methods: roll, setFaceValue, getFaceValue, toString and equals.

* The roll method should compute a random integer b/w 1 and 6 and set the current face value with that as a way of simulating the rolling of the die. (What Java class and method would u use to receive a random integer find out..)
* Now, write a driver (i.e., program used for testing) called RollingDice, in order to test ur Die class.
Part 2:
* Using the Die class, design and implement a class called PairOfDice, composed of two Die Objects. Include methods to set and receive the individual die values, toString and equals methods, a method to roll the dice (call it roll), and a method that returns the current sum of the two die values (call it getDiceSum).
Part: 3
Decently using ur PairOfDice class, write a Java program (a driver with a main function), called DiceGame.java, that allows the user to play the a game with the computer. Here are the rules of the game: A player rolls the dice repeatedly until she rolls at least one 1 or voluntarily gives up the dice. Each time she rolls the dice the total on the faces of the dice is added to her score, except when she rolls a 1. If she rolls one 1, she loses all the points she's accumulated so far in her turn. If she rolls two 1's, she loses all of her points so far in the game. (This means you've to keep track of points in each turn and points since the beginning of the game). The first player to receive a total of 100 wins. The computer follows the same rules, except that it turns over the dice as soon as its score for the current turn is at least 20.
Here's an extract from a working Program.
Welcome to the DiceGame. It is you against the computer.
You play by rolling the dice. The first player
to receive 100 points wins. However, if you roll one 1
you lose all the points you have accumulated in ur
turn. If you roll two 1's, you lose all ur
points. You can turn the dice over at any time.
However, if you roll one or two 1's, you lose ur
turn. I (the computer) play by the same rules,
except I will always turn over the dice when I have
rolled 20 or more points in one turn.
Ready to begin (Type 'y' when you are ready)
y

You are rolling the dice . . .
You rolled 2 4
This gives you a turn total of
6
and a grand total of
6
The computer has a total of
0
Do you need to continue rolling (Type 'y' or 'n')
y

You are rolling the dice . . .
You rolled 3 3
This gives you a turn total of
12
and a grand total of
12
The computer has a total of
0
Do you need to continue rolling (Type 'y' or 'n')
y

You are rolling the dice . . .
You rolled 1 3
You got a 1
Continue (Type 'y' when you are ready to
turn the dice over to me)
y
The score is
You: 0
Computer: 0

I'm rolling the dice . . .
I rolled 1 4
I got a 1
Continue (Type 'y' when you are ready)
y
The score is
You: 0
Computer: 0

You are rolling the dice . . .
You rolled 5 5
This gives you a turn total of
10
and a grand total of
10
The computer has a total of
0
Do you need to continue rolling (Type 'y' or 'n')
n

I'm rolling the dice . . .
I rolled 1 1
I got two 1's
Continue (Type 'y' when you are ready)
y
The score is
You: 10
Computer: 0

[Many turns erased . . .]

You are rolling the dice . . .
You rolled 1 6
You got a 1
Continue (Type 'y' when you are ready to
turn the dice over to me)
y
The score is
You: 0
Computer: 93

I'm rolling the dice . . .
I rolled 5 4
This gives me a turn total of
9
and a grand total of
102
The score is
You: 0
Computer: 102

Improve luck next time
I have attempted to do the part 3 of the program but I'm still have difficulties. For some reason the output always gives the user a 1 and ends the turn and the same goes for the computer. So apparently I'm not calling a method decently or some thing. Given below is code for all of the classes and the last one is the game itself. Be forewarned that it is very lengthy (in my opinion) and apologize in advance but I guess I'm very close and just wana finish this thing.import java.util.Random;
public class Die
{
private int faceValue;
private final int MAX=6;

public Die()
{
faceValue = 1;
}

Math.random generates random integers from 1 - 6
public void roll()
{
faceValue = (int)(Math.random() * MAX) +1;
}

Sets the face value
public void setFaceValue(int value)
{
faceValue=value;
}

Gets the face value using the setFaceValue method
public int getFaceValue()
{
return faceValue;
}

Converts values into a String
public String toString()
{
String result = "You rolled a " + faceValue;
return result;
}

} end class Diepublic class RollingDice
{
------------------------------------------------------
Generates two Die Objects and rolls them many times
------------------------------------------------------
public static void main (String[] args )
{
Die d1, d2 ;
int sum ;
Generates two Die Objects
d1 = new Die() ;
d2 = new Die() ;
d1.roll() ;
d2.roll() ;
System.out.println ( " Die One: " + d1 + " , Die Two: " + d2 ) ;
sum = d1.getFaceValue() + d2.getFaceValue();
System.out.println ( " Sum: " + sum ) ;
} end main
} end class RollingDicepublic class PairOfDice
{
private Die d1, d2;
private int value1, value2, total;
-----------------------------------------------------------------
Generates two six-sided Die Objects, both with an initial
face value of one.
-----------------------------------------------------------------
public PairOfDice ()
{
d1 = new Die();
d2 = new Die();
value1 = 1;
value2 = 1;
total = value1 + value2;
}
-----------------------------------------------------------------
Rolls both dice and returns the combined result.
-----------------------------------------------------------------
public void roll ()
{
d1.roll();
d2.roll();
}
-----------------------------------------------------------------
Returns the current combined dice total.
-----------------------------------------------------------------
public int getDiceSum ()
{
total = getDie1() + getDie2();
return total;
}
-----------------------------------------------------------------
Returns the current value of the first die.
-----------------------------------------------------------------
public int getDie1 ()
{
return value1;
}
-----------------------------------------------------------------
Returns the current value of the second die.
-----------------------------------------------------------------
public int getDie2 ()
{
return value2;
}
-----------------------------------------------------------------
Sets the FaceValue of the first die.
-----------------------------------------------------------------
public void setDie1 (int value)
{
d1.setFaceValue(value);
}
-----------------------------------------------------------------
Sets the FaceValue of the second die.
-----------------------------------------------------------------
public void setDie2(int value)
{
d2.setFaceValue(value);
}
-----------------------------------------------------------------
Sets the FaceValue of the second die.
-----------------------------------------------------------------
public String toString()
{
String result = "You rolled a " + total;
return result;
}
}import java.util.Scanner;
public class DiceGame
{
public static void main( String [] args )
{
Rules of the Game
System.out.println("______________________________________");
System.out.println(" Rules of the Game ");
System.out.println(" ----------------- ");
System.out.println(" 1)It is you vs computer. ");
System.out.println(" 2)You play by rolling the dice. ");
System.out.println(" 3)The first player to reach 100 ");
System.out.println(" points wins. ");
System.out.println(" 4)When a player rolls a 1 ");
System.out.println(" the turn is over. ");
System.out.println(" 5)The computer's turn is over ");
System.out.println(" when turn total reach 20 points ");
System.out.println(" in one turn. ");
System.out.println("______________________________________");
PairOfDice d1 = new PairOfDice(); Generating PairOfDice Object
int turnTotal = 0;
int computerTotal = 0; ur total
int playerTotal = 0; computer's total
int turnOver = 1; when to provide up die
int winner = 100; amount to be reached before winning
Scanner in = new Scanner( System.in );
String answer; named of what will take answer from user
first do-while loop is for repeating the alter b/w user and computer
do{
if (playerTotal = winner)
System.out.println("You win ");
else
System.out.println("You lose ): ");
}
}Also, it is significant to note that I'm not getting any compiler bugs from any of the softwares just the hiccup from the game itself. If there are any cosmetic issues pls let me know so that I can do improve next time.
Posted On: Thursday, November 29, 2012 Total Views: 4
View Complete with Replies




Related Messages:

Some questions about developing a multiplayer game  (3 Views)
Guys
This is my first post on the forum. I am uncertain if it belongs under "Game Development" or in "Java". Since, it is a game that's being written in Java.
I'm not looking for anybody to write any code snippet for me, I just want somebody to point me in the right direction.
I've been googling for the last couple of days but it is really not as efficient as getting some advice to my particular situation.
The game I'm creating is a card game, not in the sense of a standard deck of cards (ace, queen, king, jack...etc.) but a card game that in a sense is identical to Magic the gathering.
When I say identical to magic I mean in the sense that each card played has a set of effects that resolve upon playing it that can either affect a players score or
other players hands.
I think I've a grasp on how the mechanics will work (library shuffling, drawing hands, playing cards and resolving effects, win states, etc.)
My difficulty is more or less directed in how can i put a GUI around this thing. I've never really built anything that had a GUI and I'm uncertain what libraries I should be using.
Secondly, (this may effect the answer to the question I just asked) the game is intended to be played with two or more human players on different machines. Either by an executable or by an imbedded applet (the latter would be my preferred method as I would rather not have to distribute executables).
This is not intended to be anything of professional caliber, I was just hoping to share it with many friends.
For the time being I'm going to focus on a GUI that I can use for testing and leave the multiplayer aspect for a later date once I've some thing up and executing.
I'm not intending on having the software create the cards from scratch, I would rather include a set of images to be used as the cards faces. Will this dramatically effect the way the software should be implemented I'm thinking comprising a set of 27 images (with the prospect of that growing by another 70-80 images in later iterations) will bring the size of the software up considerably.
Anywho, any guidance that u can provide me on where to start would be extremely comprehended. If I could receive some tips on libraries I should be using I can maybe find some examples on the web on my own.
If anybody requires any clarification pls shoot me some questions and I will do my best to clarify.
View Replies !
TicTacToe game in Java  (1 Views)

I've tried set of things, nothing is working feels like world is falling apart.
I just want a introductory tic tac toe game working in java.
I've tried this http: pctechtips.org tictactoe-game-java-code
import java.util.*;
public class Tictactoe {
private static final int ROWS = 3;
private static final int COLUMNS = 3;
private String[][] board;
construct an empty board
public Tictactoe()
{
board = new String[ROWS][COLUMNS];
Fill with spaces
for(int i = 0; i
I saved it as t.java and receive this
I tried to remove "public" it compiles but at the execution it says.
QuoteCould not find or load main class t
View Replies !
wana help with class diagram for game  (1 Views)
so fundamentally I've to make up a class program diagram for the game Cranium. It includes different different elements, and so far I have come up with 7 classes in relation to it, but I am uncertain what data types are applicable to them or what methods to apply to them. A introductory understanding of thie game is needed to answer this question.
View Replies !
Java Pong game - trouble with ball image  (1 Views)
everyone
I have a difficulty inserting an image in the spot where my ball is suppose to be in my pong game. I when I load up the image and put it in it is spot the ball dissaperas. I will post 2 codes bellow, first 1 will be the model that works (created using some built in mechanisms) and the other will be the piece of the code snippet where I tried to insert the image. I am hoping that u can tell me what I did wrong.
The ordinary fill model :
public void paintComponent(Graphics gc) {
setOpaque(false);
super.paintComponent(gc);
gc.setColor(new Color(255, 215, 0));
gc.fillOval(ballX, ballY, 12, 12);
My solution of how the model implementation should work :public void paintComponent(Graphics gc) {
setOpaque(false);
super.paintComponent(gc);
image ballimage = Toolkit.getDefaultToolkit().getimage(
" icons ballimage.png");
gc.drawimage (ballimage , 12 , 12 , this);When I use the second code snippet, the ball dissapears but the game still counts score. I am hoping somebody can assist me clear this out.
Thank u all in advance,cheers
This post has been updated by Maverick89: 07 November 2010 - 07:50 AM
View Replies !
poker game in java  (3 Views)
I have copy pasted the code snippet from this tutorial here and I am attempting to execute it but it displays me that error message.. I am pretty new in java eclipse and i started to learning before 1 week because of my college
if anybody can guide me what is neccessery to make this poker game to work or to provide me many tips i will applaud it
Cheers
best
View Replies !
dice collection array that holds Objects  (2 Views)
I am some having difficulties but firstly I define what program does: the class define collection of single die Objects.
Attributes= field with # of dice in collection, array holding the single die Objects.
Methods = alter # sides on die, show # sides on any single die, roll all dice and add, show total # dice
constructor 1 = array of values for # of sides on each dice.
constructor 2= parameters dice and sidesNumber
Test by rolling 2 four sided dice 10 time and receive mean.
My difficulty is that output I receive 0 every single time, but I wanted to print a mean when dice roll 10 times. import java.util.*; public class Game
{
private int diceSide;
private int numDice;
private int [] Die;
private Random random;

public Game()
{
diceSide=6;
numDice= 1;
random = new Random();
}
public Game(int side)
{
diceSide= side;
random = new Random();
}
public Die(int [] Die)
{
this.Die= Die;
}
public Game(int one, int two)
{
one = numDice;
two = diceSide;
}
public int getDiceSide()
{
return diceSide;
}
public int getNumDice()
{
return numDice;
}
public int rollDice()
{
int sum = 0;
for (int i = 1; i
This post has been updated by Codemonkey123: 16 July 2011 - 12:49 PM
View Replies !
I wana your help guys on My game.  (4 Views)
Guys I've started developing my game and i want some few helps from u.
The game is some kind of scattered English Language vocabulary that want to be rearrange. i wanted to make it a Multi-player so i generated a server to be checking the players.
My request for assist are these.
1. I want the game to be selecting the words automatically in both single player and Multi-player mode.
2. I want the game to be played in sections, like 3 words per segment and when its exactly 3 words, the game should record 1 game played. So the player that got the three words correctly will be given 1 as his or her score and another section start.
3. I want the game to be played 5 levels before choosing the overall winner(The player that score highest point in out of the 5 levels (3games per 1 level).
4. I want the game to regulate the time. when It's exactly 10 seconds all player should be block from answering the question and the winner will be chosen for the 1st level of the game.
5. I've generated the server to display the list of all the players that join the game by displaying their IP address. At the client side i want each player be able to view the number of clients in the game but not more than 5. So i want the server to send the number of client connected to play the game and be appended into the "No. of Players" Textfield on the client interface.
6. I want the game to be picking the scattered words randomly not from the top to bottom.
I want ur assist on this.
This is the Server Code snippet *
* To alter this template, select Tools | Templates
* and open the template in the editor.
*
*
* MusicServer.java
*
* Generated on Feb 8, 2011, 3:53:13 PM
*
package anagrams;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashSet;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;
**
*
* @author hans
*
public class AnagramServer extends javax.swing.JFrame {
** Generates new form MusicServer *
public AnagramServer() {
initComponents();
}
** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code snippet. The content of this method is
* always regenerated by the Form Editor.
*
@SuppressWarnings("unchecked")
GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
clientTable = new javax.swing.JTable();
startServerButton = new javax.swing.JButton();
statusLabel = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
clientTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"client List"
}
) {
Class[] types = new Class [] {
java.lang.String.class
};
boolean[] canEdit = new boolean [] {
false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(clientTable);
clientTable.getColumnModel().getColumn(0).setResizable(false);
startServerButton.setText("Start Server");
startServerButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
startServerButtonActionPerformed(evt);
}
});
statusLabel.setText("not started");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.CreateSequentialGroup()
.addContainerGap()
.addGroup(layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.CreateSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 112, Short.MAX_VALUE)
.addComponent(startServerButton))
.addComponent(statusLabel))
.addContainerGap())
);
layout.setVerticalGroup(
layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.CreateSequentialGroup()
.addContainerGap()
.addGroup(layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(startServerButton)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(statusLabel)
.addContainerGap())
);
pack();
} GEN-END:initComponents
private class ReceiverClass implements Runnable {
protected Socket receiveSocket = null;
private InputStream inStream = null;
private ObjectInputStream ObjectInStream = null;
private OutputStream outStream;
boolean executing = true;
public void Run() {
try {
inStream = receiveSocket.getInputStream();
convert the Input stream to an ObjectInputStream
ObjectInStream = new ObjectInputStream(inStream);
}
catch (IOException ex) {
Logger.getLogger(AnagramServer.class.getName()).log(Level.SEVERE, null, ex);
running = false;
stopReceiving();
}

while (running) {
AnagramMessage newMessage = null;
try {
newMessage = (AnagramMessage) ObjectInStream.readObject();
}
catch (IOException ex) {
running = false;
stopReceiving();
Logger.getLogger(AnagramServer.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(AnagramServer.class.getName()).log(Level.SEVERE, null, ex);
}

handle the message we just received
if (newMessage.type == MessageType.DISCONNECT) {
stopReceiving();
}
}
}
close the socket and remove this Object from the list of clients
public void stopReceiving() {
running = false;
try {
clientReceiverObjects.remove(this);
ObjectInStream.close();
inStream.close();
receiveSocket.close();
updateclientsTable();
} catch (IOException ex) {
Logger.getLogger(AnagramServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void playerTurn(){
}
}
this function checks the list of clients and puts their ip addresses in the table
in our GUI
public void updateclientsTable() {
an iterator helps us to find all the Objects in a collection
http: download.orac...l Iterator.html
Iterator it = clientReceiverObjects.iterator();
int numclients = clientReceiverObjects.size();
String[][] clientIPAddresses = new String[numclients][1];
String[] tableColumnTitle = {"client List"};
int clientIndex = 0;
while (it.hasNext()) {
ReceiverClass nextReceiverObject = ((ReceiverClass) it.next());
InetAddress nextReceiverIPAddress = nextReceiverObject.receiveSocket.getInetAddress();
clientIPAddresses[clientIndex++][0] = nextReceiverIPAddress.toString();
}
DefaultTableModel newTableModel = new DefaultTableModel(clientIPAddresses, tableColumnTitle);
clientTable.setModel(newTableModel);
if (numclients > 0) {
statusLabel.setText("clients connected");
} else {
statusLabel.setText("no clients connected");
}
}
this thread loops infinitely, accepting connections from every client and adding
their sockets to the collection.
private class ConnectionAcceptorClass implements Runnable {
public void Run() {
while (true) {
Generate a ReceiverThread Object to manage a connection to a new client
ReceiverClass newclientGetObject = new ReceiverClass();
try {
newclientGetObject.receiveSocket = waitForConnectionSocket.accept();
} catch (IOException ex) {
Logger.getLogger(AnagramServer.class.getName()).log(Level.SEVERE, null, ex);
}
add the new ReceiverObject to our collection of ReceiverObjects
if (newclientGetObject.receiveSocket = null) {
Thread newclientReceiveThread = new Thread(newclientGetObject);
newclientReceiveThread.start();
clientReceiverObjects.add(newclientGetObject);
updateclientsTable();
}
}
}
}
ServerSocket waitForConnectionSocket;
Here we make a collection of sockets. We use GENERICS to force the collection to accept
only Objects of type Socket. http: download.orac...e generics.html
HashSet clientReceiverObjects = new HashSet();
private void startServerButtonActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_startServerButtonActionPerformed
try {
waitForConnectionSocket = new ServerSocket(4445);
ConnectionAcceptorClass connectionAcceptorObject = new ConnectionAcceptorClass();
Thread connectionAcceptorThread = new Thread(connectionAcceptorObject);
connectionAcceptorThread.start();
statusLabel.setText("Waiting for client");
} catch (IOException ex) {
Logger.getLogger(AnagramServer.class.getName()).log(Level.SEVERE, null, ex);
}
} GEN-LAST:event_startServerButtonActionPerformed
**
* @param args the command line arguments
*
public static void main(String args[]) {

try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
Logger.getLogger(AnagramServer.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(AnagramServer.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(AnagramServer.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(AnagramServer.class.getName()).log(Level.SEVERE, null, ex);
}

java.awt.EventQueue.invokeLater(new Runnable() {
public void Run() {
new AnagramServer().setVisible(true);
}
});
}
Variables declaration - do not modify GEN-BEGIN:variables
private javax.swing.JTable clientTable;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton startServerButton;
private javax.swing.JLabel statusLabel;
End of variables declaration GEN-END:variables
} for the client
* Anagram Game Software *
package anagrams;
import anagrams.WordLibrary;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.WindowListener;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
**
* Main window of the Anagram Game software.
*
public class Anagrams extends JFrame {
private int wordIdx = 0;
Socket sendSocket;
OutputStream outputStream = null;
ObjectOutputStream anagramMessageOutputStream = null;
public static void main(String[] args) throws UnsupportedLookAndFeelException {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
Logger.getLogger(Anagrams.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(Anagrams.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(Anagrams.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(Anagrams.class.getName()).log(Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void Run() {
new Anagrams().setVisible(true);
}
});
}
** Generates new form Anagrams *
public Anagrams() {
initComponents();
getRootPane().setDefaultButton(guessButton);
scrambledWord.setText(WordLibrary.getScrambledWord(wordIdx));
pack();
guessedWord.requestFocusInWindow();
Center in the screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
setLocation(new Point((screenSize.width - frameSize.width) 2,
(screenSize.height - frameSize.width) 2));
}
** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*
GEN-BEGIN:initComponents
private void initComponents() {
closeDialog = new javax.swing.JDialog();
jLabel2 = new javax.swing.JLabel();
yesButton = new javax.swing.JButton();
noButton = new javax.swing.JButton();
disconnectDialog = new javax.swing.JDialog();
jLabel6 = new javax.swing.JLabel();
yesDisButton = new javax.swing.JButton();
noDisButton = new javax.swing.JButton();
serverIPDialog = new javax.swing.JDialog();
ipByte2 = new javax.swing.JTextField();
ipByte4 = new javax.swing.JTextField();
ipOKbutton = new javax.swing.JButton();
ipByte3 = new javax.swing.JTextField();
ipAddressStatusLabel = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
ipByte1 = new javax.swing.JTextField();
jLabel10 = new javax.swing.JLabel();
mainPanel = new javax.swing.JPanel();
scrambledLabel = new javax.swing.JLabel();
scrambledWord = new javax.swing.JTextField();
guessLabel = new javax.swing.JLabel();
guessedWord = new javax.swing.JTextField();
feedbackLabel = new javax.swing.JLabel();
buttonsPanel = new javax.swing.JPanel();
guessButton = new javax.swing.JButton();
nextTrial = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
statusLabel = new javax.swing.JLabel();
connectButton = new javax.swing.JButton();
yourScore = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
noOfGame = new javax.swing.JTextField();
disconnectButton = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
noOfPlayers = new javax.swing.JTextField();
mainMenu = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
aboutMenuitem = new javax.swing.JMenuitem();
EXITMenuitem = new javax.swing.JMenuitem();
gameMode = new javax.swing.JMenu();
singlePlayer = new javax.swing.JMenuitem();
multiPlayer = new javax.swing.JMenuitem();
closeDialog.setTitle("Closing game");
closeDialog.setBounds(new java.awt.Rectangle(0, 0, 0, 0));
closeDialog.setLocationByPlatform(true);
closeDialog.setResizable(false);
jLabel2.setText("Are you sure you need to close this game");
yesButton.setText("Yes");
yesButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
yesButtonActionPerformed(evt);
}
});
noButton.setText("No");
noButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
noButtonActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout closeDialogLayout = new org.jdesktop.layout.GroupLayout(closeDialog.getContentPane());
closeDialog.getContentPane().setLayout(closeDialogLayout);
closeDialogLayout.setHorizontalGroup(
closeDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(closeDialogLayout.CreateSequentialGroup()
.add(closeDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(closeDialogLayout.CreateSequentialGroup()
.add(18, 18, 18)
.add(jLabel2))
.add(closeDialogLayout.CreateSequentialGroup()
.add(60, 60, 60)
.add(yesButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(noButton)))
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
closeDialogLayout.setVerticalGroup(
closeDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(closeDialogLayout.CreateSequentialGroup()
.add(29, 29, 29)
.add(jLabel2)
.add(18, 18, 18)
.add(closeDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(yesButton)
.add(noButton))
.addContainerGap(27, Short.MAX_VALUE))
);
disconnectDialog.setTitle("Disconnecting from server");
jLabel6.setText("Are you sure you need to close this game");
yesDisButton.setText("Ok");
yesDisButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
yesDisButtonActionPerformed(evt);
}
});
noDisButton.setText("Cancel");
noDisButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
noDisButtonActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout disconnectDialogLayout = new org.jdesktop.layout.GroupLayout(disconnectDialog.getContentPane());
disconnectDialog.getContentPane().setLayout(disconnectDialogLayout);
disconnectDialogLayout.setHorizontalGroup(
disconnectDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(disconnectDialogLayout.CreateSequentialGroup()
.add(disconnectDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(disconnectDialogLayout.CreateSequentialGroup()
.add(18, 18, 18)
.add(jLabel6))
.add(disconnectDialogLayout.CreateSequentialGroup()
.add(67, 67, 67)
.add(yesDisButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(noDisButton)))
.addContainerGap(18, Short.MAX_VALUE))
);
disconnectDialogLayout.setVerticalGroup(
disconnectDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(disconnectDialogLayout.CreateSequentialGroup()
.add(29, 29, 29)
.add(jLabel6)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 18, Short.MAX_VALUE)
.add(disconnectDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(yesDisButton)
.add(noDisButton))
.addContainerGap())
);
serverIPDialog.setTitle("Connecting to the server");
serverIPDialog.setModal(true);
serverIPDialog.setModalExclusionType(java.awt.Dialog.ModalExclusionType.Application_EXCLUDE);
serverIPDialog.setResizable(false);
ipByte2.setText("0");
ipByte4.setText("1");
ipOKbutton.setText("OK");
ipOKbutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ipOKbuttonActionPerformed(evt);
}
});
ipByte3.setText("0");
ipAddressStatusLabel.setText("Enter the IP address of the Server.");
jLabel7.setText(".");
jLabel8.setText(".");
jLabel9.setText(".");
ipByte1.setText("127");
jLabel10.setText("Server IP Address:");
org.jdesktop.layout.GroupLayout serverIPDialogLayout = new org.jdesktop.layout.GroupLayout(serverIPDialog.getContentPane());
serverIPDialog.getContentPane().setLayout(serverIPDialogLayout);
serverIPDialogLayout.setHorizontalGroup(
serverIPDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 254, Short.MAX_VALUE)
.add(serverIPDialogLayout.CreateSequentialGroup()
.addContainerGap()
.add(serverIPDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel10)
.add(serverIPDialogLayout.CreateSequentialGroup()
.add(10, 10, 10)
.add(serverIPDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(ipAddressStatusLabel)
.add(serverIPDialogLayout.CreateSequentialGroup()
.add(ipByte1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 33, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel9)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(ipByte2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel8)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(ipByte3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 33, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel7)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(ipByte4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 33, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(ipOKbutton)))))
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
serverIPDialogLayout.setVerticalGroup(
serverIPDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 85, Short.MAX_VALUE)
.add(serverIPDialogLayout.CreateSequentialGroup()
.addContainerGap()
.add(jLabel10)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(serverIPDialogLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(ipByte1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel9)
.add(ipByte2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel8)
.add(jLabel7)
.add(ipByte3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(ipByte4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(ipOKbutton))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(ipAddressStatusLabel)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setTitle("Anagrams");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
EXITForm(evt);
}
});
mainPanel.setBorder(javax.swing.BorderFactory.CreateEmptyBorder(12, 12, 12, 12));
mainPanel.setMinimumSize(new java.awt.Dimension(297, 200));
scrambledLabel.setText("Scrambled Word:");
scrambledWord.setColumns(20);
scrambledWord.setEditable(false);
scrambledWord.setEnabled(false);
guessLabel.setDisplayedMnemonic('Y');
guessLabel.setLabelFor(guessedWord);
guessLabel.setText("Your Guess:");
guessedWord.setColumns(20);
guessedWord.setEnabled(false);
guessButton.setMnemonic('G');
guessButton.setText("Guess");
guessButton.setToolTipText("Guess the scrambled word.");
guessButton.setEnabled(false);
guessButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
guessedWordActionPerformed(evt);
}
});
nextTrial.setMnemonic('N');
nextTrial.setText("New Word");
nextTrial.setToolTipText("fetch a new word.");
nextTrial.setEnabled(false);
nextTrial.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextTrialActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout buttonsPanelLayout = new org.jdesktop.layout.GroupLayout(buttonsPanel);
buttonsPanel.setLayout(buttonsPanelLayout);
buttonsPanelLayout.setHorizontalGroup(
buttonsPanelLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, buttonsPanelLayout.CreateSequentialGroup()
.addContainerGap(26, Short.MAX_VALUE)
.add(guessButton)
.add(6, 6, 6)
.add(nextTrial)
.add(19, 19, 19))
);
buttonsPanelLayout.setVerticalGroup(
buttonsPanelLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, buttonsPanelLayout.CreateSequentialGroup()
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(buttonsPanelLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(guessButton)
.add(nextTrial))
.addContainerGap())
);
org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.CreateSequentialGroup()
.addContainerGap()
.add(mainPanelLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(mainPanelLayout.CreateSequentialGroup()
.add(guessLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 82, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(6, 6, 6)
.add(guessedWord))
.add(org.jdesktop.layout.GroupLayout.LEADING, mainPanelLayout.CreateSequentialGroup()
.add(scrambledLabel)
.add(6, 6, 6)
.add(scrambledWord, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 195, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(mainPanelLayout.CreateSequentialGroup()
.add(88, 88, 88)
.add(buttonsPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(feedbackLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 467, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.CreateSequentialGroup()
.add(72, 72, 72)
.add(feedbackLabel))
.add(mainPanelLayout.CreateSequentialGroup()
.addContainerGap()
.add(mainPanelLayout.CreateParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.CreateSequentialGroup()
.add(3, 3, 3)
.add(scrambledLabel))
.add(scrambledWord, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.add(15, 15, 15)
.add(guessLabel))
.add(mainPanelLayout.createSequentialGroup()
.add(12, 12, 12)
.add(guessedWord, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(26, 26, 26)
.add(buttonsPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
);
statusLabel.setText("Not connected");
statusLabel.setEnabled(false);
connectButton.setText("Connect");
connectButton.setEnabled(false);
connectButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
connectButtonActionPerformed(evt);
}
});
yourScore.setEditable(false);
yourScore.setText("0");
yourScore.setEnabled(false);
jLabel3.setText("No. of wins");
jLabel4.setText("No. of game played");
noOfGame.setEditable(false);
noOfGame.setText("0");
noOfGame.setEnabled(false);
disconnectButton.setText("Disconnect");
disconnectButton.setEnabled(false);
disconnectButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
disconnectButtonActionPerformed(evt);
}
});
jLabel1.setText("No. of current players");
noOfPlayers.setEditable(false);
noOfPlayers.setText("0");
noOfPlayers.setEnabled(false);
org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(noOfPlayers, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 62, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel1))
.addContainerGap(12, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(34, Short.MAX_VALUE)
.add(noOfPlayers, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(jLabel1)
.add(21, 21, 21))
);
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(statusLabel)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
.add(connectButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(disconnectButton)
.add(20, 20, 20)))
.add(jLabel3)
.add(yourScore, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 62, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel4)
.add(noOfGame, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 59, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(21, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(91, Short.MAX_VALUE)
.add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(statusLabel)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(yourScore, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(11, 11, 11)
.add(jLabel3)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 27, Short.MAX_VALUE)
.add(noOfGame, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel4)
.add(18, 18, 18)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(disconnectButton)
.add(connectButton))
.addContainerGap())
);
fileMenu.setMnemonic('F');
fileMenu.setText("File");
aboutMenuitem.setMnemonic('A');
aboutMenuitem.setText("About");
aboutMenuitem.setToolTipText("About");
aboutMenuitem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aboutMenuitemActionPerformed(evt);
}
});
fileMenu.add(aboutMenuitem);
EXITMenuitem.setMnemonic('E');
EXITMenuitem.setText("EXIT");
EXITMenuitem.setToolTipText("Quit Team, Quit ");
EXITMenuitem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EXITMenuitemActionPerformed(evt);
}
});
fileMenu.add(EXITMenuitem);
mainMenu.add(fileMenu);
gameMode.setText("Game Mode");
singlePlayer.setMnemonic('S');
singlePlayer.setText("Single Player");
singlePlayer.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
singlePlayerActionPerformed(evt);
}
});
gameMode.add(singlePlayer);
multiPlayer.setMnemonic('M');
multiPlayer.setText("Multi Player");
multiPlayer.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
multiPlayerActionPerformed(evt);
}
});
gameMode.add(multiPlayer);
mainMenu.add(gameMode);
setJMenuBar(mainMenu);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(mainPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 309, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanel, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
} GEN-END:initComponents
private void aboutMenuitemActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_aboutMenuitemActionPerformed
new About(this).setVisible(true);
} GEN-LAST:event_aboutMenuitemActionPerformed
public void newWord() {
wordIdx = (wordIdx + 1) WordLibrary.getSize();
feedbackLabel.setText(" ");
scrambledWord.setText(WordLibrary.getScrambledWord(wordIdx));
guessedWord.setEditable(true);
guessedWord.setText("");
getRootPane().setDefaultButton(guessButton);
guessedWord.requestFocusInWindow();
}
private void nextTrialActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_nextTrialActionPerformed
newWord();
} GEN-LAST:event_nextTrialActionPerformed
private void EXITMenuitemActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_EXITMenuitemActionPerformed
System.EXIT(0);
} GEN-LAST:event_EXITMenuitemActionPerformed
boolean correct = false;
int scores = 0;
private void guessedWordActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_guessedWordActionPerformed
guessWord();
} GEN-LAST:event_guessedWordActionPerformed
public void guessWord() {
if (WordLibrary.isCorrect(wordIdx, guessedWord.getText())) {
correct = true;
feedbackLabel.setText("Correct Try a new word ");
guessedWord.setEditable(false);
getRootPane().setDefaultButton(nextTrial);
if (correct) {
scores++;
String playerScores = String.valueOf(scores);
yourScore.setText(playerScores);
}
} else {
feedbackLabel.setText("Incorrect Try again ");
guessedWord.setEditable(false);
guessedWord.setText("");
}
guessedWord.requestFocusInWindow();
}private class SenderClass implements Runnable {
private AnagramMessage message; this variable is used only once and it will not alter after it has been set.
public SenderClass(AnagramMessage message) { constructor
this.message = message; copy the input to the message variable in this Object
}
public void Run() {
if (anagramMessageOutputStream = null) {
try {
anagramMessageOutputStream.writeObject(message);
} catch (IOException ex) {
Logger.getLogger(Anagrams.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
private void EXITForm(java.awt.event.WindowEvent evt) { GEN-FIRST:event_EXITForm
closeDialog.pack();
closeDialog.setVisible(true);
Center in the screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
setLocation(new Point((screenSize.width - frameSize.width) 2,
(screenSize.height - frameSize.width) 2));
} GEN-LAST:event_EXITForm
private void disconnect() {
try {
AnagramMessage gameMessage = new AnagramMessage(MessageType.DISCONNECT);
SenderClass senderObject = new SenderClass(gameMessage);
Thread senderThread = new Thread(senderObject);
sendSocket.setSoTimeout(50); we set a timeout because we do not want the socket to
senderThread.start();
sendSocket.close();
} catch (IOException ex) {
Logger.getLogger(Anagrams.class.getName()).log(Level.SEVERE, null, ex);
}
}
InetAddress serverIPAddress = null;
private void yesButtonActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_yesButtonActionPerformed
System.EXIT(0);
} GEN-LAST:event_yesButtonActionPerformed
private void noButtonActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_noButtonActionPerformed
TODO add your handling code here:
closeDialog.setVisible(false);
} GEN-LAST:event_noButtonActionPerformed
private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_connectButtonActionPerformed
serverIPDialog.pack();
serverIPDialog.setVisible(true);
try {
sendSocket = new Socket(serverIPAddress, 4445);
outputStream = sendSocket.getOutputStream();
anagramMessageOutputStream = new ObjectOutputStream(outputStream); use the regular outputStream to generate an musicMessageOutputStream
statusLabel.setEnabled(true);
statusLabel.setText("Connected to Server");
scrambledWord.setEnabled(true);
guessedWord.setEnabled(true);
guessedWord.setEditable(true);
guessButton.setEnabled(true);
nextTrial.setEnabled(true);
yourScore.setEnabled(true);
noOfGame.setEnabled(true);
noOfPlayers.setEnabled(true);
disconnectButton.setEnabled(true);
connectButton.setEnabled(false);
repaint();
} catch (IOException ex) {
Logger.getLogger(Anagrams.class.getName()).log(Level.SEVERE, null, ex);
}
} GEN-LAST:event_connectButtonActionPerformed
private void yesDisButtonActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_yesDisButtonActionPerformed
if (sendSocket = null) {
if (anagramMessageOutputStream = null) {
disconnect();
}
}
disconnectDialog.setVisible(false);
statusLabel.setEnabled(false);
statusLabel.setText("Disconnected from server");
scrambledWord.setEnabled(false);
guessedWord.setEnabled(false);
guessedWord.setEditable(false);
guessButton.setEnabled(false);
nextTrial.setEnabled(false);
yourScore.setEnabled(false);
noOfGame.setEnabled(false);
noOfPlayers.setEnabled(false);
disconnectButton.setEnabled(false);
connectButton.setEnabled(true);
} GEN-LAST:event_yesDisButtonActionPerformed
private void noDisButtonActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_noDisButtonActionPerformed
disconnectDialog.setVisible(false);
} GEN-LAST:event_noDisButtonActionPerformed
private void disconnectButtonActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_disconnectButtonActionPerformed
TODO add your handling code here:
disconnectDialog.pack();
disconnectDialog.setVisible(true);
} GEN-LAST:event_disconnectButtonActionPerformed
private void ipOKbuttonActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_ipOKbuttonActionPerformed

int[] addressInInts = new int[4];
byte[] addressInBytes = new byte[4];
boolean ipAddressIsValid = true;
Check that the ip is valid
try {
addressInInts[0] = Integer.parseInt(ipByte1.getText());
addressInInts[1] = Integer.parseInt(ipByte2.getText());
addressInInts[2] = Integer.parseInt(ipByte3.getText());
addressInInts[3] = Integer.parseInt(ipByte4.getText());
} catch (NumberFormatException ex) {
ipAddressIsValid = false;
ipAddressStatusLabel.setForeground(Color.red);
ipAddressStatusLabel.setText("Error message: Each box must have a number.");
}
if (0 > addressInInts[0] || addressInInts[0] > 255
|| 0 > addressInInts[1] || addressInInts[1] > 255
|| 0 > addressInInts[2] || addressInInts[2] > 255
|| 0 > addressInInts[3] || addressInInts[3] > 255) {
ipAddressIsValid = false;
ipAddressStatusLabel.setForeground(Color.red);
ipAddressStatusLabel.setText("Error message: Enter numbers b/w 0 and 255.");
}
addressInBytes[0] = (byte) addressInInts[0];
addressInBytes[1] = (byte) addressInInts[1];
addressInBytes[2] = (byte) addressInInts[2];
addressInBytes[3] = (byte) addressInInts[3];
try {
serverIPAddress = InetAddress.getByAddress(addressInBytes);
} catch (UnknownHostException ex) {
ipAddressIsValid = false;
ipAddressStatusLabel.setForeground(Color.red);
ipAddressStatusLabel.setText("Error message: Invalid IP.");
}
if it is ok, close the dialog box
if (ipAddressIsValid) {
serverIPDialog.setVisible(false);
}

} GEN-LAST:event_ipOKbuttonActionPerformed
private void singlePlayerActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_singlePlayerActionPerformed
scrambledWord.setEnabled(true);
guessedWord.setEnabled(true);
guessButton.setEnabled(true);
nextTrial.setEnabled(true);
statusLabel.setEnabled(true);
yourScore.setEnabled(true);
guessedWord.setEditable(true);
} GEN-LAST:event_singlePlayerActionPerformed
private void multiPlayerActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_multiPlayerActionPerformed
scrambledWord.setEnabled(false);
guessedWord.setEnabled(false);
guessButton.setEnabled(false);
nextTrial.setEnabled(false);
yourScore.setEnabled(false);
connectButton.setEnabled(true);
} GEN-LAST:event_multiPlayerActionPerformed
Variables declaration - do not modify GEN-BEGIN:variables
private javax.swing.JMenuitem aboutMenuitem;
private javax.swing.JPanel buttonsPanel;
private javax.swing.JDialog closeDialog;
private javax.swing.JButton connectButton;
private javax.swing.JButton disconnectButton;
private javax.swing.JDialog disconnectDialog;
private javax.swing.JMenuitem EXITMenuitem;
private javax.swing.JLabel feedbackLabel;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenu gameMode;
private javax.swing.JButton guessButton;
private javax.swing.JLabel guessLabel;
private javax.swing.JTextField guessedWord;
private javax.swing.JLabel ipAddressStatusLabel;
private javax.swing.JTextField ipByte1;
private javax.swing.JTextField ipByte2;
private javax.swing.JTextField ipByte3;
private javax.swing.JTextField ipByte4;
private javax.swing.JButton ipOKbutton;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JMenuBar mainMenu;
private javax.swing.JPanel mainPanel;
private javax.swing.JMenuitem multiPlayer;
private javax.swing.JButton nextTrial;
private javax.swing.JButton noButton;
private javax.swing.JButton noDisButton;
private javax.swing.JTextField noOfGame;
private javax.swing.JTextField noOfPlayers;
private javax.swing.JLabel scrambledLabel;
private javax.swing.JTextField scrambledWord;
private javax.swing.JDialog serverIPDialog;
private javax.swing.JMenuitem singlePlayer;
private javax.swing.JLabel statusLabel;
private javax.swing.JButton yesButton;
private javax.swing.JButton yesDisButton;
private javax.swing.JTextField yourScore;
End of variables declaration GEN-END:variables
} For Serialization
*
* To alter this template, select Tools | Templates
* and open the template in the editor.
*
package anagrams;
import java.io.Serializable;
**
*
* @author sirhans
*
enum MessageType {
TURN, DISCONNECT
}; Read here for info about the Serializable interface:
http: java.sun.com ... serialization
class AnagramMessage implements Serializable {
public MessageType type;
public AnagramMessage(MessageType type) {
this.type = type;
}
} For Word Library
* Anagram Game Software *
package anagrams;
**
* Logic for the Anagram Game software.
*
public final class WordLibrary {
private static final String[] WORD_LIST = {
"abstraction",
"ambiguous",
"arithmetic",
"backslash",
"bitmap",
"circumstance",
"combination",
"consequently",
"consortium",
"decrementing",
"dependency",
"disambiguate",
"dynamic",
"encapsulation",
"equivalent",
"expression",
"facilitate",
"fragment",
"hexadecimal",
"implementation",
"indistinguishable",
"inheritance",
"internet",
"java",
"localization",
"microprocessor",
"navigation",
"optimization",
"parameter",
"patrick",
"pickle",
"polymorphic",
"rigorously",
"simultaneously",
"specification",
"structure",
"lexical",
"likewise",
"management",
"manipulate",
"mathematics",
"hotjava",
"vertex",
"unsigned",
"traditional"};
private static final String[] SCRAMBLED_WORD_LIST = {
"batsartcoin",
"maibuguos",
"ratimhteci",
"abkclssha",
"ibmtpa",
"iccrmutsnaec",
"ocbmnitaoni",
"ocsnqeeutnyl",
"ocsnroitmu",
"edrcmeneitgn",
"edepdnneyc",
"idasbmgiauet",
"ydanicm",
"neacsplutaoni",
"qeiuaveltn",
"xerpseisno",
"aficilatet",
"rfgaemtn",
"ehaxedicalm",
"milpmeneatitno",
"niidtsniugsiahleb",
"niehiratcen",
"nietnret",
"ajav",
"olacilazitno",
"imrcpoorecssro",
"anivagitno",
"poitimazitno",
"aparemert",
"aprtcki",
"ipkcel",
"opylomprich",
"irogorsuyl",
"isumtlnaoesuyl",
"psceficitaoni",
"tsurtcreu",
"elixalc",
"ilekiwse",
"amanegemtn",
"aminupalet",
"amhtmetacsi",
"ohjtvaa",
"evtrxe",
"nuisngde",
"rtdatioialn"
};
**
* Singleton class.
*
private WordLibrary() {
}
**
* Gets the word at a given index.
* @param idx index of required word
* @return word at that index in its natural form
*
public static String getWord(int idx) {
return WORD_LIST[idx];
}
**
* Gets the word at a given index in its scrambled form.
* @param idx index of required word
* @return word at that index in its scrambled form
*
public static String getScrambledWord(int idx) {
return SCRAMBLED_WORD_LIST[idx];
}
**
* Gets the number of words in the library.
* @return the total number of plain scrambled word pairs in the library
*
public static int getSize() {
return WORD_LIST.length;
}
**
* Checks if a user's guess for a word at the given index is correct.
* @param idx index of the word guessed
* @param userGuess the user's guess for the actual word
* @return true if the guess was correct; false otherwise
*
public static boolean isCorrect(int idx, String userGuess) {
return userGuess.equals(getWord(idx));
}
}

For About Us Code
* Anagram Game Software *
package anagrams;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import javax.swing.JDialog;
import javax.swing.JFrame;
**
* About dialog of the Anagram Game software.
*
public class About extends JDialog {
** Generates new form About *
public About(JFrame parent) {
super(parent,true);
initComponents();
pack();
Rectangle parentBounds = parent.getBounds();
Dimension size = getSize();
Center in the parent
int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) 2);
int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) 2);
setLocation(new Point(x, y));
}
** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*
GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
mainPanel = new javax.swing.JPanel();
copyrightTextArea = new javax.swing.JTextArea();
closeButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("About Anagrams");
getContentPane().setLayout(new java.awt.GridBagLayout());
mainPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(11, 11, 12, 12));
copyrightTextArea.setBackground(javax.swing.UIManager.getDefaults().getColor("Panel.background"));
copyrightTextArea.setColumns(25);
copyrightTextArea.setEditable(false);
copyrightTextArea.setLineWrap(true);
copyrightTextArea.setRows(8);
copyrightTextArea.setText("Anagrams n nThis is a game of two player. It can be played over a suitable network. nAnagram isn't just a game but a special game that teaches, educate, and better the knowledge of the players involve. n");
copyrightTextArea.setWrapStyleWord(true);
copyrightTextArea.setBorder(null);
copyrightTextArea.setFocusable(false);
closeButton.setMnemonic('C');
closeButton.setText("Close");
closeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closeButtonActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.add(copyrightTextArea, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 285, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup()
.addContainerGap(226, Short.MAX_VALUE)
.add(closeButton)
.addContainerGap())
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.add(copyrightTextArea, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 179, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(closeButton)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
getContentPane().add(mainPanel, gridBagConstraints);
} GEN-END:initComponents
private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) { GEN-FIRST:event_closeButtonActionPerformed
setVisible(false);
dispose();
} GEN-LAST:event_closeButtonActionPerformed Variables declaration - do not modify GEN-BEGIN:variables
private javax.swing.JButton closeButton;
private javax.swing.JTextArea copyrightTextArea;
private javax.swing.JPanel mainPanel;
End of variables declaration GEN-END:variables
}
I used netbeans to do this so you can load it in netbeans IDE for ease
Thank you
This post has been updated by macosxnerd101: 22 February 2011 - 08:47 AMReason for update:: Pls use code tags
View Replies !
Bunco game  (2 Views)
Ok I'm writing the GUI for this bunco game I already spell and I'm executing into some really fusterating difficulties. The game goes like this: the rounds are random and u should be able to select that player goes first. Three die are roled and if all three match the round its a bunco and u receive 21 points. If three of any kinda are rolled its a baby bunco and u receive 5 points. Otherwise if any of the die match the round u receive 1 point for each. The turn should continue as long as you're getting points and the round goes until somebody gets 21 points.
The trouble is that for some reason the scores are not going where tshould the players don't cycle by turns, and the set Turn radio buttons don't work. I used net beans to create the GUI if that helps. heres the code snippet:
GUI:
*
* To alter this template, select Tools | Templates
* and open the template in the editor.
*
*
* GUI.java
*
* Generated on Oct 4, 2010, 12:02:09 PM
*
package javaapplication1;
import javax.swing.*;
import java.util.Random;
**
* private Bunco bunco;
* @author
*
public class GUI extends javax.swing.JFrame{
private DiceSet myDice;
private Bunco bunco;
** Generates new form GUI *
public GUI() {
initComponents();
bunco = new Bunco();

}
** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*
@SuppressWarnings("unchecked")

private void initComponents() {
jInternalFrame1 = new javax.swing.JInternalFrame();
pointslbl = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
userlbl = new javax.swing.JLabel();
complbl = new javax.swing.JLabel();
jSeparator3 = new javax.swing.JSeparator();
rolloutcomelbl = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
die1disp = new javax.swing.JTextPane();
jScrollPane2 = new javax.swing.JScrollPane();
die2disp = new javax.swing.JTextPane();
jScrollPane3 = new javax.swing.JScrollPane();
die3disp = new javax.swing.JTextPane();
trnpointslbl = new javax.swing.JLabel();
jScrollPane4 = new javax.swing.JScrollPane();
trnpointsdisp = new javax.swing.JTextPane();
jScrollPane5 = new javax.swing.JScrollPane();
turnlbl = new javax.swing.JTextPane();
rollbttn = new javax.swing.JButton();
jScrollPane6 = new javax.swing.JScrollPane();
buncodisplay = new javax.swing.JTextPane();
jScrollPane7 = new javax.swing.JScrollPane();
rd1user = new javax.swing.JTextPane();
jScrollPane8 = new javax.swing.JScrollPane();
rd2user = new javax.swing.JTextPane();
jScrollPane9 = new javax.swing.JScrollPane();
rd3user = new javax.swing.JTextPane();
jScrollPane10 = new javax.swing.JScrollPane();
rd4user = new javax.swing.JTextPane();
jScrollPane11 = new javax.swing.JScrollPane();
rd5user = new javax.swing.JTextPane();
jScrollPane12 = new javax.swing.JScrollPane();
rd6user = new javax.swing.JTextPane();
jScrollPane13 = new javax.swing.JScrollPane();
rd1comp = new javax.swing.JTextPane();
jScrollPane14 = new javax.swing.JScrollPane();
rd2comp = new javax.swing.JTextPane();
jScrollPane15 = new javax.swing.JScrollPane();
rd3comp = new javax.swing.JTextPane();
jScrollPane16 = new javax.swing.JScrollPane();
rd4comp = new javax.swing.JTextPane();
jScrollPane17 = new javax.swing.JScrollPane();
rd5comp = new javax.swing.JTextPane();
jScrollPane18 = new javax.swing.JScrollPane();
rd6comp = new javax.swing.JTextPane();
jScrollPane19 = new javax.swing.JScrollPane();
currentrd = new javax.swing.JTextPane();
jMenuBar1 = new javax.swing.JMenuBar();
gameMenu = new javax.swing.JMenu();
jSeparator1 = new javax.swing.JPopupMenu.Separator();
newgameMenuitem = new javax.swing.JMenuitem();
userRadioButtonMenuitem = new javax.swing.JRadioButtonMenuitem();
compRadioButtonMenuitem = new javax.swing.JRadioButtonMenuitem();
jSeparator2 = new javax.swing.JPopupMenu.Separator();
EXITMenuitem = new javax.swing.JMenuitem();
helpMenu = new javax.swing.JMenu();
aboutMenuitem = new javax.swing.JMenuitem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jInternalFrame1.setClosable(true);
jInternalFrame1.setIconifiable(true);
jInternalFrame1.setMaximizable(true);
jInternalFrame1.setResizable(true);
jInternalFrame1.setTitle("Bunco-A Dice Game");
jInternalFrame1.setVisible(true);
pointslbl.setText("Round Points");
jLabel2.setText("R1");
jLabel3.setText("R2");
jLabel4.setText("R3");
jLabel5.setText("R4");
jLabel6.setText("R5");
jLabel7.setText("R6");
userlbl.setText("User:");
complbl.setText("Computer:");
rolloutcomelbl.setText("Roll Outcome");
die1disp.setEditable(false);
jScrollPane1.setViewportView(die1disp);
die2disp.setEditable(false);
jScrollPane2.setViewportView(die2disp);
die3disp.setEditable(false);
jScrollPane3.setViewportView(die3disp);
trnpointslbl.setText("Turn Points");
trnpointsdisp.setEditable(false);
jScrollPane4.setViewportView(trnpointsdisp);
turnlbl.setEditable(false);
jScrollPane5.setViewportView(turnlbl);
rollbttn.setText("ROLL");
rollbttn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rollbttnActionPerformed(evt);
}
});
buncodisplay.setEditable(false);
jScrollPane6.setViewportView(buncodisplay);
rd1user.setEditable(false);
rd1user.setName(""); NOI18N
jScrollPane7.setViewportView(rd1user);
rd2user.setEditable(false);
jScrollPane8.setViewportView(rd2user);
rd3user.setEditable(false);
jScrollPane9.setViewportView(rd3user);
rd4user.setEditable(false);
jScrollPane10.setViewportView(rd4user);
rd5user.setEditable(false);
jScrollPane11.setViewportView(rd5user);
rd6user.setEditable(false);
jScrollPane12.setViewportView(rd6user);
rd1comp.setEditable(false);
jScrollPane13.setViewportView(rd1comp);
rd2comp.setEditable(false);
jScrollPane14.setViewportView(rd2comp);
rd3comp.setEditable(false);
jScrollPane15.setViewportView(rd3comp);
rd4comp.setEditable(false);
jScrollPane16.setViewportView(rd4comp);
rd5comp.setEditable(false);
jScrollPane17.setViewportView(rd5comp);
rd6comp.setEditable(false);
jScrollPane18.setViewportView(rd6comp);
currentrd.setEditable(false);
jScrollPane19.setViewportView(currentrd);
gameMenu.setText("Game");
gameMenu.add(jSeparator1);
newgameMenuitem.setText("New Game");
newgameMenuitem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newgameMenuitemActionPerformed(evt);
}
});
gameMenu.add(newgameMenuitem);
userRadioButtonMenuitem.setText("User Starts Game");
userRadioButtonMenuitem.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
userRadioButtonMenuitemStateChanged(evt);
}
});
gameMenu.add(userRadioButtonMenuitem);
compRadioButtonMenuitem.setText("Computer Starts Game");
compRadioButtonMenuitem.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
compRadioButtonMenuitemStateChanged(evt);
}
});
gameMenu.add(compRadioButtonMenuitem);
gameMenu.add(jSeparator2);
EXITMenuitem.setText("EXIT");
EXITMenuitem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EXITMenuitemActionPerformed(evt);
}
});
gameMenu.add(EXITMenuitem);
jMenuBar1.add(gameMenu);
helpMenu.setText("Assist");
aboutMenuitem.setText("About Game");
aboutMenuitem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aboutMenuitemActionPerformed(evt);
}
});
helpMenu.add(aboutMenuitem);
jMenuBar1.add(helpMenu);
jInternalFrame1.setJMenuBar(jMenuBar1);
javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
jInternalFrame1Layout.setHorizontalGroup(
jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pointslbl)
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane19, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalFrame1Layout.CreateSequentialGroup()
.addContainerGap()
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(userlbl)
.addComponent(complbl))
.addGap(40, 40, 40)
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel2)
.addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 24, Short.MAX_VALUE)
.addComponent(jScrollPane13))
.addGap(18, 18, 18)
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel3)
.addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 24, Short.MAX_VALUE)
.addComponent(jScrollPane14))
.addGap(18, 18, 18)
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel4)
.addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, 24, Short.MAX_VALUE)
.addComponent(jScrollPane15))
.addGap(18, 18, 18)
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel5)
.addComponent(jScrollPane10, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
.addComponent(jScrollPane16))))
.addGap(18, 18, 18)
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel6)
.addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 24, Short.MAX_VALUE)
.addComponent(jScrollPane17))
.addGap(18, 18, 18)
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel7)
.addComponent(jScrollPane12, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.addComponent(jScrollPane18))))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalFrame1Layout.CreateSequentialGroup()
.addContainerGap()
.addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 415, Short.MAX_VALUE)
.addContainerGap())
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalFrame1Layout.CreateSequentialGroup()
.addContainerGap()
.addComponent(rolloutcomelbl)
.addGap(105, 105, 105)
.addComponent(trnpointslbl))
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalFrame1Layout.CreateSequentialGroup()
.addGap(22, 22, 22)
.addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE))
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addGap(31, 31, 31)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 24, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addGap(36, 36, 36)
.addComponent(rollbttn)
.addGap(18, 18, 18)
.addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalFrame1Layout.CreateSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(43, 43, 43)))))
.addGap(100, 100, 100))
);
jInternalFrame1Layout.setVerticalGroup(
jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addComponent(pointslbl, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(jLabel6)
.addComponent(jLabel5)
.addComponent(jLabel4)
.addComponent(jLabel3)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addComponent(userlbl)
.addGap(18, 18, 18)
.addComponent(complbl))
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane18, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane19, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(8, 8, 8)
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(rolloutcomelbl)
.addComponent(trnpointslbl))
.addGap(18, 18, 18)
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addGroup(jInternalFrame1Layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(49, 49, 49)
.addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(rollbttn)
.addGroup(jInternalFrame1Layout.CreateSequentialGroup()
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(176, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.CreateSequentialGroup()
.addContainerGap()
.addComponent(jInternalFrame1)
.addContainerGap())
);
layout.setVerticalGroup(
layout.CreateParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.CreateSequentialGroup()
.addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(294, Short.MAX_VALUE))
);
pack();
}
private void rollbttnActionPerformed(java.awt.event.ActionEvent evt) {
TODO add ur handling code here:
String cround = Integer.toString(bunco.getRound());
currentrd.setText("Current Round: " + cround);
buncodisplay.setText("");

if(bunco.getTurn() == 0){
turnlbl.setText("Turn: User");
bunco.play();
String score1String = Integer.toString(bunco.getScore1());
trnpointsdisp.setText(score1String);
displayDie();
if(bunco.getRound() == 1){
rd1user.setText(score1String);
}
else if(bunco.getRound() == 2){
rd2user.setText(score1String);
}
else if(bunco.getRound() == 3){
rd3user.setText(score1String);
}
else if(bunco.getRound() == 4){
rd4user.setText(score1String);
}
else if(bunco.getRound() == 5){
rd5user.setText(score1String);
}
else if(bunco.getRound() == 6){
rd6user.setText(score1String);
}
if(bunco.isBunco() == 1){
buncodisplay.setText("Bunco ");
}
if(bunco.isBabyBunco() == 1){
buncodisplay.setText("Baby Bunco ");
}
} if(bunco.getTurn() == 1){
displayDie();
turnlbl.setText("Turn: Computer");
String score2String = Integer.toString(bunco.getScore2());
trnpointsdisp.setText(score2String);
bunco.play();
if(bunco.getRound() == 1){
rd1comp.setText(score2String);
}
else if(bunco.getRound() == 2){
rd2comp.setText(score2String);
}
else if(bunco.getRound() == 3){
rd3comp.setText(score2String);
}
else if(bunco.getRound() == 4){
rd4comp.setText(score2String);
}
else if(bunco.getRound() == 5){
rd5comp.setText(score2String);
}
else if(bunco.getRound() == 6){
rd6comp.setText(score2String);
}
if(bunco.isBunco() == 1){
buncodisplay.setText("Bunco ");
}
if(bunco.isBabyBunco() == 1){
buncodisplay.setText("Baby Bunco ");
}
}
}

private void newgameMenuitemActionPerformed(java.awt.event.ActionEvent evt) {
TODO add ur handling code here:
String cround = Integer.toString(bunco.getRound());
currentrd.setText("Current Round: " + cround);
if(bunco.getTurn() == 0){
displayDie();
turnlbl.setText("Turn: User");
String score1String = Integer.toString(bunco.getScore1());
trnpointsdisp.setText(score1String);

}
if(bunco.getTurn() == 1){
displayDie();
turnlbl.setText("Turn: Computer");
String score2String = Integer.toString(bunco.getScore2());
trnpointsdisp.setText(score2String);

}

}
private void aboutMenuitemActionPerformed(java.awt.event.ActionEvent evt) {
TODO add ur handling code here:
JOptionPane.showMessageDialog(null,"Date: 8 5 10" + " n" + "Author: Tim Holt" + " n" + "Version 1.0");
}
private void EXITMenuitemActionPerformed(java.awt.event.ActionEvent evt) {
TODO add ur handling code here:
System.EXIT(1);
}
private void userRadioButtonMenuitemStateChanged(javax.swing.event.ChangeEvent evt) {
TODO add ur handling code here:
bunco.setTurn(0);
}
private void compRadioButtonMenuitemStateChanged(javax.swing.event.ChangeEvent evt) {
TODO add ur handling code here:
bunco.setTurn(1);
}
**
* @param args the command line arguments
*
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {

public void Run() {
new GUI().setVisible(true);

}
});
}
public void displayDie(){
String aString = Integer.toString(bunco.getDie1());
String bString = Integer.toString(bunco.getDie2());
String cString = Integer.toString(bunco.getDie3());
die1disp.setText(aString);
die2disp.setText(bString);
die3disp.setText(cString);
} Variables declaration - do not modify
private javax.swing.JMenuitem aboutMenuitem;
private javax.swing.JTextPane buncodisplay;
private javax.swing.JRadioButtonMenuitem compRadioButtonMenuitem;
private javax.swing.JLabel complbl;
private javax.swing.JTextPane currentrd;
private javax.swing.JTextPane die1disp;
private javax.swing.JTextPane die2disp;
private javax.swing.JTextPane die3disp;
private javax.swing.JMenuitem EXITMenuitem;
private javax.swing.JMenu gameMenu;
private javax.swing.JMenu helpMenu;
private javax.swing.JInternalFrame jInternalFrame1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane10;
private javax.swing.JScrollPane jScrollPane11;
private javax.swing.JScrollPane jScrollPane12;
private javax.swing.JScrollPane jScrollPane13;
private javax.swing.JScrollPane jScrollPane14;
private javax.swing.JScrollPane jScrollPane15;
private javax.swing.JScrollPane jScrollPane16;
private javax.swing.JScrollPane jScrollPane17;
private javax.swing.JScrollPane jScrollPane18;
private javax.swing.JScrollPane jScrollPane19;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JScrollPane jScrollPane6;
private javax.swing.JScrollPane jScrollPane7;
private javax.swing.JScrollPane jScrollPane8;
private javax.swing.JScrollPane jScrollPane9;
private javax.swing.JPopupMenu.Separator jSeparator1;
private javax.swing.JPopupMenu.Separator jSeparator2;
private javax.swing.JSeparator jSeparator3;
private javax.swing.JMenuitem newgameMenuitem;
private javax.swing.JLabel pointslbl;
private javax.swing.JTextPane rd1comp;
private javax.swing.JTextPane rd1user;
private javax.swing.JTextPane rd2comp;
private javax.swing.JTextPane rd2user;
private javax.swing.JTextPane rd3comp;
private javax.swing.JTextPane rd3user;
private javax.swing.JTextPane rd4comp;
private javax.swing.JTextPane rd4user;
private javax.swing.JTextPane rd5comp;
private javax.swing.JTextPane rd5user;
private javax.swing.JTextPane rd6comp;
private javax.swing.JTextPane rd6user;
private javax.swing.JButton rollbttn;
private javax.swing.JLabel rolloutcomelbl;
private javax.swing.JTextPane trnpointsdisp;
private javax.swing.JLabel trnpointslbl;
private javax.swing.JTextPane turnlbl;
private javax.swing.JRadioButtonMenuitem userRadioButtonMenuitem;
private javax.swing.JLabel userlbl;
End of variables declaration
}Bunco:
package javaapplication1;
*
* Author:
* Date: Sep. 15
*
import java.util.Random;
public class Bunco {

private DiceSet myDice;
private Random generator = new Random();
private int round = generator.nextInt(6) + 1;
private int won1;
private int won2;
private int score1;
private int score2;
private int roundsover = 0;
private int d1;
private int d2;
private int d3;
private int ibunco;
private int ibabybunco;
private int turn;
private int r1 = 0;
private int r2 = 0;
private int r3 = 0;
private int r4 = 0;
private int r5 = 0;
private int r6 = 0;
* add other private variables as needed *
public Bunco() {
myDice = new DiceSet();

}
public void play() {
the main logic of the game goes here. This method
invokes the userTurn() and computerTurn() methods as required
while(roundsover = 21){
if(round == 1){
r1 = 1;
}
else if(round == 2){
r2 = 1;
}
else if(round == 3){
r3 = 1;
}
else if(round == 4){
r4 = 1;
}
else if(round == 5){
r5 = 1;
}
else if(round == 6){
r6 = 1;
}
won1 = won1 + 1;
turn = 1;
score1 = 0;
score2 = 0;
roundsover = roundsover + 1;
round = generator.nextInt(6) + 1;
while((r1 == 1 && round == 1) || (r2 == 1 && round == 2) || (r3 == 1 && round == 3) || (r4 == 1 && round == 4) || (r5 == 1 && round == 5) || (r6 == 1 && round == 6)){
round = generator.nextInt(6) + 1;
}
}
comp wins round
else if(score2 >= 21){
if(round == 1){
r1 = 1;
}
else if(round == 2){
r2 = 1;
}
else if(round == 3){
r3 = 1;
}
else if(round == 4){
r4 = 1;
}
else if(round == 5){
r5 = 1;
}
else if(round == 6){
r6 = 1;
}
won2 = won2 + 1;
turn = 0;
score1 = 0;
score2 = 0;
round = generator.nextInt(6) + 1;
roundsover = roundsover + 1;
while((r1 == 1 && round == 1) || (r2 == 1 && round == 2) || (r3 == 1 && round == 3) || (r4 == 1 && round == 4) || (r5 == 1 && round == 5) || (r6 == 1 && round == 6)){
round = generator.nextInt(6) + 1;
}
}
if(turn == 0){
userTurn();
}
else if(turn == 1){
computerTurn();
}
}
game over win
if(won1 > won2){
roundsover = roundsover + 1;
}
game over lose
else{
roundsover = roundsover + 1;
}
}
public void userTurn() {
This method handles one turn for the user player
ibunco = 0;
ibabybunco = 0;
myDice.roll();
int a = myDice.getValue(1);
int b = myDice.getValue(2);
int c = myDice.getValue(3);
d1 = a;
d2 = b;
d3 = c;
bunco
if(a == round && b == round && c == round){
score1 = score1 + 21;
ibunco = 1;
setTurn(0);
}
baby bunco
else if(a == b && b == c){
score1 = score1 + 5;
ibabybunco = 1;
setTurn(0);
}
else if((a == round && b == round) || (a == round && c == round) || (b == round && c == round)){
score1 = score1 + 2;
setTurn(0); }
else if((a == round) || (b == round) || (c == round)){
score1 = 1 + score1;
setTurn(0);
}
else{
setTurn(1);

}
}

private void computerTurn() {
This method handles one turn for the computer player
ibunco = 0;
ibabybunco = 0;
myDice.roll();
int a = myDice.getValue(1);
int b = myDice.getValue(2);
int c = myDice.getValue(3);
d1 = a;
d2 = b;
d3 = c;
bunco
if(a == round && b == round && c == round){
score2 = score2 + 21;
ibunco = 1;
setTurn(1);
}
baby bunco
else if(a == b && b == c){
score2 = score2 + 5;
ibabybunco = 1;
setTurn(1);
}
else if((a == round && b == round) || (a == round && c == round) || (b == round && c == round)){
score2 = score2 + 2;
setTurn(1);
}
else if((a == round) || (b == round) || (c == round)){
score2 = score2 + 1;
setTurn(1);
}
else{
setTurn(0);

}
}
public void setTurn(int newTurn){
turn = newTurn;
}
public int getTurn(){
return turn;
}
public int getScore1(){
return score1;
}
public int getScore2(){
return score2;
}
public int getRound(){
return round;
}
public int getDie1(){
return d1;
}
public int getDie2(){
return d2;
}
public int getDie3(){
return d3;
}
public int isBunco(){
return ibunco;
}
public int isBabyBunco(){
return ibabybunco;
}
public void Run(){
This method is execute when the game is started.
The player selects whose turn is first here.
if(turn == 0){
userTurn();
}
else if(turn == 1){
computerTurn();
}
}
} * include other (private helper) methods as needed *
oh and heres the die class if you want it: **
* Represents one die (singular of dice) with faces displaying values
* b/w 1 and 6.
*
* @author Java Foundations
*
package javaapplication1;
public class Die {
** maximum face value *
private static final int MAX = 6;
** current value displaying on the die *
private int faceValue;
**
* Constructor: Sets the initial face value of this die.
*
public Die () {
faceValue = 1;
}
**
* Computes a new face value for this die and returns the
* result.
* @return an int
*
public int roll () {
faceValue = (int) (Math.random () * MAX) + 1;
return faceValue;
}
**
* Face value mutator. The face value isn't modified if the
* specified value isn't valid.
* @param value an int indicating the face value of the die
*
public void setFaceValue (int value) {
if (value > 0 && value
This post has been updated by macosxnerd101: 06 October 2010 - 06:09 PMReason for update:: Added code tags. Pls use them in the future.
View Replies !
creating an online multiplayer board game  (5 Views)
i just need to have an solution of what language s will i use if i want to make an online multiplayer board game..
give me some suggestions..
View Replies !
Wana help with Hangman game  (0 Views)
I want to make a hangman game some thing like this: http: www.geo.nl ki...geo-spel03.html
I'm doing this with the components pallete from Netbeans we have not use custom creation code snippet to generate own panels frames, and more.
I want to have 3 classes atleast (I'm using 4)
1)Data class to read the .txt files and put them in an array and pick a random word saying. (I alrdy got this class rdy)
2)Game class: the logic of the game.
3)GameGUI class: Jframe with buttons labels
4)Hangman class: Jpanel to show the gallow.
I'm stuck with the GameGUI class. How can i receive input from the buttons to use in the Game class.public class Game {
private final int TURNS = 10;
private int misses;
private char inputChar;
private String guessedWord;
private String hiddenWord; public Spel(char inputChar, String guessedWord) {
this.inputLetter = inputChar;
this.guessedWord = guessedWord;
}
public void hideWord(String guessedWord) {
hiddenWord = "";
for (int i = 0; i
I do not quite understand the Jframe, buttons and more... I know how can i place them on the frame but not how can i provide them actions (with the actionListener mouseListener)... I know the Game logic is not quite what it has to be but it is all what I've for now.
View Replies !
Not able to "smooth out" grid movement in game  (3 Views)
So in short, me and a partner are working on a game for our Computer Science final project, and we can not receive the introductory overworld engine to work like we want it to. The game we are making is a Pokemon clone, so the overworld screen is supposed to be a grid... plus it is a requirement to use a grid in our game . . Neither of us really know what to do here. The only solution I could think of would be to kinda "lock" the character into finishing a loop of an animation, but that did not work out too well. Any tips at all would be great
And the source code snippet:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class jFrameTest extends JFrame implements KeyListener
{
Graphics g;
int appWidth, appHeight,x,y,SQUARE_SIZE;
int currentKey,tileSlideCount;
boolean animationFlag; is the animation finished
public jFrameTest()
{
super("This is a test for JFrames");
animationFlag = true;
setSize(500,400);
addKeyListener(this);
setFocusable(true);
setVisible(true);
requestFocusInWindow();
x=0;
y=0;
SQUARE_SIZE=20;
}
public void keyPressed(KeyEvent event)
{
currentKey = event.getKeyCode();
System.out.println(currentKey);
System.out.println(x +","+ y);
if (currentKey == KeyEvent.VK_LEFT)
{
if(animationFlag)
{
animationFlag = false;
for(tileSlideCount=0;tileSlideCount getSize().width - 3 - SQUARE_SIZE)
x = getSize().width - 3 - SQUARE_SIZE;
repaint();
}
else
if (currentKey == KeyEvent.VK_UP)
{
for(tileSlideCount=0;tileSlideCount getSize().height - 3 - SQUARE_SIZE)
y = getSize().height - 3 - SQUARE_SIZE;
repaint();
}
System.out.println(currentKey);
}
public void keyReleased(KeyEvent event)
{
currentKey=event.getKeyCode();
}
public void keyTyped(KeyEvent event)
{
currentKey=event.getKeyCode();
}
public void paint(Graphics g)
{
g.setColor(Color.white);
g.fillRect(0,0,510,400);
g.setColor(Color.black);
g.fillRect(x,y+20,SQUARE_SIZE,SQUARE_SIZE);
}
public void delay(int n)
{
long startDelay=System.currentTimeMillis();
long endDelay=0;
while(endDelay-startDelay
View Replies !
I have a java slots game but wana it to start with users points  (4 Views)
I think the answer to this is easy but I've no solution how can i do it.
The page has the application on it and theres a .settings file that I can alter the odds and the "starting points"


Now Is there any method I can set this up so it searches the users credits and sets it in the game by the settings file
Any assistance would be comprehended
View Replies !
Creating a dice Object job.  (3 Views)
The question is to Write a program that generates a Dice Object.
Ur program will involve two different classes in different files:
One class for the main method
Another class describing the Dice Object
The Dice class should have fived methods (and one class variable for storing the
number on the dice):
A constructor method with the same name as the class
A roll( ) method for rolling the dice
A getValue( ) method for returning the value displaying on the dice
An isEven( ) method that checks if the value is even or odd
An isHigh( ) method that checks if the value is high or low
The main software should do the following:
1. Generate a Dice Object
2. Roll the dice every time the user hits enter
3. Print out the new value displaying on the dice
4. Print out if the value is even or odd high or lowso far I've this
public class diceGame
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Dice dice1 = new Dice();

System.out.println("dice1 is " + dice1.roll());



}
}
public class Dice
{

int roll()
{
return 1 + (int)(Math.random() * 6);
}

}
I just want assist with the other methods
View Replies !
dice rolling class difficulty  (2 Views)
Okay I am confused on how can i generate a class and use it else where... Here's my code snippet: the directions to my assignment are listed:Design and implement a class called Die (for a die in a pair of dice). Include a constructor for a die (which will set its value as null or -1) methods to set and receive the individual die values, and a method to print the die. For example, a 4 will print as
* *
* *
Generate a driver class called CreatePairOfDice to instantiate and print a pair of dice. The dice want not be random, u may select the pair. Turn in a printed copy of the software, along with a printout of the output from a sample execute.my code:
class PairOfDice {
int diceroll1=1;
int diceroll2=2;class createdice{
PairOfDice method = new PairOfDice();
if (diceroll1==1){
System.out.println("* t");
System.out.println("");
}
if (diceroll2==2){
System.out.print("* n *");
}
public static void main(String[] arg) {createdice method = new createdice;
}
}
View Replies !
comparing indices of Int array and String array  (2 Views)
guys so I've a program that gives u options to add, save, erase, see, and fetch persons to and from a binary file.
I have gotten all the methods correctly (knock on wood) but this method is killing me: array where all Person Objects are added
private Person[] data;
** Method to print and fetch the index of a retrieved Person Object.
* If no Person wasn't found with the matching search String in ANY of
* its variables, this method prints a message and returns -1.
* @return int[] - Indices within data[] of matching Person Objects
*
public int[] retrievePerson() {
Scanner keyboard = new Scanner(System.in);
System.out.println(
"Pls enter a search String (followed by the Enter key): n");
String search = keyboard.nextLine();
while(search == null || search.trim().length() == 0) {
System.out.println("Invalid entry, pls enter a search String of one or more characters.");
search = keyboard.nextLine();
}
System.out.println("Attempting to fetch person " + search);
initialize returned int[] to a maximum of numEntries indices
int[] indices = new int[numEntries];

retrieval part of this method updating the
int[] with matching indices and printing info on all Person
Objects found
for (Person p : data) {
if (p = null) {
data[p] = indices[];
System.out.println("Info found: " + data);
}
}

return indices;
}
How would I equate the indices of an Int array with a Person Object array
Thanks
This post has been updated by cfoley: 22 September 2011 - 05:30 PM
View Replies !
Getting some bugs in my completed dice software  (3 Views)
This is my so first Java program (excluding "World ").
I'm almost done with the program but I'm getting some bugs that I do not know how can i debug. For reference I'm using the Eclipse IDE.
What this program is supposed to do is generate a PairOfDice instance in main.
Then We're supposed to generate the following functions...
One to view how several rolls it takes to roll doubles
Another to view how several doubles are rolled after a million rolls
and finally, to roll the dice 100,000 times and add up all the numbers and average them.Here's the difficulties I'm having, I generated my main as just a class at first because I kept getting bugs on all my functions until I took away "public static void main(String[] args) {", then the bugs went away.Also, I've the 3 function in seperate .java files instead of all in the same file, I do not know if I'm supposed to do that.
I receive bugs on every function header, for instance public int Million().
Then I receive an error message on int count on the first two functions, and int sum on the third that keeps telling me I've a syntax error message.
I also receive an error message on the closing bracket of all three functions.
PairOfDice.java
public class PairOfDice {
public static void main(String[] args) {
public int die1; Number displaying on the first die.
public int die2; Number displaying on the second die.


public int getDie1() {
return die1;
}
public void setDie1(int die1) {
this.die1 = die1;
}
public int getDie2() {
return die2;
}
public void setDie2(int die2) {
this.die2 = die2;
}
public PairOfDice() {
Constructor. Rolls the dice, so that tinitially
display some random values.
roll(); Call the roll() method to roll the dice.
}

public PairOfDice(int val1, int val2) {
Constructor. Generates a pair of dice that
are initially displaying the values val1 and val2.
die1 = val1; Assign specified values
die2 = val2; to the instance variables.
}
public void roll() {
Roll the dice by setting each of the dice to be
a random number b/w 1 and 6.
die1 = (int)(Math.random()*6) + 1;
die2 = (int)(Math.random()*6) + 1;
}

int rollDoubles();
int Million();
float Average();
}
}rollDoubles.java
public int rollDoubles() {
PairOfDice pod = new PairOfDice();
int count = 0;
while (pod.getDie1() = pod.getDie2())
{
pod.roll();
count++;
}
System.out.println ("It took " + count + " roll(s) to receive a double." );
return count;
}Million.java
public int Million() {
PairOfDice pod = new PairOfDice();
int count = 0;
for (int i = 1; i
Average.java
public float Average {
PairOfDice pod = new PairOfDice();
int count = 0;
float average = 0;
int sum = 0;
while (count = 100000)
{
sum = sum + pod.getDie1();
sum = sum + pod.getDie2();
}
average = sum count;
System.out.println ("The average number rolled after 100,000 rolls was :" + count);
return average;
}

View Replies !
i want to inter student data according to their spadices major  (2 Views)

import javax.swing.JOptionPane;
public class assignment22{
public static double major( Students[] a1int n){

for(int i=0;i;


}

System.out.println("Student ID t t"+"Student Name t t"+"course1 t t"+"mark1 t t"+"course2 t t"+"mark2 t t"+"course3 t t"+"mark3");
for (int i=0;i
This post has been updated by smohd: 06 December 2011 - 03:38 PMReason for update:: Code tags added. Pls use [code] tags when posting codes
View Replies !
Random numbers rolling dices strange results  (3 Views)

I've got some strange results that i can not define.
I roll a die for say 100.000.000 times, add all results and divide by the number of the rolls.
This is how i roll a die:
public static int rollDice(){
int result;
Random r = new Random();
int randint = r.nextInt(6);
result=randint+1;
return result;
}

This is how i do the calculations:
public static void main(String[] args) {
long sum,result, n;
double mean;
n=100000000;
sum =0;
result =0;
System.out.println(n+" rolls");
for(int i=0;i
sample output:
100000000 rolls
relative frequency: 3.49980715
Of course the relative frequency (->mean) should approximate the expected value of one roll, that is 3.5. To be more accurate, after this number of rolls the result should lie within 3.5 + - 0.001 with a probability of 99,9 .
This seems to work.
But now comes the riddle.
In a different sum (->vsum) i add only those dices, that do not display a six and still divide by the total number of rolls.
The relative frequency (->vmean) of this modified counting should approximate 2.5, again 2.5 + - 0.001 with a probability of 99,9 .
I take the original main method, and add some more lines:
public static void main(String[] args) {
long sum,result, n,vsum;
n=100000000;
System.out.println(n+" rolls");
double mean, vmean;
sum =0;
vsum =0;
result =0;
for(int i=0;i
sample output:
100000000 rolls
relative frequency: 3.50447067
relative frequency, modified counting: 2.51237313
Not only the modified value is way out of bounds, but also the original one is too high
I've checked many times, the results for the variable mean are constantly too high, but i did not alter anything in the code snippet that should affect this variable.
Right now I am using widows eclipse, but I guess i had identical results with linux console (I will check on this).
Some thing for the X-files
Cheers, Rumo
View Replies !
Wana dice to display  (1 Views)
I am attempting to make a Yahtzee type game for my Java class. Every thing seems to be working fine except when I press the roll button I do not receive the images to show. I did set the JLabels to images it just seems to be with the roll method or the actionPerformed method and I can't figure it out. I am attempting to make it roll specific die on the basis of if or not a corresponding checkbox is selected. If it matters, I am using the netbeans platform.
Here is the action code snippet:
public void actionPerformed(ActionEvent event1){

String command = event1.getActionCommand();
if(command.equals("New Game")){
dispose();
GameGUI gameGUI = new GameGUI();
try{
dispose();
gameGUI.Start();

}
catch(IOException e){

}
}
else if(command.equals("EXIT Game")){
JOptionPane.showMessageDialog(null, "OK, U asked for it");
try{
CloseAll sd = new CloseAll();
sd.closeAll();
}
catch(IOException e){
}
}
else if(command.equals("Roll")){

if(diceScores.size()
And here is the roll code:public void roll(){
int dieNum = 0;
die1Box.setSelected(true);
die2Box.setSelected(true);
die3Box.setSelected(true);
die4Box.setSelected(true);
die5Box.setSelected(true);
for(int i = 0; i
I am only in my second term of Java and have just learned how can i even generate a GUI so
View Replies !
java simple dice game difficulty  (1 Views)
Hello
Thank u in advance for taking the time to assist me
My assignment is to write a dice game in java using the Die.java class.The Object of the game is to reach a total of 41 or more by rolling a pair of dice no more than 6 times. If u receive 10, 20,30, or 40 as ur total u automatically lose, and if u roll doubles u receive an extra roll (however if u roll a 5 & 5 u loose).
I am having difficulties adding my turn totals pls assist me.
for instance i receive
Roll #1 5 2 Ur total is : 7
Roll #2 3 1 Ur total is : 7 when it should be 11
Roll #3 2 3 Ur total is : 7 when it should be 16 and it keeps doing that for all the rolls
How can I receive the turn total to add up after every rollI am just a newbie in programming so pls be patient with me, and i apologize if did not make myself too clear.
Thank u again
my code snippet :
public class FortyOne{
public static void main(String [] args){Die die1, die2;
Generate a pair of dice
die1 = new Die();
die2 = new Die(6);
Rolls dice
die1.roll();
die2.roll();
int rollCount;
rollCount = 0;
rollCount++; Initiate game
System.out.println("Let's Play 41 ");
System.out.print("Roll #"+ rollCount+" ");
rollCount++;
After the roll, prints out the value of die1 & 2.
System.out.print(die1.getUpValue() + " ");
System.out.print(die2.getUpValue() + " ");
if u get doubles
if (die1.getUpValue() == die2.getUpValue())
System.out.print("U GOT DOUBLES ");
Gives turn total
int turnTotal = die1.getUpValue()+die2.getUpValue();
prints out sum of die1 and die2
System.out.print("Ur total is: " + turnTotal+ " ");
Adds turnTotal to the next
int playerTotal =0;
playerTotal+=turnTotal; gives the wining number
int winner= 41;
Limits the amount of rolls to 6.
if(rollCount >=7)
System.out.println("U LOSE ");
Tells player tlose if their roll amount or total equals 10,20,30,or 40
if(turnTotal == 10 || turnTotal == 20 || turnTotal == 30 || turnTotal == 40){
System.out.println(" n" +" AW U lose Sorry ");}
else if(playerTotal == 10 || playerTotal == 20 || playerTotal == 30 || playerTotal == 40){
System.out.println(" n" +" AW U lose Sorry ");}
else
do {
System.out.print(" n" + "Roll #"+ rollCount+" ");
rollCount++;
die1.roll();
die2.roll();
die1.getUpValue();
die2.getUpValue();
System.out.print(die1.getUpValue() + " ");
System.out.print(die2.getUpValue() + " ");
System.out.print("Ur total is: " + (turnTotal)+ " ");
} while (rollCount
View Replies !