Professional Documents
Culture Documents
Without ID
Without ID
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.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
class Patient {
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 class Project10 extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Patient Registration Form");
clearButton.setDefaultButton(true);
viewButton.setDefaultButton(true);
submitButton.setDefaultButton(true);
HBox hb = new HBox();
hb.getChildren().addAll(R1, R2);
HBox hbo = new HBox();
hbo.getChildren().addAll(Welcome);
hbo.setAlignment(Pos.TOP_CENTER);
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);
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(hb, 1, 11);
gridPane.add(genderLabel, 0, 11);
gridPane.add(submitButton, 0, 12);
gridPane.add(clearButton, 0, 13);
gridPane.add(viewButton, 0, 14);
gridPane.setAlignment(Pos.CENTER);
scene.getStylesheets().add("/css/css.css");
root.setId("a1");
hbo.setId("a2");
root.setCenter(gridPane);
root.setTop(hbo);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
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,600,500);
primaryStage.setScene(scene2);
}
});
///////////////////////////////////////////////////////////////////////////////////
//////////
package sampleproject;
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.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
class Student {
String id, fname, lname, year, sex, department, adress, email, phon, phys;
public Student(String id, String fname, String lname, String year, String sex,
String department, String email, String adress, String phon, String phys) {
this.id = id;
this.fname = fname;
this.lname = lname;
this.year = year;
this.sex = sex;
this.department = department;
this.email = email;
this.adress = adress;
this.phon = phon;
this.phys = phys;
}
@Override
public void start(Stage primaryStage) {
// Create the TabPane
TabPane tabPane = new TabPane();
// Create tabs
Tab tab1 = new Tab("Register");
Tab tab2 = new Tab("View Info");
Tab tab3 = new Tab("Search Info");
Tab tab4 = new Tab("Delete Info");
// create content
GridPane gridPane = new GridPane();
gridPane.setPadding(new Insets(10, 10, 10, 10));
gridPane.setHgap(10);
gridPane.setVgap(10);
// Year ComboBox
ComboBox<String> yearComboBox = new ComboBox<>();
yearComboBox.getItems().addAll("I", "II", "III", "IV", "V");
Label lfname = new Label("First Name:");
Label llname = new Label("Last Name:");
Label lid = new Label("ID:");
TextField tf1 = new TextField();
TextField tf2 = new TextField();
TextField tf3 = new TextField();
// Sex RadioButtons
ToggleGroup sexToggleGroup = new ToggleGroup();
RadioButton maleRadioButton = new RadioButton("Male");
maleRadioButton.setToggleGroup(sexToggleGroup);
RadioButton femaleRadioButton = new RadioButton("Female");
femaleRadioButton.setToggleGroup(sexToggleGroup);
// gridPane.add(new Label("Sex:"), 0, 1);
maleRadioButton.setSelected(true);
HBox h = new HBox();
h.getChildren().addAll(femaleRadioButton, maleRadioButton);
// gridPane.add(h, 1, 1);
//gridPane.add(femaleRadioButton, 2, 1);
// Department ComboBox
ComboBox<String> departmentComboBox = new ComboBox<>();
maleRadioButton.getStyleClass().add("custom-radio-button");
femaleRadioButton.getStyleClass().add("custom-radio-button");
departmentComboBox.getStyleClass().add("custom-combo-box");
departmentComboBox.getItems().addAll("CS", "IT", "IS");
try {
Alert a;
//check if empty field exist
if (fname.isEmpty() || lname.isEmpty() || id.isEmpty() ||
sex.isEmpty() || adress.isEmpty() || email.isEmpty() || phon.isEmpty() ||
phon.isEmpty()) {
a = new Alert(Alert.AlertType.ERROR);
a.setContentText("Please fill all field");
a.show();
} else {
//file reading to check id redundancy
PrintWriter out = new PrintWriter(new
FileOutputStream("student.txt", true));
Scanner c = new Scanner(new
FileInputStream("student.txt"));
int check = 0;
while (c.hasNext()) {
if (c.next().equals(id)) {
//id is exist
check = 1;
}
}
if (check == 0) {
//create print writer to write data
out.println(id + " " + fname + " " + lname + " " + year
+ " " + sex + " " + department + " " + adress + " " + email + " " + phon + " " +
phys);
out.close();
a = new Alert(Alert.AlertType.INFORMATION);
a.setContentText("Successfully Saved");
a.show();
Scanner c2 = new Scanner(new
FileInputStream("student.txt"));
Student st;
while (c2.hasNext()) {
String id1 = c2.next();
String fname1 = c2.next();
String lname1 = c2.next();
String year1 = c2.next();
String dep1 = c2.next();
String sex1 = c2.next();
String adr1 = c2.next();
String ema1 = c2.next();
String pho1 = c2.next();
String phy1 = c2.next();
st = new Student(id1, fname1, lname1, year1, dep1,
sex1, adr1, ema1, pho1, phy1);
table.getItems().clear();
table.getItems().add(st);
}
} else {
a = new Alert(Alert.AlertType.ERROR);
a.setContentText("Sorry Id already exist");
a.show();
}
}
} catch (FileNotFoundException e) {
}
}
});
clearButton.setOnAction(event -> {
// Handle clear button action
});
HBox h3 = new HBox();
TableColumn<Student, String> col1 = new TableColumn<>("ID");
TableColumn<Student, String> col2 = new TableColumn<>("First Name");
TableColumn<Student, String> col3 = new TableColumn<>("Last Name");
TableColumn<Student, String> col4 = new TableColumn<>("Year");
TableColumn<Student, String> col5 = new TableColumn<>("Department");
TableColumn<Student, String> col6 = new TableColumn<>("Sex");
TableColumn<Student, String> col7 = new TableColumn<>("Addres");
TableColumn<Student, String> col8 = new TableColumn<>("Email");
TableColumn<Student, String> col9 = new TableColumn<>("Phone");
TableColumn<Student, String> col10 = new TableColumn<>("Physician");
} catch (FileNotFoundException e) {
}
h3.getChildren().addAll(table);
tab2.setContent(h3);
// Set content for tabs
tab1.setContent(gridPane);
// tab2.setContent(new StackPane(saveButton));
//create serach UI for tab3
TextField idtf = new TextField();
Button search = new Button("Search");
HBox h4 = new HBox();
HBox h5 = new HBox();
h4.setSpacing(10);
h4.getChildren().addAll(new Label("ID"), idtf, search);
clearButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
tf1.clear();
tf2.clear();
addressArea.clear();
phoneField.clear();
emailField.clear();
phoneField.clear();
physicianField.clear();
tf3.clear();
}
});
search.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
Scanner c = new Scanner(new FileInputStream("student.txt"));
Student st;
String searchId = idtf.getText();
int check = 0;
while (c.hasNext()) {
String id = c.next();
String fname = c.next();
String lname = c.next();
String year = c.next();
String dep = c.next();
String sex = c.next();
String adr = c.next();
String ema = c.next();
String pho = c.next();
String phy = c.next();
if (id.equals(searchId)) {
check++;
st = new Student(id, fname, lname, year, dep, sex, adr,
ema, pho, phy);
table.getItems().clear();
table.getItems().add(st);
}
}
if (check == 0) {
Alert a = new Alert(Alert.AlertType.ERROR);
a.setContentText("Data not found");
a.show();
} else {
h5.getChildren().add(table);
}
} catch (FileNotFoundException e) {
}
}
});
// tab4.setContent(gridPane);
// tab2.setContent(new StackPane(saveButton));
//create serach UI for tab3
TextField idt = new TextField();
Button delete = new Button("Delete");
h6.setSpacing(10);
h6.getChildren().addAll(new Label("ID"), idt, delete);
delete.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
Scanner c = new Scanner(new FileInputStream("student.txt"));
Student st;
String deleteId = idt.getText();
int check = 0;
while (c.hasNext()) {
String id = c.next();
String fname = c.next();
String lname = c.next();
String year = c.next();
String dep = c.next();
String sex = c.next();
String adr = c.next();
String ema = c.next();
String pho = c.next();
String phy = c.next();
if (id.equals(deleteId)) {
check++;
st = new Student(id, fname, lname, year, dep, sex, adr,
ema, pho, phy);
table.getItems().clear();
table.getItems().remove(st);
}
}
if (check == 0) {
} else {
Alert a = new Alert(Alert.AlertType.INFORMATION);
a.setContentText("Data Deleted Successfuly");
a.show();
h7.getChildren().add(table);
}
} catch (FileNotFoundException e) {
}
}
});
VBox v = new VBox();
v.getChildren().addAll(h4, h5);
tab3.setContent(v);
VBox z = new VBox();
z.getChildren().addAll(h6, h7);
tab4.setContent(z);
// Add tabs to the TabPane
tabPane.getTabs().addAll(tab1, tab2, tab3, tab4);
gridPane.setId("a1");
// Create the Scene
Scene scene = new Scene(tabPane, 800, 500);
// scene.getStylesheets().add("/css/style.css");
// Set the title and scene for the Stage
primaryStage.setTitle("Student Information");
primaryStage.setScene(scene);