Proj

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

import javafx.application.

Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

public class Proj1 extends Application {

public void start(Stage primaryStage) {

FlowPane root = new FlowPane();


Label l1 = new Label("Name");
TextField t1 = new TextField();
Label l2 = new Label("Gender");
ToggleGroup group = new ToggleGroup();
RadioButton opt1 = new RadioButton("M");
RadioButton opt2 = new RadioButton("F");
opt1.setToggleGroup(group);
opt2.setToggleGroup(group);
Label l3 = new Label("Salary");
TextField t3 = new TextField();
Label l4 = new Label("HOBBY");
CheckBox c1 = new CheckBox("Listening music");
CheckBox c2 = new CheckBox("Playing Games");
CheckBox c3 = new CheckBox("Reading books");
Label l5 = new Label("Summary");
TextArea t4 = new TextArea();
Button b1 = new Button("Save");
Label l6 = new Label("Marital Status");
ToggleGroup group1 = new ToggleGroup();
RadioButton r1 = new RadioButton("Single");
RadioButton r2 = new RadioButton("Married");
RadioButton r3 = new RadioButton("Widow");
RadioButton r4 = new RadioButton("Divorced");
t4.setText(" ");

b1.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
String title = "";
String title2 = "";
if (opt1.isSelected()) {
title = "Mr.";
title2 = "His";
} else if (opt2.isSelected()) {
title = "Ms.";
title2 = "Her";
}
String title3 = "";
if (c1.isSelected()) {
title3 += c1.getText() + ",";
}
if (c2.isSelected()) {
title3 += c2.getText() + "";
}
if (c3.isSelected()) {
title3 += c3.getText() + "";
}
String title4 = "";
if (r1.isSelected()) {
title4 = "Single";
}
if (r2.isSelected()) {
title4 = "Married";
}
if (r3.isSelected()) {
title4 = "Widow";
}
if (r4.isSelected()) {
title4 = "Divorced";
}

String Summary;
Summary = (title + " " + t1.getText() + " " + "is earning Rs." +
t3.getText()
+ " in a month! and " + title2 + " Marital status is " +
title4 + ".." + title2
+ " Hobbies are " + title3);
t4.setText(Summary);
}
});

t1.setOnKeyTyped(new EventHandler<KeyEvent>() {

public void handle(KeyEvent event) {


if (Character.isDigit(event.getCharacter().charAt(0))) {
event.consume();
}
}
});
t3.setOnKeyTyped(new EventHandler<KeyEvent>() {

public void handle(KeyEvent event) {


if (!Character.isDigit(event.getCharacter().charAt(0))) {
event.consume();
}
}
});

root.getChildren().addAll(l1, t1, l2, opt1, opt2, l3, t3, l6, r1, r2, r3,
r4, l4, c1, c2, c3, l5, t4, b1);

Scene scene = new Scene(root, 500, 250);

primaryStage.setTitle("Project 1");
primaryStage.setScene(scene);
primaryStage.show();
}

public static void main(String[] args) {


launch(args);
}

You might also like