0% found this document useful (0 votes)
4 views5 pages

JavaFX User Form and Calculator

Uploaded by

rohansain.mca
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

JavaFX User Form and Calculator

Uploaded by

rohansain.mca
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Simple JavaFX Application

[Link]

package javafxa1demo1;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class JavaFXA1Demo1 extends Application {

@Override
public void start(Stage primaryStage) {
// Label controls
Label idLabel = new Label("ID");
Label nameLabel = new Label("Name");
Label mobLabel = new Label("Mobile Number");
Label genderLabel = new Label("Gender");
Label resultLabel = new Label();

//TextField Controls
TextField idText = new TextField();
TextField nameText = new TextField();
TextField mobText = new TextField();
//Radio Button controls
RadioButton male = new RadioButton("Male");
RadioButton female = new RadioButton("Female");
RadioButton transgender = new RadioButton("Transgender");
ToggleGroup gender = new ToggleGroup();
//Grouping Radio Buttons
[Link](gender);
[Link](gender);
[Link](gender);
[Link](true);
//Button controls
Button submitBtn = new Button("SUBMIT");
Button resetBtn = new Button("RESET");
//Creating Pane
GridPane gp =new GridPane();
//set Pane spacing
[Link](new Insets(15,15,15,15));
[Link](10);
[Link](10);
//adding controls to the pane
[Link](0,idLabel,idText);
[Link](1,nameLabel,nameText);
[Link](2,mobLabel,mobText);
[Link](3, genderLabel,male);
[Link](female,1,4);
[Link](transgender,1,5);
[Link](submitBtn,1,6);
[Link](resetBtn,2,6);

[Link](resultLabel,2,7);

//click event methods for button


[Link](new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
//adding the input field values
String s ="id - "+ [Link]()+" Name - "+[Link]()+" Mobile -
"+[Link]()+" Gender - ";
//finding which radio button was selected
if ([Link]())
s = s+[Link]();
else if ([Link]())
s = s +[Link]();
else
s = s+[Link]();
[Link](s);
}
});
[Link](new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
[Link]("");
[Link]("");
[Link]("");
[Link]("");
}
});

//creating scene with pane


Scene scene = new Scene(gp, 500, 500);
//set the scene to the stage
[Link]("User Details");
[Link](scene);
[Link]();
}
public static void main(String[] args) {
launch(args);
}

Simple Calculator
[Link]

package javafxa2demo1;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class SimpleCalc extends Application {

@Override
public void start(Stage primaryStage) {
Label n1Label = new Label("Number1");
Label n2Label = new Label("Number2");
Label resLabel = new Label("Result");

TextField n1Text = new TextField();


TextField n2Text = new TextField();
TextField resText = new TextField();
[Link](false);

Button addbtn = new Button("ADDITION");


Button mulbtn = new Button("MULTIPLICATION");
Button divbtn = new Button("DIVISION");
Button subbtn = new Button("SUBTRACTION");

[Link](new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
int res;
res = [Link]([Link]()) + [Link]([Link]());
[Link]([Link](res));
[Link]("Addition");
}
});
[Link](new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
int res;
res = [Link]([Link]()) - [Link]([Link]());
[Link]([Link](res));
[Link]("Sutraction");
}
});
[Link](new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
int res;
res = [Link]([Link]()) * [Link]([Link]());
[Link]([Link](res));
[Link]("Multiplication");
}
});
[Link](new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
int res;
res = [Link]([Link]()) / [Link]([Link]());
[Link]([Link](res));
[Link]("Divsion");
}
});
GridPane root = new GridPane();
[Link](new Insets(10,10,10,10));
[Link](10);
[Link](5);
[Link](0,n1Label,n1Text);
[Link](1,n2Label,n2Text);
[Link](2,resLabel,resText);
[Link](3,addbtn,subbtn);
[Link](4,mulbtn,divbtn);
Scene scene = new Scene(root, 500, 250);

[Link]("Simple Calculator");
[Link](scene);
[Link]();
}

public static void main(String[] args) {


launch(args);
}

You might also like