Game Over Method Not Updating Correctly

Sep 4, 2014

If I run this code. I can manipulate it so that X wins. When the third X button is pressed, there is no display saying that X has won and that the game is over. I have read over this code for days and still have not figured it out.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 public class TicTacToe extends JFrame implements ActionListener, WindowListener{
 public JFrame window = new JFrame("window");

[Code] ....

View Replies


ADVERTISEMENT

SetText Method Not Updating JLabel?

Jun 26, 2015

updating a label from a different actionPerformed class. The problem is in the settext command it is not updating the JLabel.
 
public class total1 extends swingPointofSale implements ActionListener

public double totalCost;
public String totLabel;

[Code]....

View Replies View Related

Swing/AWT/SWT :: Controls Not Updating Until Method Is Completely Finished

Dec 30, 2014

I have this method that does several RegEx queries along with a lot of searching and replacing of text, and each regex search / replace takes some time and a total of maybe two minutes for all of them to finish up. So I added a ProgressBar to my JavaFX form and I added code after each step to simply use the ProgressBar.setProgress method by a factor of 10% each step ... so the code would resemble something like this:

do a regex query
if it finds things then do a replaceAll method on the string being searched
ProgressBar.setProgress(.1)

do another RegexQuery
If it finds stuff, so a replaceAll method
ProgressBar.setProgress(.2)

etc...

What is happening is that the progress bar will not actually paint any progress until AFTER the entire method is done executing. So from the users perspective, they click on the button and the program appears to freeze until its all done with that method at which point it instantly changes the progress bar to the last value I set ...

So the desired effect is simply not working, and I don't know why.

I tried changing (as in replacing the progress bar with a different control) the progress bar value settings with updating text in a text box on the form, and even that didn't display any of the text messages until AFTER the procedure was done executing at which point, all of the text logs appeared at one time instead of gradually adding text to the box in increments as the method executed.So it FEELS like any time a method is actually running, the JavaFX scene simply freezes until the method is done running. And it doesn't matter if I change the progress bars value directly or put it into its own method which gets called throughout the execution of the regex method ... either way, nothing actually happens on the form until the software is done executing all of the procedures called and then it comes back to a "resting" state...

I tried simplifying it by making a single method that does two things ... it updates the progress bar and then it waits for 1 second. Then it increments a variable then updates the progress bar, then waits a second, thinking to myself that 1 second pause would give it time to update the progress bars value but even that little method would not work.

Here is the test method I created:

private void testProgressBar() {
for(int x = 0;x<10;x++) {
progressBar.setProgressBar(.1*(x+1));
try {
sleep(1000);
}
catch(InterruptedException e) {
e.printStackTrace();
}
}
}

Even that little piece of code will not actually show any changes in the progress bar until after its done looping at which point, the progress bar is filled to 100%, but I never see the first 9 changes in the progress bar within that for next loop.

View Replies View Related

Dice Game - Invoking Method In Other Method Of Same Class

Feb 26, 2015

I am currently working on a dice game. I have a private method called rollDice and it performs the action of rolling two dice. For my project, I need to create another method called playerRolls and I am supposed to invoke the rollDice method in the playerRolls method and perform actions based off of that. My question right now is how do I invoke a method into another method of the same class?

View Replies View Related

Game Logic - Run Something In Main Method When JButton Is Pressed

Apr 11, 2014

I want to run a few things in my main when a JButton is pressed but can't work out the best way to do it. Here's the code in the main.

public static void main(String[] args) throws FileNotFoundException, ParseException, InterruptedException{
Map m = new Map("defaultMap");
GameLogic g = new GameLogic("defaultMap");
GodsEyeView gev = new GodsEyeView(g, m);
gev.initialRun();

//Want to run this when a button is pressed.
HumanUser h = new HumanUser(g);
playerGUI gui = new playerGUI(h);
gui.run();
gev.run();
}

View Replies View Related

Java Game - Breaking Down A Method To Smaller Methods And Where To Call

Aug 6, 2014

I have a question about a method I have. In my game, I had a move method to move my player left and right, and originally this method was huge, as it also took care checking collisions and a few other things. I broke it up a bit and put the collisions in their own methods and call them from again another method... Here is an extract which I hope illustrates my point:

private static final double MOVE_SPEED = 0.2;
private static final double MAX_MOVE_SPEED = 3.5;
private static final double STOP_SPEED = 0.18;
private double xPos;
private double yPos;

[Code] .....

Something I thought might be a good idea is to check the direction collision when im doing the calculations for that direction:

if(moveLeft) {
dx -= MOVE_SPEED;
(dx < -MAX_MOVE_SPEED) {
dx = -MAX_MOVE_SPEED;
}
checkLeft();
}

But then I would also need to check it when I'm slowing down the left movement:

if(dx < 0.0) {
dx += STOP_SPEED;
if(dx > 0.0) {
dx = 0.0;
}
checkLeft();
}

Then I thought instead i can check it after both of these steps:

if(moveLeft || dx < 0.0) {
checkLeft();
}

I guess my question is quite general: How much is acceptable to break up a method? How many chains of method calls is acceptable? Is it ok to call the same method from different nearby places?

View Replies View Related

Java Game Errors - No Suitable Method Found For Intersect JButton

Apr 9, 2014

I am receiving two errors that I'm not sure how to fix. The first is illegal start of expression at line

"public void actionPerformed(ActionEvent e)"

and no suitable method found for intersect JButton at line

"if(blocker01.getBounds().intersects(r_wall))" .
 
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
 public class gamePanel01 extends JPanel implements KeyListener {
character ch1 = new character("Hero");

[Code] ....

View Replies View Related

JSF :: Updating Session Value

Apr 29, 2014

I am using JSF2 with Primefaces. Here is my business requirement-Hidden field on JSF page should take the value from the session object that is set in managed bean. Session object is updated every time when the user submits the page. I am able to update the session object in the managed bean and able to get the value in the hidden field first time and after that i see the same value in the hidden field even though session object has different value. Here is the hidden field: <h:inputHidden id="xyz" value="xyz"/> i tried using sessionScope but still didn't work.

View Replies View Related

Updating Value In JTextPane

Feb 20, 2015

I have a jTextPane set up and a panel with radioButtons. My jTextPane displays the contents of a text file I have chosen. The 3rd line, 4th index, displayed in my jTextPane specifies a value of type int. When I click my radioButton, I would like that value to increase by 1. So far, I have the following code. I tried to pane.setText(value + 1), but that doesn't seem to work. How do I update the value and display the updated value in jTextPane?

My code :
 
private final ActionListener actionListen = new ActionListener() {  
for(String line: pane.getText().split("")){     String lineThree = line[3];    
int value =  lineThree.charAt(4);     if(radioButton.isSelected()){      
pane.setText(value+1);     }   }};

View Replies View Related

Interface Not Updating Properly

Mar 20, 2015

The program runs well , it adds the applet but it dosn't update the interface unless I press "_"(Minimize) . To be more clear , the object paints a spring wich goes through 4 stages , it is added to the JFrame but it dosn't uptade until I minimize the frame , that is when it goes to the next stage .

The main class which calls the spring to be added to the frame :

public class principal implements ActionListener ,Runnable{
JTextField field;
JFrame frame;
private class Action implements ActionListener {
public void actionPerformed(ActionEvent event) {
  frame.repaint();

[Code] .....

View Replies View Related

GUI JComboBox With Updating Jlabel

Oct 18, 2014

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

[Code]....

I am trying to Make A GUI which has a Jcombo box i also want it to have a jlabel that up dates depending on which option the user selects from the JcomboBox

for exampl if i select lion i want it to say you chose lion on the Jlabel and if i choose ostrich i want it to say ostrich and so on

View Replies View Related

JSF :: Updating View From AJAX

Sep 26, 2014

I have two images. I want to be able to click them and kick off a call to a listener in Java to change a value in the bean. I also want the view to update my dropdown (labeled "menuModel") to either be rendered or not, depending on which image I click. Alternatively, I would be fine with the dropdown simply being disabled and enabled for the same criteria.

So far, the listener kicks off fine, and the value gets updated correctly in the bean. However, the view never gets updated. I have tried this a hundred different ways, but nothing seems to work. If I hit refresh on my browser, the view updates. But I want it to do it automatically.

I am using standard JSF 2.1.

<div style="font-family: Verdana; font-size: 10pt; color: #FFFFFF">
<h2>Calibrations</h2>
<h:form id="tunerSelectionForm" style="color: #000000">
<h:commandLink>

[Code] .....

View Replies View Related

Why If Statement Isn't Working Correctly

Apr 23, 2015

I am building a program that when you enter 1. it allows you to setup an item. However running my code my second if statement runs through.

import java.util.Scanner;
public class InventorySystem {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int count=0;
int inputEntered=0;
int numberOfItems=0;
double cost=0.00;
String item;
String description;
 
[code]...

View Replies View Related

JComboBox Is Not Visually Updating

Jun 15, 2014

I have loaded the combo box at starting of program.When i am adding the element to combo box through database it's not updating visually.But the inserted data is successfully loaded in List.

void update_Attan() {
DefaultComboBoxModel nm = new DefaultComboBoxModel(new StudentMethods().update_combo_AttendanceType());
cmbStdAttType.setModel(nm);
}

View Replies View Related

Array Not Updating As A Heap?

Sep 25, 2014

When I add an element to my array, I have to make sure that it stays a heap, ie every child is smaller than its parent. However the method that I am using for this, trickling up, is not updating the elements properly, it pretty much just leaves is as is.

Here is the relevant code:

public class MaxIntHeap {
int[] array;
int actualSize = 0;
public MaxIntHeap(){
array = new int[20];

[code].....

View Replies View Related

Swing/AWT/SWT :: Why ProgressBar Not Updating

Aug 14, 2014

Why the Progress Bar is not Working in Second attempt?When i am Invoking Below Method on actionPerformed at first attempt its Working Fine but After that Its Not Working at all....

void initWait() {
go.setEnabled(false);
browse.setEnabled(false);
choice.setEnabled(false);
wait.setVisible(true);
wait.setMinimum(0);
wait.setMaximum(Info.getMp3().length);
System.out.println(Info.getMp3().length);
wait.setStringPainted(true);

[code]...

for a better Understand see this Mp3Arranger.jar or see the Whole Project SourceCode

View Replies View Related

How To Read A File Correctly

Feb 13, 2014

So i am creating a File object which has a text file passed to it. I then try to do logic with it using a BufferedReader. However, I get a FileNotFoundException on the using my code below. The Error is on the BufferedReader line. I

Java Code: System.out.println("--Reading text file--");
File file = getFile(c,fileName) // Returns a File object.
System.out.println(file); // Shows me the file is looking correct. Displays contents to console.
BufferedReader br = new BufferedReader(new FileReader(file));
System.out.println("BUFFERED");
while((line = br.readLine()) != null) {
try {
// Do Logic
}
catch(Exception ex){
ex.printStackTrace();
}
br.close(); mh_sh_highlight_all('java');

View Replies View Related

If Else / Switch Not Outputting Correctly

Jan 27, 2014

Trying to learn switch statements. Can't figure out what I am doing wrong.

java Code:

import java.util.Scanner;
public class Ok1 {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);

[code]...
When I run, it makes me enter letter = null and it wont output correctly.

View Replies View Related

Updating Time In Java

Oct 22, 2014

My program is working fine. When I executes it, it shows me this:

The clock is 54 minutes over 23 (+41 seconds.

and when i press ENTER, it shows me this:

23:54:41

But then it won't show me the update. I want to update the time, for example when I started the execution the time was 23:54:41 but it must show me something like 23:54:45, because I need the current time.

I have searched the whole internet about this but I don't know how to use the "Date.update ();".

Here is my code

package p2;

import java.util.Calendar;
import java.util.Date;
import javax.swing.JOptionPane;
public class Time {
public void myTime() {
Calendar cal = Calendar.getInstance();

[Code] ....

View Replies View Related

Opoly Game - Goal Of The Game Is To Reach Or Exceed Reward Value 1000

Mar 12, 2015

Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.

Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.

In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.

Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions. Thus if the board size is 10, then this board drawing:

**o******

means that the player is at location 2 on the board.

Here are the other Opoly game rules:

If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.

If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).

If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,

Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.

Here is the driver class for the game:

import java.util.*;
public class OpolyDriver{
public static void main(String[] args){
System.out.println("Enter an int > 3 - the size of the board");
Scanner s = new Scanner(System.in);
int boardSize = s.nextInt();

[Code] ....

heres the methods:

REQUIRED CODE STRUCTURE: Your Opoly class must include the following methods (in addition to the Opoly constructor) and must implement the method calls as specified:

playGame - The top-level method that controls the game. No return value, no parameters. Must call drawBoard, displayReport, spinAndMove, isGameOver.

spinAndMove - spins the spinner and then advances the piece according to the rules of the game. No return value, no parameters. Must call spin and move.

spin - generates an integer value from 1 to 5 at random- all equally likely. Returns an integer, no parameters.

move - advances the piece according to the rules of the game. No return value, takes an integer parameter that is a value from 1 to 5.

isGameOver - checks if game termination condition has been met. Returns true if game is over, false otherwise. No parameters.

drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward. No return value, no parameters.

displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward. No return value, no parameters.

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

JSF :: Application Scoped Data Updating

Feb 18, 2015

I have an application scoped and i want to edit it from request scoped data. I use this code but application scoped data are not updating. What i am doing wrong?

Application Scoped Data

@ManagedBean
@ApplicationScoped
public class ApplicationData {
protected String contactEmail;
public String getContactEmail() {
return contactEmail;

[Code] ....

View Replies View Related

Write Correctly Border And Gravity

Sep 27, 2014

I want to write simple game. Why if I press button UP and RIGHT it not move diogonally, may be it have special code. And how I need to write correctly border and gravity?

public class Main {
public static void main(String args[]) {
JFrame frame = new JFrame("Stickman");
Ground ground = new Ground();
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setSize(710, 480);

[code]....

View Replies View Related

GCanvas In ACM Graphics Not Working Correctly

Mar 25, 2014

I am trying to implement a game using the ACM graphics. For the game, I am trying to make the main frame a Grid of Cells.I made a Grid class which extends GCanvas:

import acm.graphics.GCanvas;
public class Grid extends GCanvas{
private final static int WIDTH = 300;
private final static int HEIGHT = 300;
private final int DIMENSION = 5;
Cell[][] grid;

[code]....

View Replies View Related

New Instance Variable Values Not Updating

May 6, 2015

Alright, I have a JavaFX gui that is creating a new instance of data calculation to graph in a chart; however, the data is not updating each time the Platform.runLater() feature executes. Each time an event occurs, a new instance with the same variable name occurs. I use to get methods to retrieve the data I want, so shouldn't the values update each time the new instance is created? This is a very condensed version of what happens with the event, but this is what is not working correctly.

Event:
solarPlot = new SolarTracker();
solarPlot.getElevation();
solarPlot.getAzimuth();
Class constructor :
public SolarTracker() {

[Code] .....

View Replies View Related

How To Drag JLabel Correctly Across JFrame

May 26, 2014

I am currently trying to make a method that will enable a jLabel to be dragged across the screen. I want to be able to drag the object pretty much anywhere on the screen(I hope to eventually make a destination for it where it can be dropped but I will get to that later). I have looked on various places on the internet on how to achieve this and the most simple solution does something like this:

Java Code:

jLabel6.setText("jLabel6");
jLabel6.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(java.awt.event.MouseEvent evt) {
jLabel6MouseMoved(evt);
}
});
private void jLabel6MouseDragged(java.awt.event.MouseEvent evt) {
x = evt.getX();

[Code]...

This actually works somewhat but it is very faulty. For example the jLabel keeps appearing and reappearing as I drag it. Furthermore when I drag it I can see a duplicate Jlabel being dragged as well in the top left hand screen. So how might I fix this?

View Replies View Related







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