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

QQQ

This Java code defines a GUI application for registering patient information. It creates a form with fields for a patient's name, address, email, insurance provider, and physician. The form allows submitting a new patient record to a text file or viewing existing records. Buttons are included for submitting, clearing, and displaying the patient records table.

Uploaded by

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

QQQ

This Java code defines a GUI application for registering patient information. It creates a form with fields for a patient's name, address, email, insurance provider, and physician. The form allows submitting a new patient record to a text file or viewing existing records. Buttons are included for submitting, clearing, and displaying the patient records table.

Uploaded by

YEAB XXV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

import java.io.

FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.beans.property.SimpleStringProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

class Patient {

String fname, lname, adress, email, insu, phys;

public Patient(String fname, String lname, String adress, String email, String
insu, String phys) {
this.fname = fname;
this.lname = lname;
this.adress = adress;
this.email = email;
this.insu = insu;
this.phys = phys;
}

public String getFname() {


return fname;
}

public String getLname() {


return lname;
}

public String getAdress() {


return adress;
}

public String getEmail() {


return email;
}

public String getInsu() {


return insu;
}

public String getPhys() {


return phys;
}

}
public class Project101 extends Application {

@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Patient Registration Form");

Label firstNameLabel = new Label("First Name:");


TextField firstNameField = new TextField();
Label lastNameLabel = new Label("Last Name:");
TextField lastNameField = new TextField();
Label dobLabel = new Label("Date of Birth:");
DatePicker dobPicker = new DatePicker();
Label genderLabel = new Label("Gender:");
ToggleGroup t = new ToggleGroup();
RadioButton R1 = new RadioButton("male");
RadioButton R2 = new RadioButton("female");

R1.setToggleGroup(t);
R2.setToggleGroup(t);
Label addressLabel = new Label("Address:");
TextField addressArea = new TextField();
Label phoneLabel = new Label("Phone Number:");
TextField phoneField = new TextField();
Label emailLabel = new Label("Email Address:");
TextField emailField = new TextField();
Label insuranceLabel = new Label("Insurance Provider:");
TextField insuranceField = new TextField();
Label physicianLabel = new Label("Primary Care Physician:");
TextField physicianField = new TextField();
Button submitButton = new Button("Submit");
submitButton.setDefaultButton(true);
Button clearButton = new Button("Clear");
Button viewButton = new Button("Display");

firstNameField.setPrefHeight(40);
dobPicker.setPrefHeight(40);
lastNameField.setPrefHeight(40);
addressArea.setPrefHeight(80);
addressArea.setPrefWidth(200);
emailField.setPrefHeight(40);
insuranceField.setPrefHeight(40);
physicianField.setPrefHeight(40);
submitButton.setPrefHeight(40);
submitButton.setPrefWidth(100);
viewButton.setPrefWidth(100);
clearButton.setPrefHeight(40);
viewButton .setPrefHeight(40);
clearButton.setDefaultButton(true);
clearButton.setPrefWidth(100);
phoneField.setPrefHeight(40);

HBox hb = new HBox();


hb.getChildren().addAll(R1, R2);

GridPane gridPane = new GridPane();


gridPane.setPadding(new Insets(20, 20, 20, 20));
gridPane.setVgap(5);
gridPane.setHgap(5);
gridPane.add(firstNameLabel, 0, 1);
gridPane.add(firstNameField, 1, 1);
gridPane.add(lastNameLabel, 0, 2);
gridPane.add(lastNameField, 1, 2);

gridPane.add(addressLabel, 0, 5);
gridPane.add(addressArea, 1, 5, 2, 1);
gridPane.add(phoneLabel, 0, 6);
gridPane.add(phoneField, 1, 6);
gridPane.add(emailLabel, 0, 7);
gridPane.add(emailField, 1, 7);
gridPane.add(insuranceLabel, 0, 8);
gridPane.add(insuranceField, 1, 8);
gridPane.add(physicianLabel, 0, 9);
gridPane.add(physicianField, 1, 9);
gridPane.add(dobLabel, 0, 10);
gridPane.add(dobPicker, 1, 10);
gridPane.add(R1, 1, 11);
gridPane.add(R2, 2, 11);
gridPane.add(genderLabel, 0, 11);
gridPane.add(submitButton, 0, 12);
gridPane.add(clearButton, 1, 12);
gridPane.add(viewButton, 2, 12);

gridPane.setAlignment(Pos.CENTER);

Scene scene = new Scene(gridPane, 800, 500);


primaryStage.setScene(scene);
primaryStage.show();
GridPane.setHalignment(submitButton, javafx.geometry.HPos.RIGHT);
GridPane.setHalignment(clearButton, javafx.geometry.HPos.LEFT);
GridPane.setHalignment(viewButton, javafx.geometry.HPos.CENTER);

clearButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
firstNameField.clear();
lastNameField.clear();
addressArea.clear();
phoneField.clear();
emailField.clear();
insuranceField.clear();
physicianField.clear();
}
});
submitButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
String fname = firstNameField.getText();
String lname = lastNameField.getText();
String adress = addressArea.getText();
String email = emailField.getText();
String insu = insuranceField.getText();
String phys = physicianField.getText();

