Game Loop Freezing - Reset Button To Clear Board

Nov 9, 2014

I'm back with a question about the Black Jack assignment. I've created a working game that works for one round, as well as a reset button that's able to clear the board of the old hand. However the runGame() loop, which checks whether a player has played his hand seems to freeze the program the second time around

private void initNewGame(){
dealer.addCard();
for(int i = 0; i < numberofplayers; i++){
players[i].addCard(); //draws card, adds score and paints card to the board
players[i].setStatus(false); //makes the buttons usable in the players[] class

[Code] .....

I know it's probably not optimal having an while loop constantly running to check the status, but I can't seem to figure out why it freezes.

View Replies


ADVERTISEMENT

Guessing Game - How To Reset Random Number When User Reset Game

Oct 2, 2014

I tried this program, its guessing game. Where program decide 1 number and user will guess number. I am getting 1 problem. When user want to play game again.the random number remain same. So where i can put reset random in code..? And 1 more question if I want to write driver code for this. What should i transfer to driver code.

import java.util.Random;
import java.util.Scanner;
public class GuessGame {
public static void main(String args[])
{
String choice="y";

[Code] ......

View Replies View Related

Radio Buttons - Reset - Clear Dot

Oct 13, 2009

I have 5 radio buttons in my gui, I have a reset button which I have resetting everything else but now I am looking to remove the dot from the selected RB when you press the reset.

View Replies View Related

Tic Tac Toe Game - Random Number Generator And Two Dimensional Arrays For Game Board

May 9, 2015

Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.

import java.util.Random;
import java.util.Scanner;
 public class TicTacToe {
 private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
 
[Code] ....

View Replies View Related

Button To Reset View Of JFrame

Jan 23, 2015

I have to write a program that will generate 20 random circles with random radius lengths. If any of these circles intersect with another, the circle must be blue, and if it does not intersect, the color is red. I must also place a button on the JFrame. If this button is pressed, it needs to clear out the JFrame, and generate a new set of 20 circles following the same color rules. I am extremely new to Java Swing and am really stuck. I have everything working except the button. I cannot get a new set of circles to generate.

import java.awt.Graphics;
import javax.swing.JPanel;
import java.util.Random;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

[Code] ....

View Replies View Related

Stuck In A Loop - Max Value Gets Reset To The Next Value In File

Mar 14, 2014

The problem i believe is that I have the max value set to the first value given out, but every time the loop repeats the Max value gets reset to the next value in the file.

Essentially the program is supposed to read a list of credit card transactions and tell the user which transaction is the highest.

Here's the list of the sample file, note that the number of transactions could change that's why i haven't tried simply passing the values to method.

Bicycle 562.90
Groceries 138.43
Hotel 612.00

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class CreditCards {
public static void main(String[] args) throws IOException {
String fileName = "C:/Users/David/Desktop/CreditCard.txt";
File inputFile = new File(fileName);

[Code] ....

View Replies View Related

Tic Tac Toe Game - X And O Do Not Show In The Board

Apr 12, 2014

I have a tic tac toe game and when i run it it works and there are no errors. but the X's and O'x do not show in the board. I know the problem is in the "gameBoard" method and its cause i am telling the code to print the same board every time but i dont know how to do it the right way....

package chap7MDA;

import java.util.Scanner;
public class chapexe7we {
public static void main(String[] args) {
char[][] board = new char [3][3];//make a game board
gameBoard(board);// call the method game board to make the board

[Code] ....

View Replies View Related

Clear Button - How To Fix Price To Stop Adding Up

Apr 26, 2014

I've got my clear button to work on most of the stuff I want, however I cant figure out how to fix the price to stop adding up. e.g. hit a button image with a price of 599.99, hit the clear button to empty, select price of 599.99 again then it display 1199.98.

sofa method

if (source == jBSofa) {
System.out.println("Sofa"); {
dTotal = dTotal + 599.99;
jTotal.setText(Double.toString(dTotal));
jTotal.setText(String.format("%.2f", dTotal));
}

Reset method

private void Reset() {
jTTotal.setText(" ");
jTotal.setText(" "); //sub total clear
jTTotalTotal.setText(" ");

Attached image(s)

View Replies View Related

How To Make Button Clear The Data That User Entered

Mar 25, 2015

package com.example.imc;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

[Code] ....

View Replies View Related

Design Layout Of Calculator And Add One More Button To Clear Textbox Strings One By One

Mar 30, 2014

I need to design the layout of this calculator and also add one more button that clears textbox strings one by one instead of whole.

import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.event.*;
public class Calculator extends JFrame{
double value1;
double value2;
String operator;
double result;

[Code] .....

View Replies View Related

Keeping Track Of Player Position In Monopoly Board Game

Jun 28, 2014

I am trying to design a monopoly board game with a class and a main program. I can not make the method to keep track of the player's position after every roll. After every roll it prints "Previous position: 0".The player should also not go over 14th spot because the board is just 15 including 0. That is what I have (just the particular method and the part from the main program which call it).

public int getpospl1()
{
System.out.println( getplayer1name() + " Rolls "
+ "Dice 1: " + getrolld1() + "" + "Dice 2: " + getrolld2() + "" );
int spot1 = 14; //The end spot
int start = 0;
int previousPosition = start;

[Code] .....

View Replies View Related

Clear JButton Will Not Clear Text

May 6, 2014

import javax.swing.*;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.*;

[code]....

My issues is at the bottom, I can't get the clear button to clear, well it clears but it also show the JOptionPane. I couldn't find the edit button on the page

View Replies View Related

Checkers Button Game

May 1, 2015

How do I track player (piece) movement?Building on the movement, to capture the piece you don't jump over it as in checkers, you move your piece onto the other color, so...How do I count pieces captured?

I'm really struggling on the physical code part. Conceptually I get that I need to store the information of each button clicked, but I don't understand HOW to store it, HOW to move a piece, and HOW to implement a system of turns.

View Replies View Related

Loop Ending With ESC Button?

Jun 10, 2014

end the loop with the ESC button.

import java.util.Scanner; 
class Sum {
public static void main(String[] args) {
int sum = 0;
System.out.println("Please write a number, end with ESC button");
Scanner in = new Scanner(System.in);

[Code] ....

View Replies View Related

Loop Ending With ESC Button

Jun 10, 2014

I'm doing old projects . This loop will take any number, sum it and when you press the ESC button the loop will end and you will be shown the sum.

Java Code:

import java.util.Scanner;
class Sum {
public static void main(String[] args) {
int sum = 0;
System.out.println("Please write a number, end with ESC button");
Scanner in = new Scanner(System.in);
int number = in.nextInt();

[Code] ....

Here is the error

Java Code:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

The operator != is undefined for the argument type(s) int, null mh_sh_highlight_all('java');

So well, the int ain't boolean says itself. also null ain't that for string ?

The original project was to get the number using one dialog box, convert the string to int and run the loop, so when you pressed ESC there then the return would be null.

View Replies View Related

Actionlistener For Calculator / Button Are Created Within A For Loop For Number 1 To 9

Mar 8, 2014

coding the action listener for my button (btBody) which create button displaying 1 to 9 in a nested for loop; the button should allow the user to click on them and to display the number clicked on in a JTextField;my code;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class EX_7_2 extends JFrame
{
public EX_7_2()
{
setLayout(new BorderLayout(5, 10));

[code]....

View Replies View Related

Swing GUI Freezing With Bounded-buffer

Jul 12, 2014

I'm writing a simple application, that provides a Swing GUI to a bounded-buffer problem. The application is composed by:

- Main.java: it creates a map of four threads (four instances of the class MyThread). Also it creates a shared database (an instance of the class Database) between the four threads.

- MyThread.java: it's an extension of Thread, and it shows a Swing GUI associated to this thread. Each thread is associated a GUI.

- GUI.java

- Database.java: it's an extension of ArrayList and and it can contain a maximum of five elements. An element is an instance of the class User. Also it implements put() and extract() method consistent with the algorithm of bounded-buffer problem.

- DatabaseException.java: it's a simple message.

- User.java

public class Main {
public static void main(String[] args) {
Database db = new Database();
Map<String, Thread> tdg_m = new HashMap();
for (int i = 1; i <= 4; i++) {
tdg_m.put("T" + i, new MyThread(db));

[Code] .....

The issue is the following. When the database is full, and i try to put an element, the GUI freezes. The same problem occurs when I try to extract an element from the empty database.

View Replies View Related

JSF :: Hibernate On Tomcat 7- UI Is Freezing After Uncertain Time

Jan 31, 2014

Currently we are facing a problem in application developed in JSF, Hibernate on Tomcat server 7. The UI is getting freezed after uncertain time. Sometimes it worked for 2 to 5 hours and sometimes it hangs out within 10 mins, too.

Session time out in web.xml is -1

Before, we were getting memory leak logs in catalina, so we implemented ClassLoaderLeakPreventor in the application. When problem occurs, below log is printing in catalina.out.

INFO: Reloading context [/SHRWeb241213]
Jan 31, 2014 12:42:36 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/SHRWeb241213] has started
ClassLoaderLeakPreventor: com.cosmos.leakPrevention.ClassLoaderLeakPreventor shutting down context by removing known leaks (CL: 0x19a37a)
ClassLoaderLeakPreventor: Removing 47 classes from Mojarra descriptors cache

[Code] ....

View Replies View Related

Broken Loop - Number Guessing Game

Jun 3, 2014

What's wrong with my code. It says 'you win' even when I guess an incorrect number. And then the 'win' message keeps repeating. I'm thinking I need a way to generate a new input? And then maybe take the 'win' message out of the loop, but that breaks it too.

View Replies View Related

Guessing Game Demo - How To Add DoAgain Loop

Apr 8, 2014

Ok, here's what I got.
 
import java.util.Random;
import java.util.Scanner;
 
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
 
public class demoGuessGame { 
public static void main(String[] args) {
Random any = new Random();
Scanner input = new Scanner (System.in);
try {
  int maxNum, maxTries, guess;
boolean win = false;
 
[Code] .....

I want to make it loop again when asked, "Do you want to play again?"

View Replies View Related

Applets :: Java Applet Freezing At Client Side?

May 6, 2014

We have a weblogic based application, which runs Applet at the client side when the application is launced.

the application is getting freezed for a client.

how we can analyze the cause of this behavior,

1) As to how we can take thread dump or any other details to analyze the issue.

View Replies View Related

Swing/AWT/SWT :: Window To Submit Data Freezing When Created Inside Mouse Clicked Event

Feb 18, 2014

I'm trying to right a GUI in swing, and as part of my program, I want to open a secondary window out of the main window when a mouse clicks on the main window. Then, once I click a button on the secondary window, I want that window to close and submit data to the main window (like an info form). I have almost figured out how to do this, except for one problem. By putting a variable inside my form window called "ready," and then in my main window running a loop that constantly checks if ready is true and doesn't proceed until its true, I can create the form window, modify the values in it (currently just one value called "difficulty" that's modified by a jSlider), and then when i click the "begin" button, ready is changed to true, the form window closes, and the main window can proceed. However, when I try to put the while loop checking the ready variable inside a mouseClicked method in the main window, the form window freezes when it opens, and you can't see any of its content or modify it in any way (you can't even close it).

Here is my code:

//form window class
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class formWindow extends JFrame {
private JTextField instructions1;

[Code]...

View Replies View Related

Cardlayout Format - Change Main Menu Screen Into Game Screen On Button Click

Mar 16, 2015

I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so

Here is the code from my CardLayout:

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;

[Code] ....

I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.

Here is the main important GUI from my CheckerBoard class:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
  public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
 
[Code] ....

Once again kept to a minimal.

View Replies View Related

Socket Exception - Connection Reset

May 13, 2014

I got the below exception .how to resolve this .It's receiving the data up to 10 min then suddenly below error happening. I have embedded the source code below

java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)

[Code] .....

View Replies View Related

Applets :: JRE 7 - Reset Default Toolkit

Aug 14, 2014

I want to use my implemented toolkit while loading applets. So, I have set the Runtime Parameters

-Dawt.toolkit=org.sug.MyToolkit in Java Control panel.

But when it is not picking MyToolkit, instead its default toolkit sun.awt.windows.WToolkit.

I am able to set it perfectly in Java 6 but it is not working in java 7.

View Replies View Related

Reset Form By Passing Between 2 JSPs?

May 2, 2013

I have a HelloWorld.java_:

package com.javapapers.sample.ajax;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved