HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

JavaFX Scene Builder Tutorial 34 - Calculator JavaFX

31,869 views April 25, 2020 22:46

Watch on YouTube
ChannelCode Amir

Description from the creator

JavaFX Scene Builder Tutorial 34 Calculator JavaFX

Code source here : codebyamir.blogspot.com/

@FXML
private TextField txt_result;
String op ="";
long number1;
long number2;
// First Method
public void Number (ActionEvent ae){
String no = ((Button)ae.getSource()).getText();
txt_result.setText(txt_result.getText()+no);
}

// Second Method
public void Operation (ActionEvent ae){

String operation = ((Button)ae.getSource()).getText();
if (!operation.equals("=")){
if(!op.equals("")){
return;
}
op = operation;
number1 = Long.parseLong(txt_result.getText());
txt_result.setText("");
}else {
if(op.equals("")){
return;
}
number2 = Long.parseLong(txt_result.getText());
calculate(number1, number2, op);
op="";
}
}
// 3 Methode
public void calculate (long n1, long n2, String op){

switch (op){

case "+" : txt_result.setText(n1 + n2 + "");break;
case "-" : txt_result.setText(n1 - n2 + "");break;
case "*" : txt_result.setText(n1 * n2 + "");break;
case "/" :
if (n2 == 0){
txt_result.setText("0");break;
}
txt_result.setText(n1/n2+ "");break;
}
}
Libraries Importing :
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

About this tutorial

Code Amir published this 22:46 video tutorial on April 25, 2020. It has been watched 31,869 times on YouTube.

Channel
Code Amir
Category
Education
Duration
22:46
Published
April 25, 2020
Views
31,869
Likes
260

Tags

Share

Further reading

  • JavaFX Calculator with Java code | DiscoverSDK Blog discoversdk.com

    A JavaFX application defines the user interface container by means of a stage and a scene. The JavaFX Stage class is the top-level JavaFX container. The JavaFX Scene class is the container for all content. In JavaFX, th…

  • How to build a Calculator in JavaFX Part-1 video lecture ... freevideolectures.com

    5.Installing JavaFX Scene Builder; 6.Events with JavaFX Scene Builder; 7.Styling with CSS in JavaFX; 8.How to build a Calculator in JavaFX Part-1; 9.How to build a Calculator in JavaFX Part-2; 10.Create Login Applicatio…

  • Making Calculator in JavaFX (with Source Code) genuinecoder.com

    JavaFX is a wonderful improvement to Java programming language. It includes a wide number of new user interface controls and the ability to add cascade style sheets (CSS), Animations etc. Today, Let’s see how we can bui…

  • Creating Calculator in JavaFX - ZatackCoder zatackcoder.com

    Hello Friends Today I am going to share, how to create Calculator using JavaFX. This is a simple calculator with simple UI where you can Add, Substract, Mutiply, Divide, and calculate Percentage. So here is the code. Ca…

This tutorial in other languages