Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JavaFX button needs doulbe click. I understand where it is happening but unsure how to fix this. This is a temperature converter but it does

JavaFX button needs doulbe click. I understand where it is happening but unsure how to fix this. This is a temperature converter but it does not do anything until the second click. The problem is in my controller since I have this

"public void handleButtonAction(ActionEvent event) {

btnFtoC.setOnAction(new EventHandler() {"

Can someone please help clearify what I have to change in order for this to work.

*************************Controller****************************************

package GUI_HW;

import javafx.event.ActionEvent;

import javafx.event.EventHandler;

import javafx.fxml.FXML;

import javafx.scene.control.Button;

import javafx.scene.control.Label;

import javafx.scene.control.TextField;

public class TempConvert_Controller {

@FXML

public Button btnFtoC;

@FXML

public Button btnCtoF;

@FXML

public TextField txtText;

@FXML

private Label actiontarget;

@FXML

public void handleButtonAction(ActionEvent event) {

btnFtoC.setOnAction(new EventHandler() {

@Override

public void handle(ActionEvent e) {

String Temp = "";

int FtoC;

if ((txtText.getText().isEmpty())) {

FtoC = 0;

actiontarget.setText("Enter Temperature");

} else {

FtoC = Integer.parseInt(txtText.getText());

int celcius = (FtoC-32)*5/9;

Temp = ("Celcius: "+celcius);

actiontarget.setText(Temp);

// input 50, answer 10

}

}

});

btnCtoF.setOnAction(new EventHandler() {

@Override

public void handle(ActionEvent e) {

String Temp = "";

int CtoF;

if ((txtText.getText().isEmpty())) {

CtoF = 0;

actiontarget.setText("Enter Temperature");

} else {

CtoF = Integer.parseInt(txtText.getText());

int fahrenheit = (CtoF*9/5) + 32;

Temp = ("Fahrenheit: "+fahrenheit);

actiontarget.setText(Temp);

// input 50, answer 122

}

}

});

}

}

*************************FXML****************************************

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions