javaf, problem...plz help someone...urgent [closed]
- by innovative_aj
i have made a word guessing game, when i click myButton to check if the guessed word is right or wrong, ball1 is moved into the "container" if its right, i want that when i click the button again and if the typed word is right, the 2nd ball should move into the container too... means one ball per correct answer...plz help me someone and provide me with the code that i can implement, its quite urgent...
controller class coding
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package project3;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Circle;
/**
* FXML Controller class
*
* @xxx */
public class MyFxmlController implements Initializable {
@FXML // fx:id="ball1"
private Circle ball1; // Value injected by FXMLLoader
@FXML // fx:id="ball2"
private Circle ball2; // Value injected by FXMLLoader
@FXML // fx:id="ball3"
private Circle ball3; // Value injected by FXMLLoader
@FXML // fx:id="ball4"
private Circle ball4; // Value injected by FXMLLoader
@FXML // fx:id="container"
private Circle container; // Value injected by FXMLLoader
@FXML // fx:id="myButton"
private Button myButton; // Value injected by FXMLLoader
@FXML // fx:id="myLabel1"
private Label myLabel1; // Value injected by FXMLLoader
@FXML // fx:id="myLabel2"
private Label myLabel2; // Value injected by FXMLLoader
@FXML // fx:id="pane"
private StackPane pane; // Value injected by FXMLLoader
@FXML // fx:id="txt"
private TextField txt; // Value injected by FXMLLoader
@Override // This method is called by the FXMLLoader when initialization is complete
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
assert ball1 != null : "fx:id=\"ball1\" was not injected: check your FXML file 'MyFxml.fxml'.";
assert ball2 != null : "fx:id=\"ball2\" was not injected: check your FXML file 'MyFxml.fxml'.";
assert ball3 != null : "fx:id=\"ball3\" was not injected: check your FXML file 'MyFxml.fxml'.";
assert ball4 != null : "fx:id=\"ball4\" was not injected: check your FXML file 'MyFxml.fxml'.";
assert container != null : "fx:id=\"container\" was not injected: check your FXML file 'MyFxml.fxml'.";
assert myButton != null : "fx:id=\"myButton\" was not injected: check your FXML file 'MyFxml.fxml'.";
assert myLabel1 != null : "fx:id=\"myLabel1\" was not injected: check your FXML file 'MyFxml.fxml'.";
assert myLabel2 != null : "fx:id=\"myLabel2\" was not injected: check your FXML file 'MyFxml.fxml'.";
assert pane != null : "fx:id=\"pane\" was not injected: check your FXML file 'MyFxml.fxml'.";
assert txt != null : "fx:id=\"txt\" was not injected: check your FXML file 'MyFxml.fxml'.";
// initialize your logic here: all @FXML variables will have been injected
myButton.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
int count = 0;
String guessed=txt.getText();
boolean result;
result=MyCode.check(guessed);
if(result)
{
ball1.setTranslateX(600);
ball1.setTranslateY(250-container.getRadius());
//ball2.setTranslateX(600);
// ball2.setTranslateY(250-container.getRadius());
}
else
System.out.println("wrong");
}
});
}
}
word guessing logic
public class MyCode {
static String x="Netbeans";
static String y[]={"net","beans","neat","beat","bet"};
//static int counter;
// public MyCode() {
// counter++;
//}
static boolean check(String guessed)
{
int count=0;
boolean result=false;
//counter++;
//System.out.println("turns"+counter);
for(count=0;count<5;count++)
{
if(guessed.equals(y[count]))
{
result=true;
break;
}
}
if(result)
System.out.println("Right");
else
System.out.println("Wrong");
return result;
}
}