how to retrieve data from multiple JTextField - jtextfield

we are creating a project in netbeans which needs to read data from 3 JTextFields in order for us to use it in equations to solve a problem here the part we already finished:
package combustionofgaseousfuels;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CombustionOfGaseousFuels extends JFrame
{
private JTextField C;
private JTextField H;
private JTextField Excess;
private JTextField Answer;
private JTextField Theo;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
private JPanel panel4;
private JPanel panel5;
private JLabel label1;
private JLabel label2;
private JLabel label3;
private JLabel label4;
private JLabel label5;
private JLabel label6;
private JLabel label7;
private ButtonGroup rad1;
private JRadioButton ORSAT;
private JRadioButton WET;
private JRadioButton BOTH;
private JRadioButton c4;
private JRadioButton c5;
public CombustionOfGaseousFuels()
{
super("Flue Gas Analyzer");
ORSAT= new JRadioButton("ORSAT Analysis",false);
WET= new JRadioButton("Wet Analysis",false);
BOTH= new JRadioButton("Both",false);
rad1= new ButtonGroup();
rad1.add(ORSAT);
rad1.add(WET);
rad1.add(BOTH);
panel1=new JPanel();
panel1.setLayout(new GridLayout(1,3));
panel1.add(ORSAT);
panel1.add(WET);
panel1.add(BOTH);
label1= new JLabel("Enter the Number of Carbon and Hydrogen in Your Fuel:");
label2= new JLabel("C:");
label3= new JLabel("H:");
label4= new JLabel("How Much is the %Excess Air?");
label5=new JLabel("Your Flue Gas Analysis is:");
label6=new JLabel("The Theoretical O2 is:");
label7=new JLabel("What Flue Gas Analysis Do You Want?");
C=new JTextField(5);
C.addActionListener(
new ActionListener(){
#Override
public void actionPerformed(ActionEvent event)
{
int carbon;
carbon= Integer.parseInt( ( (JTextField)
event.getSource()).getText());
H=new JTextField(5);
H.addActionListener(
new ActionListener(){
#Override
public void actionPerformed(ActionEvent event)
{
int hydrogen;
hydrogen=Integer.parseInt(((JTextField)
event.getSource()).getText());
Excess= new JTextField(5);
Excess.addActionListener(
new ActionListener(){
#Override
public void actionPerformed(ActionEvent event)
{
int excess;
excess=Integer.parseInt(((JTextField)
event.getSource()).getText());
{
if (ORSAT.isSelected()){
//double c = Integer.parseInt( carbon );
//double h = Integer.parseInt( hydrogen );
//double x = Integer.parseInt( excess );
double tc = (carbon*1);
double th = (hydrogen*1);
double tx = (excess/100);
double theo = tc + (th/4);
double xs = tx * theo;
double osupplied = (1+ tx)* theo;
double n = 3.761904762 * osupplied;
double total = (tc) + xs + n;
double carbondioxide = ((tc)/ total)*100;
double nitrogen = (n/ total)*100;
double oxygen = (xs/total)*100;
Answer.setText(String.valueOf(total));
}
}
}
});
}
});
}
});
Answer=new JTextField(10);
Answer.setEditable(false);
Theo=new JTextField(10);
Theo.setEditable(false);
Container project=getContentPane();
project.setLayout(new GridLayout(15,1));
project.add(label1);
project.add(label2);
project.add(C);
project.add(label3);
project.add(H);
project.add(label4);
project.add(Excess);
project.add(label7);
project.add(panel1);
project.add(label5);
project.add(Answer);
project.add(label6);
project.add(Theo);
setSize (400,300);
setVisible(true);
}
public static void main(String[] args)
{
CombustionOfGaseousFuels analyzer=new CombustionOfGaseousFuels();
analyzer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
There is no error in the codes but when we try to run it, it shows some errors, .please help us in pursuing our project.

public class CombustionOfGaseousFuels extends JFrame
{
private JTextField C;
private JTextField H;
private JTextField Excess;
private JTextField Answer;
private JTextField Theo;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
private JPanel panel4;
private JPanel panel5;
private JLabel label1;
private JLabel label2;
private JLabel label3;
private JLabel label4;
private JLabel label5;
private JLabel label6;
private JLabel label7;
private ButtonGroup rad1;
private JRadioButton ORSAT;
private JRadioButton WET;
private JRadioButton BOTH;
private JRadioButton c4;
private JRadioButton c5;
public CombustionOfGaseousFuels()
{
super("Flue Gas Analyzer");
ORSAT= new JRadioButton("ORSAT Analysis",false);
WET= new JRadioButton("Wet Analysis",false);
BOTH= new JRadioButton("Both",false);
rad1= new ButtonGroup();
rad1.add(ORSAT);
rad1.add(WET);
rad1.add(BOTH);
panel1=new JPanel();
panel1.setLayout(new GridLayout(1,3));
panel1.add(ORSAT);
panel1.add(WET);
panel1.add(BOTH);
label1= new JLabel("Enter the Number of Carbon and Hydrogen in Your Fuel:");
label2= new JLabel("C:");
label3= new JLabel("H:");
label4= new JLabel("How Much is the %Excess Air?");
label5=new JLabel("Your Flue Gas Analysis is:");
label6=new JLabel("The Theoretical O2 is:");
label7=new JLabel("What Flue Gas Analysis Do You Want?");
C=new JTextField(5);
H=new JTextField(5);
Excess= new JTextField(5);
C.addActionListener(
new ActionListener(){
#Override
public void actionPerformed(ActionEvent event)
{
final int carbon;
carbon= Integer.parseInt( ( (JTextField)
event.getSource()).getText());
H.addActionListener(
new ActionListener(){
#Override
public void actionPerformed(ActionEvent event)
{
final int hydrogen;
hydrogen=Integer.parseInt(((JTextField)
event.getSource()).getText());
Excess.addActionListener(
new ActionListener(){
#Override
public void actionPerformed(ActionEvent event)
{
int excess;
excess=Integer.parseInt(((JTextField)
event.getSource()).getText());
{
if (ORSAT.isSelected()){
//double c = Integer.parseInt( carbon );
//double h = Integer.parseInt( hydrogen );
//double x = Integer.parseInt( excess );
double tc = (carbon*1);
double th = (hydrogen*1);
double tx = (excess/100);
double theo = tc + (th/4);
double xs = tx * theo;
double osupplied = (1+ tx)* theo;
double n = 3.761904762 * osupplied;
double total = (tc) + xs + n;
double carbondioxide = ((tc)/ total)*100;
double nitrogen = (n/ total)*100;
double oxygen = (xs/total)*100;
Answer.setText(String.valueOf(total));
}
}
}
});
}
});
}
});
Answer=new JTextField(10);
Answer.setEditable(false);
Theo=new JTextField(10);
Theo.setEditable(false);
Container project=getContentPane();
project.setLayout(new GridLayout(15,1));
project.add(label1);
project.add(label2);
project.add(C);
project.add(label3);
project.add(H);
project.add(label4);
project.add(Excess);
project.add(label7);
project.add(panel1);
project.add(label5);
project.add(Answer);
project.add(label6);
project.add(Theo);
setSize (400,300);
setVisible(true);
}
public static void main(String[] args)
{
CombustionOfGaseousFuels analyzer=new CombustionOfGaseousFuels();
analyzer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

You should define H and Excess outside the C.addActionListener. Just try putting
H=new JTextField(5);
Excess= new JTextField(5);
just after
C=new JTextField(5);

Related

Using a static nested class insted of toString

I have this task:
"We do not want to rely on us Currency their toString() for how a currency is displayed in list our. We will be able to set this up ourselves.
Create a static nested class called "Currency Cell" in ValutaOversikController as extender List Cell <Value>.
Override methods updateItem (Currency and Currency, boolean empty).
Set how a currency should be presented in the list e.g. "Country - Currency Code"
Then put CellFactory for our ListView, which returns an instance of the new Currency Cell class."
I started to make the last method in Controller, but don't know if this is correct. As of now this is what I have:
public class Controller {
#FXML
private ComboBox<Valuta> listeMedValutaerEn, listeMedValutaerTo;
#FXML
private ComboBox<Sorteringen> listeMedSortering;
#FXML
private TextField textFieldValutaerEn, textFieldValutaerTo;
#FXML
private ImageView imageViewValutaerEn, imageViewValutaerTo;
#FXML
public void initialize() {
listeMedValutaerEn.setItems(DataHandler.hentValutaData());
listeMedValutaerTo.setItems(DataHandler.hentValutaData());
listeMedSortering.setItems(DataHandler.hentSorteringsData());
listeMedValutaerEn.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Valuta>() {
#Override
public void changed(ObservableValue<? extends Valuta> observableValue, Valuta gammelValuta, Valuta nyValuta) {
fyllUtValutaEn(nyValuta);
}
});
listeMedValutaerTo.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Valuta>() {
#Override
public void changed(ObservableValue<? extends Valuta> observableValue, Valuta gammelValuta, Valuta nyValuta) {
fyllUtValutaTo(nyValuta);
}
});
listeMedSortering.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Sorteringen>() {
#Override
public void changed(ObservableValue<? extends Sorteringen> observableValue, Sorteringen gammelSortering, Sorteringen nySortering) {
sortere(nySortering);
}
});
}
private void sortere(Sorteringen nySortering) {
ObservableList<Valuta> valutaSomSkalSorteres = DataHandler.hentValutaData();
CompareToValuta sortere = new CompareToValuta(nySortering.getSorteringsKode());
Collections.sort(valutaSomSkalSorteres, sortere);
listeMedValutaerEn.setItems(valutaSomSkalSorteres);
listeMedValutaerTo.setItems(valutaSomSkalSorteres);
}
private void fyllUtValutaEn(Valuta enValuta) {
if (enValuta != null) {
Image flaggEn = new Image("https://www.countryflags.io/" + enValuta.getLandskode() + "/shiny/64.png");
imageViewValutaerEn.setImage(flaggEn);
}
}
private void fyllUtValutaTo(Valuta enValuta) {
if (enValuta != null) {
Image flaggTo = new Image("https://www.countryflags.io/" + enValuta.getLandskode() + "/shiny/64.png");
imageViewValutaerTo.setImage(flaggTo);
}
}
#FXML
private void buttonBeregn(ActionEvent event) {
Integer valutaAntall = Integer.valueOf(textFieldValutaerEn.getText());
double valutaNrEn = listeMedValutaerEn.getSelectionModel().getSelectedItem().getValutakurs();
double valutaNrTo = listeMedValutaerTo.getSelectionModel().getSelectedItem().getValutakurs();
double valutaResultat = valutaAntall * (valutaNrEn / valutaNrTo);
textFieldValutaerTo.setText(String.valueOf(valutaResultat));
}
private static ListCell<Valuta> ValutaCelle() {
ListCell<Valuta> tja = new ListCell<>();
return tja;
}
}
Class DataHandler:
public class DataHandler {
private final static ObservableList<Valuta> valutaListe = FXCollections.observableArrayList();
private final static ObservableList<Sorteringen> sorteringsListe = FXCollections.observableArrayList();
public static ObservableList<Sorteringen> hentSorteringsData() {
if (sorteringsListe.isEmpty()) {
sorteringsListe.add(new Sorteringen("Sortere alfabetisk på land synkende", 1));
sorteringsListe.add(new Sorteringen("Sortere alfabetisk på land stigende", 2));
sorteringsListe.add(new Sorteringen("Sortere på valutakode, stigende", 3));
sorteringsListe.add(new Sorteringen("Sortere på valutakode, synkende", 4));
}
return sorteringsListe;
}
public static ObservableList<Valuta> hentValutaData() {
if (valutaListe.isEmpty()) {
valutaListe.addAll(genererValutaData());
}
return valutaListe;
}
private static ArrayList<Valuta> genererValutaData() {
File kilden = new File("src/no/hiof/aleksar/oblig5/valutakurser.csv");
ArrayList<Valuta> valutaerFraFiler = lesFraCSVFil(kilden);
return valutaerFraFiler;
}
private static ArrayList<Valuta> lesFraCSVFil(File filSomLesesFra) {
ArrayList<Valuta> valutaerFraFil = new ArrayList<>();
try (BufferedReader bufretLeser = new BufferedReader(new FileReader(filSomLesesFra))) {
String linje;
while( (linje = bufretLeser.readLine()) != null ){
String[] deler = linje.split(";");
Valuta enValuta = new Valuta(deler[0], deler[1], deler[2], Double.parseDouble(deler[3]));
valutaerFraFil.add(enValuta);
}
} catch (IOException e) {
System.out.println(e);
}
return valutaerFraFil;
}
}

JavaFX run a method once a specified key is pressed

I am trying to run a method in a controller class specified to a particular task, once a specified key is pressed using KeyListener. But i'm unable to detect the keypress and invoke the java.awt.event keyPressed method. My code is as follows :
public class POSController implements KeyListener {
#Override
public void keyPressed(java.awt.event.KeyEvent e) {
if (e.getKeyCode() == com.sun.glass.events.KeyEvent.VK_F1) {
try {
paymentAction();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
What could have gone wrong? Thanks in advance.
Here is the minimal executable example of the problem.
public class POSController implements KeyListener {
#FXML
private TableView<Product> productTableView;
#FXML
private TableView<Item> listTableView;
#FXML
private MenuItem logoutItem, profile;
#FXML
private javafx.scene.image.ImageView backImage;
#FXML
private MenuButton menuButton;
#FXML
private TableColumn<Item, String> itemColumn;
#FXML
private ComboBox<String> clientId, paymentMethod;
#FXML
private TableColumn<Item, Double> priceColumn, totalColumn, discountPercentageColumn, amountColumn;
#FXML
private TableColumn<Item, Integer> quantityColumn;
#FXML
private TableColumn<Product, String> productColumn;
#FXML
private TextField searchField,discountPercentage,productField,priceField,quantityField,vatPercentage,subTotalField,discountField,totalVatField,vatField,netPayableField,totalDiscountField;
#FXML
private TextField ;
#FXML
private TextField ;
#FXML
private TextField ;
#FXML
private TextField ;
#FXML
private TextArea descriptionArea;
#FXML
private Button addButton, removeButton, paymentButton, resetTableButton, resetButton;
#FXML
private Label quantityLabel, errorLabel, userName, backLabel;
#FXML
private ObservableList<Item> ITEMLIST;
public static Scene paymentScene;
private double xOffset = 0;
private double yOffset = 0;
public static double finalNetPayablePrice = 0.0;
public static double finalSubTotalPrice = 0.0;
public static double finalVat = 0.0;
public static double finalDiscount = 0.0;
public static String clientName = null;
public static String selectedPaymentMethod = null;
public static List<String> itemNames = new ArrayList<>();
public static List<Double> itemDiscounts = new ArrayList<>();
public static List<String> prices = new ArrayList<>();
public static List<String> quantities = new ArrayList<>();
public static List<String> subTotals = new ArrayList<>();
public static ObservableList<Item> itemList;
public static List<String> columnItemData = new ArrayList<>();
public static List<String> columnQuantityData = new ArrayList<>();
#FXML
private void initialize() throws SQLException, ClassNotFoundException, IOException {
ObservableList<Product> productsData = ProductDAO.searchGoodProducts(app.values.getProperty("STATUS_TYPE1"));
populateProducts(productsData);
}
#FXML
private void populateProducts(ObservableList<Product> productData) throws ClassNotFoundException {
productTableView.setItems(productData);
}
#Override
public void keyTyped(java.awt.event.KeyEvent e) {
}
#Override
public void keyPressed(java.awt.event.KeyEvent e) {
if (e.getKeyCode() == java.awt.event.KeyEvent.VK_F1) {
try {
paymentAction();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
#Override
public void keyReleased(java.awt.event.KeyEvent e) {
}
#FXML
public void paymentAction() throws Exception {
if (validateInputsForPayment()) {
Payment payment = new Payment();
FXMLLoader loader = new FXMLLoader((getClass().getResource(app.values.getProperty("INVOICE_VIEW_LOCATION"))));
Parent root = loader.load();
Stage stage = new Stage();
root.setOnMousePressed((MouseEvent e) -> {
xOffset = e.getSceneX();
yOffset = e.getSceneY();
});
root.setOnMouseDragged((MouseEvent e) -> {
stage.setX(e.getScreenX() - xOffset);
stage.setY(e.getScreenY() - yOffset);
});
Scene scene = new Scene(root);
stage.initModality(Modality.APPLICATION_MODAL);
stage.initStyle(StageStyle.UNDECORATED);
stage.setScene(scene);
this.paymentScene = scene;
stage.showAndWait();
}
}
You shouldn't be using java.awt.event.KeyListener for a JavaFX application. JavaFX has its own set of event API.
Assuming that POSController is a controller class for a particular FXML:
public class POSController {
#FXML private BorderPane root; // Or any other Node from FXML file
#FXML private void initialize() {
javafx.event.EventHandler<javafx.scene.input.KeyEvent> handler = event -> {
if (event.getCode() == javafx.scene.input.KeyCode.F1) {
try {
paymentAction();
} catch (Exception e1) {
e1.printStackTrace();
}
}
};
// I'm using root to get scene, but any node would be fine
if (root.getScene() != null) {
root.getScene().addEventHandler(javafx.scene.input.KeyEvent.KEY_PRESSED, handler);
}
else {
root.sceneProperty().addListener((obs, oldScene, newScene) -> {
if (newScene != null) {
root.getScene().addEventHandler(javafx.scene.input.KeyEvent.KEY_PRESSED, handler);
}
});
}
}
}
This will add the key event to the Scene. If you do not need to apply this event scene-wide, then you can add the event handler at other appropriate nodes.
Update
If there are any input controls in the scene, then you may need to use setEventFilter() instead of setEventHandler(). This is because those controls are probably going to consume the key event during the event bubbling phase.

Having trouble retrieving value from tableview

I'm having having trouble getting a correct output from tableview. I'm using a button to set one item from tableview to a label. However, it prints "StringProperty [Value pineapples]" where I would like it to be just "pineapples".
The tableview gives them correctly.
public class ProductListController implements Initializable {
#FXML public TableView<Model> tableview ;
#FXML private TableColumn<Model, Number> ProductID;
#FXML private TableColumn<Model, String> ProductName;
#FXML private TableColumn<Model, Number> ProductPrice;
#FXML private Label lblProduct;
#FXML private Label lblPrice;
#FXML
private void btnActionShow(ActionEvent event) {
assert tableview !=null : " ";
ProductID.setCellValueFactory(cellData -> cellData.getValue().ProductIDProperty());
ProductName.setCellValueFactory(cellData -> cellData.getValue().ProductNameProperty());
ProductPrice.setCellValueFactory(cellData -> cellData.getValue().ProductPriceProperty());
buildData();
}
private ObservableList<Model> data;
public void buildData(){
data = FXCollections.observableArrayList();
try{
Connection conn = DriverManager.getConnection
("jdbc:derby://localhost:1527/Stock", "*****", "*****");
Statement stmt = conn.createStatement();
String SQL = "SELECT * FROM PRODUCTS";
ResultSet rs = stmt.executeQuery(SQL);
while (rs.next()) {
Model mod = new Model();
mod.ProductID.set(rs.getInt("ID"));
mod.ProductName.set(rs.getString("NAME"));
mod.ProductPrice.set(rs.getInt("SELL_PRICE"));
data.add(mod);
}
tableview.setItems(data);
}
catch ( SQLException err) {
System.out.println(err.getMessage() );
}
}
//Button to fetch data from Tableview. Sets the data not the way I want.
#FXML
private void btnConfirmAction(ActionEvent event) {
Model model = tableview.getSelectionModel().getSelectedItem();
String prd;
prd = model.getProductName().toString();
lblProduct.setText(prd);
}
#FXML
private void btnNextAction(ActionEvent event) {
try{
FXMLLoader loader = new FXMLLoader(getClass().getResource("/appl/Discount.fxml"));
Parent parent = loader.load();
DiscountController discountcontr = loader.getController();
discountcontr.setProduct(tableview.getSelectionModel().getSelectedItem().getProductName().toString());
Stage stage = new Stage();
Scene scene = new Scene(parent);
stage.setScene(scene);
stage.show();
}
catch(IOException e){
}
}
#Override
public void initialize(URL url, ResourceBundle rb) {
}
}
Model
public class Model {
public SimpleIntegerProperty ProductID = new SimpleIntegerProperty();
public SimpleStringProperty ProductName = new SimpleStringProperty ();
public SimpleIntegerProperty ProductPrice = new SimpleIntegerProperty();
private final SimpleBooleanProperty Checked = new SimpleBooleanProperty(false);
public SimpleBooleanProperty checkedProperty() {
return this.Checked;
}
public java.lang.Boolean getChecked() {
return this.checkedProperty().get();
}
public void setChecked(final java.lang.Boolean checked) {
this.checkedProperty().set(checked);
}
public SimpleIntegerProperty getProductID() {
return ProductID;
}
public SimpleStringProperty getProductName() {
return ProductName;
}
public SimpleIntegerProperty getProductPrice() {
return ProductPrice;
}
Since getProductName() returns a SimpleStringProperty, you need to retrieve the String from it using the get(). Just use :
String prd = model.getProductName().get();
Your model is implemented incorrectly. You should use the following pattern:
public class Model {
private SimpleStringProperty productName = new SimpleStringProperty();
public SimpleStringProperty productNameProperty() {
return productName ;
}
public final String getProductName() {
return productNameProperty().get();
}
public final void setProductName(String productName) {
productNameProperty().set(productName);
}
}
and similarly for the other properties.
If you use the e(fx)clipse plugin, you can generate the methods automatically from the property definition by right-clicking, choosing "Source" and then "Generate JavaFX Getters and Setters". I think NetBeans has similar functionality.

Service is terminated when click on TableView

I have the following problem. When I press the Button, I execute a Service that parses an html page and puts the results in a table. When I click on the table, while the Service is running, the Service will be terminated.
Can someone help me with this problem?
Here is my controller class:
public class ProxySearchController implements Initializable {
private Scene scene;
#FXML
private Button btn_refresh;
#FXML
private TableView<ProxyResult> tbl_results;
#FXML
private ProgressBar pb_search;
#FXML
private TableColumn<ProxyResult, String> column_ip;
#FXML
private TableColumn<ProxyResult, Integer> column_port;
#FXML
private TableColumn<ProxyResult, Locale> column_locale;
#FXML
private TableColumn<ProxyResult, String> column_anonymity;
#FXML
private TableColumn<ProxyResult, Boolean> column_google;
#FXML
private TableColumn<ProxyResult, Boolean> column_https;
#FXML
private TableColumn<ProxyResult, String> column_lastchecked;
#FXML
private TableColumn<ProxyResult, Long> column_response;
private ObservableList<ProxyResult> data = FXCollections.observableArrayList();
/*
* (non-Javadoc)
*
* #see javafx.fxml.Initializable#initialize(java.net.URL, java.util.ResourceBundle)
*/
#Override
public void initialize(URL location, ResourceBundle resources) {
tbl_results.setItems(data);
tbl_results.getSelectionModel().setCellSelectionEnabled(true);
Clipboard clipboard = Clipboard.getSystemClipboard();
// add listner to your tableview selecteditemproperty
tbl_results.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ProxyResult>() {
#Override
public void changed(ObservableValue observable, ProxyResult oldValue, ProxyResult newValue) {
ObservableList<TablePosition> posList = tbl_results.getSelectionModel().getSelectedCells();
int old_r = -1;
StringBuilder clipboardString = new StringBuilder();
for (TablePosition p : posList) {
int r = p.getRow();
int c = p.getColumn();
Object cell = tbl_results.getColumns().get(c).getCellData(r);
if (cell == null)
cell = "";
if (old_r == r)
clipboardString.append('\t');
else if (old_r != -1)
clipboardString.append('\n');
clipboardString.append(cell);
old_r = r;
}
final ClipboardContent content = new ClipboardContent();
content.putString(clipboardString.toString());
Clipboard.getSystemClipboard().setContent(content);
}
});
column_ip.setCellValueFactory(new PropertyValueFactory<ProxyResult, String>("ip"));
column_port.setCellValueFactory(new PropertyValueFactory<ProxyResult, Integer>("port"));
column_locale.setCellValueFactory(new PropertyValueFactory<ProxyResult, Locale>("locale"));
column_anonymity.setCellValueFactory(new PropertyValueFactory<ProxyResult, String>("anonymity"));
column_google.setCellValueFactory(new PropertyValueFactory<ProxyResult, Boolean>("google"));
column_https.setCellValueFactory(new PropertyValueFactory<ProxyResult, Boolean>("https"));
column_lastchecked.setCellValueFactory(new PropertyValueFactory<ProxyResult, String>("lastChecked"));
column_response.setCellValueFactory(new PropertyValueFactory<ProxyResult, Long>("responseTime"));
}
public void handleSearchButton(ActionEvent event) {
Service<Void> searchWorker = new SearchProxyWorker(pb_search, data);
searchWorker.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
#Override
public void handle(WorkerStateEvent event) {
System.out.println("Tadaaa");
}
});
searchWorker.start();
}
/**
* Set the current scene.
*
* #param scene A scene
*/
public void setScene(Scene scene) {
this.scene = scene;
}
}

JAVAFX game collision

I am making a school project in JAVAFX and I can't figure out how to collide with my 2 objects(bullet and enemy tank). Can someone tell me the right way to do it? I am trying more than 3 weeks... google everything but still not working.
public class TankGame extends Application {
private final static int WIDTH = 800;
private final static int HEIGHT = 600;
private final static Image BACKGROUND_IMAGE = new Image(TankGame.class.getResource("imgs/Tank_back.png").toString());
private final static Image PATRONA = new Image(TankGame.class.getResource("imgs/Tank_patrona.png").toString());
private Animation modelAnimacePatrony;
private Group patrona;
private double smerStrelyX, smerStrelyY;
private Otaceni otaceni = new Otaceni();
private TankHrac tankHrac = new TankHrac();
private TankProtivnik tankProtivnik = new TankProtivnik();
#Override
public void start(Stage primaryStage) {
final ImageView background = new ImageView(BACKGROUND_IMAGE);
final ImageView bullet = new ImageView(PATRONA);
patrona = new Group(bullet);
final Group root = new Group(background, tankHrac, tankProtivnik, patrona);//deti
patrona.setVisible(false);
Scene scene = new Scene(root, WIDTH, HEIGHT); //okno
tankHrac.setTranslateX(50);//defaultni vyskyt modelu
tankHrac.setTranslateY(50);//defaultni vyskyt modelu
tankProtivnik.setTranslateX(350);//defaultni vyskyt modeluProtivnika
tankProtivnik.setTranslateY(150);//defaultni vyskyt modeluProtivnika
smerStrelyX = tankHrac.getTranslateX();
smerStrelyY = tankHrac.getTranslateY()-250;
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
#Override
public void handle(KeyEvent ke) {
/**
* Shooting
*/
if( ke.getCode() == KeyCode.SPACE ) {
if(!patrona.isVisible()){
//patrona.setVisible(true);
shooting(smerStrelyX,smerStrelyY, tankHrac);
}
}
}
});
primaryStage.setTitle("Tank 1.0");
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setResizable(false);
}
public void shooting(double smerStrelyX, double smerStrelyY, TankHrac jakyModelTanku){
patrona.setVisible(true);
modelAnimacePatrony = TranslateTransitionBuilder.create()
.node(patrona)
.fromX(jakyModelTanku.getTranslateX()+30)
.toX(smerStrelyX+30)
.fromY(jakyModelTanku.getTranslateY()+30)
.toY(smerStrelyY+30)
.duration(Duration.seconds(1))
.onFinished(new EventHandler<ActionEvent>(){
#Override
public void handle(ActionEvent t){
modelAnimacePatrony.stop();
patrona.setVisible(false);
}
})
.build();
modelAnimacePatrony.play();
}
here are all source files: https://www.dropbox.com/sh/1iq98jtxh8m06tt/7Y9LQSjfYs

Resources