JavaFX-不同控制器中按钮和文本字段之间的通信不';行不通
我的桌面应用程序(诊所)出现问题,这里是RegistrationController,它负责输入有关患者的数据,单击按钮“添加”后,这些数据将传输到另一个控制器,称为InfoPatientController(带有FXML文件,其中显示输入的患者信息),我在单击后设置测试“添加”在其他窗口中显示文本“asdf”,但它不起作用,下面是一个代码和屏幕: java.lang.RuntimeException:java.lang.reflect.InvocationTargetException -出现这些错误 我创建了MainController,但我不知道如何在一个类中管理所有控制器。是否可以用我的方式管理它 以下是注册PatientController:JavaFX-不同控制器中按钮和文本字段之间的通信不';行不通,java,eclipse,javafx,Java,Eclipse,Javafx,我的桌面应用程序(诊所)出现问题,这里是RegistrationController,它负责输入有关患者的数据,单击按钮“添加”后,这些数据将传输到另一个控制器,称为InfoPatientController(带有FXML文件,其中显示输入的患者信息),我在单击后设置测试“添加”在其他窗口中显示文本“asdf”,但它不起作用,下面是一个代码和屏幕: java.lang.RuntimeException:java.lang.reflect.InvocationTargetException -出现
public class RegistrationPatientController implements Initializable {
@FXML
Button registrationButton, infopatientButton, checkoutButton, medicalstaffButton, usersButton, logoutButton,
exitButton;
@FXML
TextField PIDField, nameField, lastNameField, genderField, ageField, phonenumberField, adressField, diseaseField,
IDField, dataField, conditionField, priceField;
@FXML
RadioButton normalRoom, vipRoom;
@FXML
MenuButton roomMenuField;
@FXML
MenuItem room101, room102, room103, room104, room105, room106, room107, room108;
@FXML
Button confirmButton, closeButton, addpatientButton;
ToggleGroup choiceRoom = new ToggleGroup();
@FXML
InfoPatientController infoPatientController;
Stage stage;
BorderPane root;
boolean start = true;
String name;
String lastname;
String gender;
String age;
String phonenumber;
String adress;
String disease;
String condition;
String roomtype;
@FXML
public void enterInfoAboutPatient(ActionEvent event) {
}
@FXML
public void roomChoiceAndCalculatePrice(ActionEvent event) {
normalRoom.setToggleGroup(choiceRoom);
vipRoom.setToggleGroup(choiceRoom);
if (choiceRoom.equals(normalRoom)) {
normalRoom.isSelected();
}
if (choiceRoom.equals(vipRoom)) {
vipRoom.isSelected();
}
}
@FXML
public void roomNumberChoice(ActionEvent event) {
String numberRoom101 = "101";
String numberRoom102 = "102";
String numberRoom103 = "103";
String numberRoom104 = "104";
String numberRoom105 = "105";
String numberRoom106 = "106";
String numberRoom107 = "107";
String numberRoom108 = "108";
String firstpriceNormalRoom = "30";
String secondpriceNormalRoom = "40";
String firstpriceVipRoom = "80";
String secondpriceVipRoom = "120";
if (normalRoom.isSelected()) {
if (event.getSource() == room101) {
roomMenuField.setText(numberRoom101);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room102) {
roomMenuField.setText(numberRoom102);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room103) {
roomMenuField.setText(numberRoom103);
priceField.setText(secondpriceNormalRoom);
return;
}
if (event.getSource() == room104) {
roomMenuField.setText(numberRoom104);
priceField.setText(secondpriceNormalRoom);
return;
}
if (event.getSource() == room105) {
roomMenuField.setText(numberRoom105);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room106) {
roomMenuField.setText(numberRoom106);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room107) {
roomMenuField.setText(numberRoom107);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room108) {
roomMenuField.setText(numberRoom108);
priceField.setText(secondpriceNormalRoom);
return;
}
}
if (vipRoom.isSelected()) {
if (event.getSource() == room101) {
roomMenuField.setText(numberRoom101);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room102) {
roomMenuField.setText(numberRoom102);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room103) {
roomMenuField.setText(numberRoom103);
priceField.setText(secondpriceVipRoom);
return;
}
if (event.getSource() == room104) {
roomMenuField.setText(numberRoom104);
priceField.setText(secondpriceVipRoom);
return;
}
if (event.getSource() == room105) {
roomMenuField.setText(numberRoom105);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room106) {
roomMenuField.setText(numberRoom106);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room107) {
roomMenuField.setText(numberRoom107);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room108) {
roomMenuField.setText(numberRoom108);
priceField.setText(secondpriceVipRoom);
return;
}
}
}
@FXML
public void handleAddPatient(ActionEvent event) {
// name = nameField.getText();
// lastname = lastNameField.getText();
// gender = genderField.getText();
// age = ageField.getText();
// phonenumber = phonenumberField.getText();
// adress = adressField.getText();
// disease = diseaseField.getText();
// condition = conditionField.getText();
infoPatientController.infoageField.setText("asdf");
// boolean enterCondition = !nameField.getText().isEmpty() &&
// !lastNameField.getText().isEmpty()
/// && !genderField.getText().isEmpty() && !ageField.getText().isEmpty()
// && !phonenumberField.getText().isEmpty() &&
// !adressField.getText().isEmpty()
// && !diseaseField.getText().isEmpty() &&
// !conditionField.getText().isEmpty()
// && (normalRoom.isSelected() || vipRoom.isSelected());
//
// boolean choiceRoomCondition = (event.getSource() == room101) ||
// (event.getSource() == room102)
// || (event.getSource() == room103) || (event.getSource() == room104)
// || (event.getSource() == room105)
// || (event.getSource() == room106) || (event.getSource() == room107)
// || (event.getSource() == room108);
// if(enterCondition&choiceRoomCondition)
// {
// EntityManagerFactory entityManagerFactory =
// Persistence.createEntityManagerFactory("test");
// EntityManager entityManager =
// entityManagerFactory.createEntityManager();
// Patient patient = new Patient();
// patient.setID(001);
// patient.setFirstName(name);
// patient.setLastName(lastname);
// patient.setGender(gender);
// patient.setAge(age);
// patient.setPhonenumber(phonenumber);
// patient.setAdress(adress);
// patient.setDisease(disease);
// patient.setCondition(condition);
// entityManager.getTransaction().begin();
// entityManager.persist(patient);
// entityManager.getTransaction().commit();
//
// entityManager.close();
// entityManagerFactory.close();
// }
}
@FXML
public void closeRegistration(ActionEvent event) throws IOException {
root = FXMLLoader.load(getClass().getResource("/view/Main.fxml"));
stage = (Stage) registrationButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
}
@FXML
public void chooseOption(ActionEvent event) throws IOException {
if (event.getSource() == registrationButton) {
root = FXMLLoader.load(getClass().getResource("/view/RegistrationPatient.fxml"));
stage = (Stage) registrationButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == infopatientButton) {
root = FXMLLoader.load(getClass().getResource("/view/InfoPatient.fxml"));
stage = (Stage) infopatientButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == checkoutButton) {
root = FXMLLoader.load(getClass().getResource("/view/CheckOutPatient.fxml"));
stage = (Stage) checkoutButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == medicalstaffButton) {
root = FXMLLoader.load(getClass().getResource("/view/MedicalStaff.fxml"));
stage = (Stage) medicalstaffButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == usersButton) {
root = FXMLLoader.load(getClass().getResource("/view/Users.fxml"));
stage = (Stage) usersButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == infopatientButton) {
root = FXMLLoader.load(getClass().getResource("/view/InfoPatient.fxml"));
stage = (Stage) infopatientButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == logoutButton) {
root = FXMLLoader.load(getClass().getResource("/view/Login.fxml"));
stage = (Stage) logoutButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 280, 280));
stage.show();
return;
}
if (event.getSource() == exitButton) {
stage = (Stage) exitButton.getScene().getWindow();
stage.close();
}
}
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
PIDField.setEditable(false);
dataField.setEditable(false);
IDField.setEditable(false);
priceField.setEditable(false);
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
dataField.setText((dateFormat.format(date)));
}
public class InfoPatientController implements Initializable {
@FXML
Button registrationButton, infopatientButton, checkoutButton, medicalstaffButton, usersButton,
logoutButton, exitButton;
@FXML
TextField infoPIDField, infonameField, infolastNameField, infogenderField, infoageField,
infophonenumberField, infoadressField, infodiseaseField, infoconditionField, infodataField,
infoRoomNumber, infoRoomType;
@FXML
ListView<String> patientList;
@FXML
Button confirmButton, editButton, closeButton;
@FXML
RegistrationPatientController registrationPatientController;
Stage stage;
BorderPane root;
boolean start = true;
private MainController main;
@FXML
public void enteredInfoAboutPatient(ActionEvent event)
{
}
@FXML
public void optionsAction(ActionEvent event)
{
}
@FXML
public void chooseOption(ActionEvent event) throws IOException
{
if(event.getSource()==registrationButton)
{
root = FXMLLoader.load(getClass().getResource("/view/RegistrationPatient.fxml"));
stage = (Stage) registrationButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource()==infopatientButton)
{
root = FXMLLoader.load(getClass().getResource("/view/InfoPatient.fxml"));
stage = (Stage) infopatientButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if(event.getSource()==checkoutButton)
{
root = FXMLLoader.load(getClass().getResource("/view/CheckOutPatient.fxml"));
stage = (Stage) checkoutButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource()==medicalstaffButton)
{
root = FXMLLoader.load(getClass().getResource("/view/MedicalStaff.fxml"));
stage = (Stage) medicalstaffButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if(event.getSource()==usersButton)
{
root = FXMLLoader.load(getClass().getResource("/view/Users.fxml"));
stage = (Stage) usersButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource()==infopatientButton)
{
root = FXMLLoader.load(getClass().getResource("/view/InfoPatient.fxml"));
stage = (Stage) infopatientButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if(event.getSource()==logoutButton)
{
root = FXMLLoader.load(getClass().getResource("/view/Login.fxml"));
stage = (Stage) logoutButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 280, 280));
stage.show();
return;
}
if (event.getSource()==exitButton)
{
stage = (Stage) exitButton.getScene().getWindow();
stage.close();
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
infoPatientController.infoageField.setText("asdf");
}
以下是InfoPatientController:
public class RegistrationPatientController implements Initializable {
@FXML
Button registrationButton, infopatientButton, checkoutButton, medicalstaffButton, usersButton, logoutButton,
exitButton;
@FXML
TextField PIDField, nameField, lastNameField, genderField, ageField, phonenumberField, adressField, diseaseField,
IDField, dataField, conditionField, priceField;
@FXML
RadioButton normalRoom, vipRoom;
@FXML
MenuButton roomMenuField;
@FXML
MenuItem room101, room102, room103, room104, room105, room106, room107, room108;
@FXML
Button confirmButton, closeButton, addpatientButton;
ToggleGroup choiceRoom = new ToggleGroup();
@FXML
InfoPatientController infoPatientController;
Stage stage;
BorderPane root;
boolean start = true;
String name;
String lastname;
String gender;
String age;
String phonenumber;
String adress;
String disease;
String condition;
String roomtype;
@FXML
public void enterInfoAboutPatient(ActionEvent event) {
}
@FXML
public void roomChoiceAndCalculatePrice(ActionEvent event) {
normalRoom.setToggleGroup(choiceRoom);
vipRoom.setToggleGroup(choiceRoom);
if (choiceRoom.equals(normalRoom)) {
normalRoom.isSelected();
}
if (choiceRoom.equals(vipRoom)) {
vipRoom.isSelected();
}
}
@FXML
public void roomNumberChoice(ActionEvent event) {
String numberRoom101 = "101";
String numberRoom102 = "102";
String numberRoom103 = "103";
String numberRoom104 = "104";
String numberRoom105 = "105";
String numberRoom106 = "106";
String numberRoom107 = "107";
String numberRoom108 = "108";
String firstpriceNormalRoom = "30";
String secondpriceNormalRoom = "40";
String firstpriceVipRoom = "80";
String secondpriceVipRoom = "120";
if (normalRoom.isSelected()) {
if (event.getSource() == room101) {
roomMenuField.setText(numberRoom101);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room102) {
roomMenuField.setText(numberRoom102);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room103) {
roomMenuField.setText(numberRoom103);
priceField.setText(secondpriceNormalRoom);
return;
}
if (event.getSource() == room104) {
roomMenuField.setText(numberRoom104);
priceField.setText(secondpriceNormalRoom);
return;
}
if (event.getSource() == room105) {
roomMenuField.setText(numberRoom105);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room106) {
roomMenuField.setText(numberRoom106);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room107) {
roomMenuField.setText(numberRoom107);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room108) {
roomMenuField.setText(numberRoom108);
priceField.setText(secondpriceNormalRoom);
return;
}
}
if (vipRoom.isSelected()) {
if (event.getSource() == room101) {
roomMenuField.setText(numberRoom101);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room102) {
roomMenuField.setText(numberRoom102);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room103) {
roomMenuField.setText(numberRoom103);
priceField.setText(secondpriceVipRoom);
return;
}
if (event.getSource() == room104) {
roomMenuField.setText(numberRoom104);
priceField.setText(secondpriceVipRoom);
return;
}
if (event.getSource() == room105) {
roomMenuField.setText(numberRoom105);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room106) {
roomMenuField.setText(numberRoom106);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room107) {
roomMenuField.setText(numberRoom107);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room108) {
roomMenuField.setText(numberRoom108);
priceField.setText(secondpriceVipRoom);
return;
}
}
}
@FXML
public void handleAddPatient(ActionEvent event) {
// name = nameField.getText();
// lastname = lastNameField.getText();
// gender = genderField.getText();
// age = ageField.getText();
// phonenumber = phonenumberField.getText();
// adress = adressField.getText();
// disease = diseaseField.getText();
// condition = conditionField.getText();
infoPatientController.infoageField.setText("asdf");
// boolean enterCondition = !nameField.getText().isEmpty() &&
// !lastNameField.getText().isEmpty()
/// && !genderField.getText().isEmpty() && !ageField.getText().isEmpty()
// && !phonenumberField.getText().isEmpty() &&
// !adressField.getText().isEmpty()
// && !diseaseField.getText().isEmpty() &&
// !conditionField.getText().isEmpty()
// && (normalRoom.isSelected() || vipRoom.isSelected());
//
// boolean choiceRoomCondition = (event.getSource() == room101) ||
// (event.getSource() == room102)
// || (event.getSource() == room103) || (event.getSource() == room104)
// || (event.getSource() == room105)
// || (event.getSource() == room106) || (event.getSource() == room107)
// || (event.getSource() == room108);
// if(enterCondition&choiceRoomCondition)
// {
// EntityManagerFactory entityManagerFactory =
// Persistence.createEntityManagerFactory("test");
// EntityManager entityManager =
// entityManagerFactory.createEntityManager();
// Patient patient = new Patient();
// patient.setID(001);
// patient.setFirstName(name);
// patient.setLastName(lastname);
// patient.setGender(gender);
// patient.setAge(age);
// patient.setPhonenumber(phonenumber);
// patient.setAdress(adress);
// patient.setDisease(disease);
// patient.setCondition(condition);
// entityManager.getTransaction().begin();
// entityManager.persist(patient);
// entityManager.getTransaction().commit();
//
// entityManager.close();
// entityManagerFactory.close();
// }
}
@FXML
public void closeRegistration(ActionEvent event) throws IOException {
root = FXMLLoader.load(getClass().getResource("/view/Main.fxml"));
stage = (Stage) registrationButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
}
@FXML
public void chooseOption(ActionEvent event) throws IOException {
if (event.getSource() == registrationButton) {
root = FXMLLoader.load(getClass().getResource("/view/RegistrationPatient.fxml"));
stage = (Stage) registrationButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == infopatientButton) {
root = FXMLLoader.load(getClass().getResource("/view/InfoPatient.fxml"));
stage = (Stage) infopatientButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == checkoutButton) {
root = FXMLLoader.load(getClass().getResource("/view/CheckOutPatient.fxml"));
stage = (Stage) checkoutButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == medicalstaffButton) {
root = FXMLLoader.load(getClass().getResource("/view/MedicalStaff.fxml"));
stage = (Stage) medicalstaffButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == usersButton) {
root = FXMLLoader.load(getClass().getResource("/view/Users.fxml"));
stage = (Stage) usersButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == infopatientButton) {
root = FXMLLoader.load(getClass().getResource("/view/InfoPatient.fxml"));
stage = (Stage) infopatientButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == logoutButton) {
root = FXMLLoader.load(getClass().getResource("/view/Login.fxml"));
stage = (Stage) logoutButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 280, 280));
stage.show();
return;
}
if (event.getSource() == exitButton) {
stage = (Stage) exitButton.getScene().getWindow();
stage.close();
}
}
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
PIDField.setEditable(false);
dataField.setEditable(false);
IDField.setEditable(false);
priceField.setEditable(false);
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
dataField.setText((dateFormat.format(date)));
}
public class InfoPatientController implements Initializable {
@FXML
Button registrationButton, infopatientButton, checkoutButton, medicalstaffButton, usersButton,
logoutButton, exitButton;
@FXML
TextField infoPIDField, infonameField, infolastNameField, infogenderField, infoageField,
infophonenumberField, infoadressField, infodiseaseField, infoconditionField, infodataField,
infoRoomNumber, infoRoomType;
@FXML
ListView<String> patientList;
@FXML
Button confirmButton, editButton, closeButton;
@FXML
RegistrationPatientController registrationPatientController;
Stage stage;
BorderPane root;
boolean start = true;
private MainController main;
@FXML
public void enteredInfoAboutPatient(ActionEvent event)
{
}
@FXML
public void optionsAction(ActionEvent event)
{
}
@FXML
public void chooseOption(ActionEvent event) throws IOException
{
if(event.getSource()==registrationButton)
{
root = FXMLLoader.load(getClass().getResource("/view/RegistrationPatient.fxml"));
stage = (Stage) registrationButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource()==infopatientButton)
{
root = FXMLLoader.load(getClass().getResource("/view/InfoPatient.fxml"));
stage = (Stage) infopatientButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if(event.getSource()==checkoutButton)
{
root = FXMLLoader.load(getClass().getResource("/view/CheckOutPatient.fxml"));
stage = (Stage) checkoutButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource()==medicalstaffButton)
{
root = FXMLLoader.load(getClass().getResource("/view/MedicalStaff.fxml"));
stage = (Stage) medicalstaffButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if(event.getSource()==usersButton)
{
root = FXMLLoader.load(getClass().getResource("/view/Users.fxml"));
stage = (Stage) usersButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource()==infopatientButton)
{
root = FXMLLoader.load(getClass().getResource("/view/InfoPatient.fxml"));
stage = (Stage) infopatientButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if(event.getSource()==logoutButton)
{
root = FXMLLoader.load(getClass().getResource("/view/Login.fxml"));
stage = (Stage) logoutButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 280, 280));
stage.show();
return;
}
if (event.getSource()==exitButton)
{
stage = (Stage) exitButton.getScene().getWindow();
stage.close();
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
infoPatientController.infoageField.setText("asdf");
注册控制器中的第221行:
public class RegistrationPatientController implements Initializable {
@FXML
Button registrationButton, infopatientButton, checkoutButton, medicalstaffButton, usersButton, logoutButton,
exitButton;
@FXML
TextField PIDField, nameField, lastNameField, genderField, ageField, phonenumberField, adressField, diseaseField,
IDField, dataField, conditionField, priceField;
@FXML
RadioButton normalRoom, vipRoom;
@FXML
MenuButton roomMenuField;
@FXML
MenuItem room101, room102, room103, room104, room105, room106, room107, room108;
@FXML
Button confirmButton, closeButton, addpatientButton;
ToggleGroup choiceRoom = new ToggleGroup();
@FXML
InfoPatientController infoPatientController;
Stage stage;
BorderPane root;
boolean start = true;
String name;
String lastname;
String gender;
String age;
String phonenumber;
String adress;
String disease;
String condition;
String roomtype;
@FXML
public void enterInfoAboutPatient(ActionEvent event) {
}
@FXML
public void roomChoiceAndCalculatePrice(ActionEvent event) {
normalRoom.setToggleGroup(choiceRoom);
vipRoom.setToggleGroup(choiceRoom);
if (choiceRoom.equals(normalRoom)) {
normalRoom.isSelected();
}
if (choiceRoom.equals(vipRoom)) {
vipRoom.isSelected();
}
}
@FXML
public void roomNumberChoice(ActionEvent event) {
String numberRoom101 = "101";
String numberRoom102 = "102";
String numberRoom103 = "103";
String numberRoom104 = "104";
String numberRoom105 = "105";
String numberRoom106 = "106";
String numberRoom107 = "107";
String numberRoom108 = "108";
String firstpriceNormalRoom = "30";
String secondpriceNormalRoom = "40";
String firstpriceVipRoom = "80";
String secondpriceVipRoom = "120";
if (normalRoom.isSelected()) {
if (event.getSource() == room101) {
roomMenuField.setText(numberRoom101);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room102) {
roomMenuField.setText(numberRoom102);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room103) {
roomMenuField.setText(numberRoom103);
priceField.setText(secondpriceNormalRoom);
return;
}
if (event.getSource() == room104) {
roomMenuField.setText(numberRoom104);
priceField.setText(secondpriceNormalRoom);
return;
}
if (event.getSource() == room105) {
roomMenuField.setText(numberRoom105);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room106) {
roomMenuField.setText(numberRoom106);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room107) {
roomMenuField.setText(numberRoom107);
priceField.setText(firstpriceNormalRoom);
return;
}
if (event.getSource() == room108) {
roomMenuField.setText(numberRoom108);
priceField.setText(secondpriceNormalRoom);
return;
}
}
if (vipRoom.isSelected()) {
if (event.getSource() == room101) {
roomMenuField.setText(numberRoom101);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room102) {
roomMenuField.setText(numberRoom102);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room103) {
roomMenuField.setText(numberRoom103);
priceField.setText(secondpriceVipRoom);
return;
}
if (event.getSource() == room104) {
roomMenuField.setText(numberRoom104);
priceField.setText(secondpriceVipRoom);
return;
}
if (event.getSource() == room105) {
roomMenuField.setText(numberRoom105);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room106) {
roomMenuField.setText(numberRoom106);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room107) {
roomMenuField.setText(numberRoom107);
priceField.setText(firstpriceVipRoom);
return;
}
if (event.getSource() == room108) {
roomMenuField.setText(numberRoom108);
priceField.setText(secondpriceVipRoom);
return;
}
}
}
@FXML
public void handleAddPatient(ActionEvent event) {
// name = nameField.getText();
// lastname = lastNameField.getText();
// gender = genderField.getText();
// age = ageField.getText();
// phonenumber = phonenumberField.getText();
// adress = adressField.getText();
// disease = diseaseField.getText();
// condition = conditionField.getText();
infoPatientController.infoageField.setText("asdf");
// boolean enterCondition = !nameField.getText().isEmpty() &&
// !lastNameField.getText().isEmpty()
/// && !genderField.getText().isEmpty() && !ageField.getText().isEmpty()
// && !phonenumberField.getText().isEmpty() &&
// !adressField.getText().isEmpty()
// && !diseaseField.getText().isEmpty() &&
// !conditionField.getText().isEmpty()
// && (normalRoom.isSelected() || vipRoom.isSelected());
//
// boolean choiceRoomCondition = (event.getSource() == room101) ||
// (event.getSource() == room102)
// || (event.getSource() == room103) || (event.getSource() == room104)
// || (event.getSource() == room105)
// || (event.getSource() == room106) || (event.getSource() == room107)
// || (event.getSource() == room108);
// if(enterCondition&choiceRoomCondition)
// {
// EntityManagerFactory entityManagerFactory =
// Persistence.createEntityManagerFactory("test");
// EntityManager entityManager =
// entityManagerFactory.createEntityManager();
// Patient patient = new Patient();
// patient.setID(001);
// patient.setFirstName(name);
// patient.setLastName(lastname);
// patient.setGender(gender);
// patient.setAge(age);
// patient.setPhonenumber(phonenumber);
// patient.setAdress(adress);
// patient.setDisease(disease);
// patient.setCondition(condition);
// entityManager.getTransaction().begin();
// entityManager.persist(patient);
// entityManager.getTransaction().commit();
//
// entityManager.close();
// entityManagerFactory.close();
// }
}
@FXML
public void closeRegistration(ActionEvent event) throws IOException {
root = FXMLLoader.load(getClass().getResource("/view/Main.fxml"));
stage = (Stage) registrationButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
}
@FXML
public void chooseOption(ActionEvent event) throws IOException {
if (event.getSource() == registrationButton) {
root = FXMLLoader.load(getClass().getResource("/view/RegistrationPatient.fxml"));
stage = (Stage) registrationButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == infopatientButton) {
root = FXMLLoader.load(getClass().getResource("/view/InfoPatient.fxml"));
stage = (Stage) infopatientButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == checkoutButton) {
root = FXMLLoader.load(getClass().getResource("/view/CheckOutPatient.fxml"));
stage = (Stage) checkoutButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == medicalstaffButton) {
root = FXMLLoader.load(getClass().getResource("/view/MedicalStaff.fxml"));
stage = (Stage) medicalstaffButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == usersButton) {
root = FXMLLoader.load(getClass().getResource("/view/Users.fxml"));
stage = (Stage) usersButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == infopatientButton) {
root = FXMLLoader.load(getClass().getResource("/view/InfoPatient.fxml"));
stage = (Stage) infopatientButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource() == logoutButton) {
root = FXMLLoader.load(getClass().getResource("/view/Login.fxml"));
stage = (Stage) logoutButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 280, 280));
stage.show();
return;
}
if (event.getSource() == exitButton) {
stage = (Stage) exitButton.getScene().getWindow();
stage.close();
}
}
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
PIDField.setEditable(false);
dataField.setEditable(false);
IDField.setEditable(false);
priceField.setEditable(false);
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
dataField.setText((dateFormat.format(date)));
}
public class InfoPatientController implements Initializable {
@FXML
Button registrationButton, infopatientButton, checkoutButton, medicalstaffButton, usersButton,
logoutButton, exitButton;
@FXML
TextField infoPIDField, infonameField, infolastNameField, infogenderField, infoageField,
infophonenumberField, infoadressField, infodiseaseField, infoconditionField, infodataField,
infoRoomNumber, infoRoomType;
@FXML
ListView<String> patientList;
@FXML
Button confirmButton, editButton, closeButton;
@FXML
RegistrationPatientController registrationPatientController;
Stage stage;
BorderPane root;
boolean start = true;
private MainController main;
@FXML
public void enteredInfoAboutPatient(ActionEvent event)
{
}
@FXML
public void optionsAction(ActionEvent event)
{
}
@FXML
public void chooseOption(ActionEvent event) throws IOException
{
if(event.getSource()==registrationButton)
{
root = FXMLLoader.load(getClass().getResource("/view/RegistrationPatient.fxml"));
stage = (Stage) registrationButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource()==infopatientButton)
{
root = FXMLLoader.load(getClass().getResource("/view/InfoPatient.fxml"));
stage = (Stage) infopatientButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if(event.getSource()==checkoutButton)
{
root = FXMLLoader.load(getClass().getResource("/view/CheckOutPatient.fxml"));
stage = (Stage) checkoutButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource()==medicalstaffButton)
{
root = FXMLLoader.load(getClass().getResource("/view/MedicalStaff.fxml"));
stage = (Stage) medicalstaffButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if(event.getSource()==usersButton)
{
root = FXMLLoader.load(getClass().getResource("/view/Users.fxml"));
stage = (Stage) usersButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if (event.getSource()==infopatientButton)
{
root = FXMLLoader.load(getClass().getResource("/view/InfoPatient.fxml"));
stage = (Stage) infopatientButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 750, 530));
stage.show();
return;
}
if(event.getSource()==logoutButton)
{
root = FXMLLoader.load(getClass().getResource("/view/Login.fxml"));
stage = (Stage) logoutButton.getScene().getWindow();
stage.setTitle("Przychodnia");
stage.setScene(new Scene(root, 280, 280));
stage.show();
return;
}
if (event.getSource()==exitButton)
{
stage = (Stage) exitButton.getScene().getWindow();
stage.close();
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
infoPatientController.infoageField.setText("asdf");
这是RegistrationPatient.FXML:
<BorderPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.RegistrationPatientController">
<center>
<Pane prefHeight="530.0" prefWidth="750.0" BorderPane.alignment="CENTER">
<children>
<VBox layoutX="-1.0" prefHeight="450.0" prefWidth="112.0" />
<ImageView fitHeight="539.0" fitWidth="953.0" layoutX="-196.0" layoutY="-4.0">
<image>
<Image url="@../../../../../Users/Damian/Desktop/asdffff.png" />
</image>
</ImageView>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#89a1b9" height="540.0" layoutX="-6.0" layoutY="-3.0" opacity="0.94" stroke="WHITE" strokeType="INSIDE" width="154.0" />
<Button fx:id="registrationButton" layoutX="5.0" layoutY="72.0" mnemonicParsing="false" onAction="#chooseOption" prefHeight="27.0" prefWidth="137.0" style="-fx-background-color: #89a1b9; -fx-border-color: WHITE;" text="Zarejestruj pacjenta">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Button fx:id="infopatientButton" layoutX="5.0" layoutY="122.0" mnemonicParsing="false" onAction="#chooseOption" style="-fx-background-color: #89a1b9; -fx-border-color: WHITE;" text="Informacje o pacjencie">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Button fx:id="checkoutButton" layoutX="5.0" layoutY="172.0" mnemonicParsing="false" onAction="#chooseOption" prefHeight="27.0" prefWidth="137.0" style="-fx-background-color: #89a1b9; -fx-border-color: WHITE;" text="Wypisz pacjenta">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Button fx:id="medicalstaffButton" layoutX="5.0" layoutY="225.0" mnemonicParsing="false" onAction="#chooseOption" prefHeight="27.0" prefWidth="137.0" style="-fx-background-color: #89a1b9; -fx-border-color: WHITE;" text="Personel medyczny">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Button fx:id="usersButton" layoutX="5.0" layoutY="275.0" mnemonicParsing="false" onAction="#chooseOption" prefHeight="27.0" prefWidth="137.0" style="-fx-background-color: #89a1b9; -fx-border-color: WHITE;" text="Użytkownicy">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Button fx:id="logoutButton" layoutX="5.0" layoutY="325.0" mnemonicParsing="false" onAction="#chooseOption" prefHeight="27.0" prefWidth="64.0" style="-fx-background-color: #89a1b9; -fx-border-color: WHITE;" text="Wyloguj">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Button fx:id="exitButton" layoutX="78.0" layoutY="325.0" mnemonicParsing="false" onAction="#chooseOption" prefHeight="27.0" prefWidth="63.0" style="-fx-background-color: #89a1b9; -fx-border-color: WHITE;" text="Zamknij">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<ImageView fitHeight="200.0" fitWidth="200.0" layoutX="550.0" layoutY="350.0">
<image>
<Image url="@../../../../../Users/Damian/Desktop/imagesff.png" />
</image>
</ImageView>
<Label layoutX="36.0" layoutY="14.0" prefHeight="37.0" prefWidth="489.0" text="MENU" wrapText="true">
<font>
<Font size="28.0" />
</font>
</Label>
<Pane layoutX="164.0" layoutY="17.0" opacity="0.85" prefHeight="497.0" prefWidth="572.0" style="-fx-background-color: #81a1b9;">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#95b1cc00" height="98.0" layoutX="5.0" layoutY="10.0" stroke="WHITE" strokeType="INSIDE" width="189.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#95b1cc00" height="369.0" layoutX="5.0" layoutY="109.0" stroke="WHITE" strokeType="INSIDE" width="349.0" />
<Label layoutX="25.0" layoutY="15.0" prefHeight="17.0" prefWidth="90.0" text="ID rejestracji">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="14.0" layoutY="41.0" text="ID:">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="14.0" layoutY="78.0" text="Data:">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="25.0" layoutY="124.0" prefHeight="17.0" prefWidth="143.0" text="Informacje o pacjencie">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="11.0" layoutY="150.0" text="PID:">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="11.0" layoutY="186.0" text="Imię:">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="11.0" layoutY="227.0" text="Nazwisko:">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="11.0" layoutY="265.0" text="Płeć:">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="11.0" layoutY="305.0" text="Wiek:">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="10.0" layoutY="342.0" text="Telefon:">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="10.0" layoutY="382.0" text="Adres:">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="10.0" layoutY="419.0" text="Dolegliwość:">
<font>
<Font size="13.0" />
</font>
</Label>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#95b1cc00" height="98.0" layoutX="200.0" layoutY="10.0" stroke="WHITE" strokeType="INSIDE" width="156.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#95b1cc00" height="477.0" layoutX="363.0" layoutY="10.0" stroke="WHITE" strokeType="INSIDE" width="202.0" />
<Label layoutX="216.0" layoutY="15.0" text="Rodzaj pokoju">
<font>
<Font size="13.0" />
</font>
</Label>
<RadioButton fx:id="normalRoom" layoutX="217.0" layoutY="40.0" mnemonicParsing="false" onAction="#roomChoiceAndCalculatePrice" text="Zwykły">
<font>
<Font size="13.0" />
</font>
</RadioButton>
<RadioButton fx:id="vipRoom" layoutX="217.0" layoutY="70.0" mnemonicParsing="false" onAction="#roomChoiceAndCalculatePrice" text="VIP">
<font>
<Font size="14.0" />
</font>
</RadioButton>
<Label layoutX="374.0" layoutY="15.0" text="Informacje o pokoju pacjenta">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="375.0" layoutY="55.0" text="Numer pokoju:">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="375.0" layoutY="99.0" text="Cena:">
<font>
<Font size="13.0" />
</font>
</Label>
<TextField fx:id="PIDField" layoutX="176.0" layoutY="148.0" />
<TextField fx:id="nameField" layoutX="176.0" layoutY="184.0" onAction="#enterInfoAboutPatient" />
<TextField fx:id="lastNameField" layoutX="176.0" layoutY="224.0" onAction="#enterInfoAboutPatient" />
<TextField fx:id="genderField" layoutX="176.0" layoutY="263.0" onAction="#enterInfoAboutPatient" />
<TextField fx:id="ageField" layoutX="176.0" layoutY="303.0" onAction="#enterInfoAboutPatient" prefHeight="25.0" prefWidth="149.0" />
<TextField fx:id="phonenumberField" layoutX="175.0" layoutY="340.0" onAction="#enterInfoAboutPatient" prefHeight="25.0" prefWidth="149.0" />
<TextField fx:id="adressField" layoutX="59.0" layoutY="380.0" onAction="#enterInfoAboutPatient" prefHeight="25.0" prefWidth="267.0" />
<TextField fx:id="diseaseField" layoutX="176.0" layoutY="416.0" onAction="#enterInfoAboutPatient" />
<TextField fx:id="IDField" layoutX="69.0" layoutY="39.0" prefHeight="25.0" prefWidth="121.0" />
<TextField fx:id="dataField" layoutX="69.0" layoutY="76.0" prefHeight="25.0" prefWidth="121.0" />
<MenuButton fx:id="roomMenuField" layoutX="471.0" layoutY="52.0" mnemonicParsing="false" onAction="#roomNumberChoice" prefHeight="25.0" prefWidth="87.0">
<items>
<MenuItem fx:id="room101" mnemonicParsing="false" onAction="#roomNumberChoice" text="101" />
<MenuItem fx:id="room102" mnemonicParsing="false" onAction="#roomNumberChoice" text="102" />
<MenuItem fx:id="room103" mnemonicParsing="false" onAction="#roomNumberChoice" text="103" />
<MenuItem fx:id="room104" mnemonicParsing="false" onAction="#roomNumberChoice" text="104" />
<MenuItem fx:id="room105" mnemonicParsing="false" onAction="#roomNumberChoice" text="105" />
<MenuItem fx:id="room106" mnemonicParsing="false" onAction="#roomNumberChoice" text="106" />
<MenuItem fx:id="room107" mnemonicParsing="false" onAction="#roomNumberChoice" text="107" />
<MenuItem fx:id="room108" mnemonicParsing="false" onAction="#roomNumberChoice" text="108" />
</items>
</MenuButton>
<TextField fx:id="priceField" layoutX="472.0" layoutY="96.0" onAction="#roomNumberChoice" prefHeight="25.0" prefWidth="85.0" />
<Label layoutX="10.0" layoutY="448.0" text="Stan pacjenta:">
<font>
<Font size="13.0" />
</font>
</Label>
<TextField fx:id="conditionField" layoutX="177.0" layoutY="445.0" onAction="#enterInfoAboutPatient" prefHeight="25.0" prefWidth="147.0" />
<Button fx:id="closeButton" layoutX="422.0" layoutY="258.0" mnemonicParsing="false" onAction="#closeRegistration" prefHeight="36.0" prefWidth="100.0" text="Zamknij" />
<Button fx:id="addpatientButton" layoutX="421.0" layoutY="197.0" mnemonicParsing="false" onAction="#handleAddPatient" prefHeight="36.0" prefWidth="100.0" text="Dodaj" />
</children></Pane>
</children>
</Pane>
</center>
</BorderPane>
请发布完整的堆栈跟踪并确定它出现的行。好的,我想我粘贴它,不确定我是否按照您的要求执行了infoPatientController
或infoPatientController。infoageField
为空。infoPatientController
是如何注入RegistrationController
的?您认为呢您在FXML中使用了
?确切地说,它没有以任何方式注入,我应该在哪一行注入?然后它会工作吗?我将粘贴到FXML后文件以注册PatientController