Alert a;
if (fname.isEmpty()) {
a = new Alert(Alert.AlertType.ERROR);
a.setContentText("Please Fill all fields");
a.show();
} else if (lname.isEmpty()) {
a = new Alert(Alert.AlertType.ERROR);
a.setContentText("Please Fill all fields");
a.show();
} else if (adress.isEmpty()) {
a = new Alert(Alert.AlertType.ERROR);
a.setContentText("Please Fill all fields");
a.show();
} else if (email.isEmpty()) {
a = new Alert(Alert.AlertType.ERROR);
a.setContentText("Please Fill all fields");
a.show();
} else if (insu.isEmpty()) {
a = new Alert(Alert.AlertType.ERROR);
a.setContentText("Please Fill all fields");
a.show();
} else if (phys.isEmpty()) {
a = new Alert(Alert.AlertType.ERROR);
a.setContentText("Please Fill all fields");
a.show();
} else {
try {
PrintWriter op = new PrintWriter(new
FileOutputStream("myfile.txt", true));
op.println(fname + " " + lname + " " + adress + " " + email
+ " " + insu + " " + phys);
op.flush();
op.close();
a = new Alert(Alert.AlertType.INFORMATION);
a.setContentText("Successfull");
a.show();
} catch (Exception e) {

}
}
}
});
viewButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
HBox h = new HBox();
TableView<Patient> table = new TableView();
TableColumn<Patient, String> col1 = new TableColumn<>("First
Name");
TableColumn<Patient, String> col2 = new TableColumn<>("Last Name");
TableColumn<Patient, String> col3 = new TableColumn<>("Addres");
TableColumn<Patient, String> col4 = new TableColumn<>("Email");
TableColumn<Patient, String> col5 = new TableColumn<>("Insurance");
TableColumn<Patient, String> col6 = new TableColumn<>("Physician");
table.getColumns().add(col1);
table.getColumns().add(col2);
table.getColumns().add(col3);
table.getColumns().add(col4);
table.getColumns().add(col5);
table.getColumns().add(col6);
col1.setCellValueFactory(celldata -> new
SimpleStringProperty(celldata.getValue().getFname()));
col2.setCellValueFactory(celldata -> new
SimpleStringProperty(celldata.getValue().getLname()));
col3.setCellValueFactory(celldata -> new
SimpleStringProperty(celldata.getValue().getAdress()));
col4.setCellValueFactory(celldata -> new
SimpleStringProperty(celldata.getValue().getEmail()));
col5.setCellValueFactory(celldata -> new
SimpleStringProperty(celldata.getValue().getInsu()));
col6.setCellValueFactory(celldata -> new
SimpleStringProperty(celldata.getValue().getPhys()));

Patient s;

try {
Scanner sc = new Scanner(new FileInputStream("myfile.txt"));

while (sc.hasNext()) {
String fname, lname, adress, email, insu, phys;
fname = sc.next();
lname = sc.next();
adress = sc.next();
email = sc.next();
insu = sc.next();
phys = sc.next();
s = new Patient(fname, lname, adress, email, insu, phys);
table.getItems().add(s);

}
} catch (FileNotFoundException ex) {
}
h.getChildren().add(table);
Scene scene2 = new Scene(h,400,500);
primaryStage.setScene(scene2);

}
});
}

public static void main(String[] args) {


launch(args);
}
}

You might also like