Java E 公共void初始化(URL arg0,ResourceBundle arg1){ assert tableView!=null:“fx:id=\“tableView\”未被注入:检查FXML文件'FXMLQueueTabPage.FXML'; setCellValueFactory(新的PropertyValueFactory(“firstName”); setCellValueFactory(新的PropertyValueFactory(“lastName”); postCodeColumn.setCellValueFactory(新属性值工厂(“邮政编码”); } 公共无效显示队列(列表队列){ tableData=FXCollections.observableArrayList(); System.out.println(“启动qtc中的显示队列方法+firstNameColumn=“+firstNameColumn”)的值); 用于(患者:队列){ System.out.println(patient.getFirstName()); System.out.println(patient.getLastName()); System.out.println(patient.getPostCode()); System.out.println(patient.getTriage()); //tableData.addAll(队列); tableData.add(患者); System.out.println(tableData); } tableView.setItems(tableData); 刷新表(); } 空刷新表(){ 最终列表项=tableView.getItems(); if(items==null | | items.size()==0)返回; 最终患者项目=tableView.getItems().get(0); 项目。删除(0); Platform.runLater(新的Runnable(){ @凌驾 公开募捐{ 项目。添加(0,项目); } }); } }
。Java E 公共void初始化(URL arg0,ResourceBundle arg1){ assert tableView!=null:“fx:id=\“tableView\”未被注入:检查FXML文件'FXMLQueueTabPage.FXML'; setCellValueFactory(新的PropertyValueFactory(“firstName”); setCellValueFactory(新的PropertyValueFactory(“lastName”); postCodeColumn.setCellValueFactory(新属性值工厂(“邮政编码”); } 公共无效显示队列(列表队列){ tableData=FXCollections.observableArrayList(); System.out.println(“启动qtc中的显示队列方法+firstNameColumn=“+firstNameColumn”)的值); 用于(患者:队列){ System.out.println(patient.getFirstName()); System.out.println(patient.getLastName()); System.out.println(patient.getPostCode()); System.out.println(patient.getTriage()); //tableData.addAll(队列); tableData.add(患者); System.out.println(tableData); } tableView.setItems(tableData); 刷新表(); } 空刷新表(){ 最终列表项=tableView.getItems(); if(items==null | | items.size()==0)返回; 最终患者项目=tableView.getItems().get(0); 项目。删除(0); Platform.runLater(新的Runnable(){ @凌驾 公开募捐{ 项目。添加(0,项目); } }); } },java,javafx,Java,Javafx,。 基本上发生的是TableView被填充和绘制,但由于这一行:private TableView TableView=new TableView()另一个空的TableView被画在上面。如果你改变 @FXML private TableView<Patient> tableView = new TableView<Patient>(); @FXML private TableView TableView=new TableView(); 到 @FXML 私有Ta
基本上发生的是
TableView
被填充和绘制,但由于这一行:private TableView TableView=new TableView()代码>另一个空的TableView
被画在上面。如果你改变
@FXML
private TableView<Patient> tableView = new TableView<Patient>();
@FXML
private TableView TableView=new TableView();
到
@FXML
私有TableView TableView;
您应该会看到填充的tableView
,因为您处理的是@fxml
,您不必使用private tableView tableView=new tableView()代码>在公共类QueueTabPageController
中。可以是private TableView TableView代码>因为该部分在.fxml
文件中处理。我认为您在那里也在做同样的事情。实例化queueTabPageController=new queueTabPageController()代码>控制器。我不是100%确定,但我认为您不必这样做。当我更改该行时,我现在得到以下NullPointerException错误:java.lang.NullPointerException at controllers.QueueTabPageController.displayQueue(QueueTabPageController.java:80)at controllers.PatientInfoController.btnConfirm(PatientInfoController.java:87)
我已经尝试过调试,但我不确定该怎么做,因为我对Java和JavaFX还不熟悉。如果你不确定该做什么,我建议你读一读,了解一下该做什么和不该做什么。我认为queueTabPageController=new queueTabPageController()代码>queueTabPageController.displayQueue(队列)代码>可以以不同的方式处理。因为控制器都是关于fxml
的,而display方法不涉及fxml
,所以您可能应该将display
方法移动到另一个类或新类。问题是您使用了两个控制器(看起来),我对此没有太多经验。到目前为止,我只编写了使用一个的程序。使用2意味着需要更多的窗口(阶段)。但我很快就会读到这一点好的,无论如何谢谢你的帮助-我将阅读文档并查看你提到的其他要点。因为我有两个不同的页面,所以我创建了两个控制器。我不确定这是不是正确的做法。
package controllers;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
import app.Patient;
import app.Queue;
import app.Status;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
public class PatientInfoController implements Initializable {
@FXML
private TableView<Patient> personTable;
@FXML
private TableColumn<Patient, String> firstNameColumn;
@FXML
private TableColumn<Patient, String> lastNameColumn;
@FXML
private Label nhsNumberLabel;
@FXML
private Label titleLabel;
@FXML
private Label firstNameLabel;
@FXML
private Label lastNameLabel;
@FXML
private Label streetNumberLabel;
@FXML
private Label streetNameLabel;
@FXML
private Label cityLabel;
@FXML
private Label postCodeLabel;
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
assert personTable != null : "fx:id=\"tableView\" was not injected: check your FXML file 'PatientInfoPage.fxml'";
}
/**
* Button to send user back to receptionist homepage
*
* @param event
* @throws IOException
*/
@FXML
private void btnCancel(ActionEvent event) throws IOException {
Stage stage = (Stage) ((Node) (event.getSource())).getScene().getWindow();
stage.close();
}
public static List<Patient> queue;
public static QueueTabPageController queueTabPageController;
/**
* Button to confirm patient and send them to triage/waiting queue
*
* @param event
*/
@FXML
private void btnConfirm(ActionEvent event) {
Stage stage = (Stage) ((Node) (event.getSource())).getScene().getWindow();
// patientservicesclass psc = new patientservicesclass
// test.enqueue("test");
// psc.getPatientById(nhsNumberLabel.getText())
Patient p = new Patient(firstNameLabel.getText(), lastNameLabel.getText(), nhsNumberLabel.getText(),
titleLabel.getText(), streetNumberLabel.getText(), streetNameLabel.getText(), cityLabel.getText(),
postCodeLabel.getText(), Status.EMERGENCY);
queueTabPageController = new QueueTabPageController();
queue = Queue.addToQueue(p);
queueTabPageController.displayQueue(queue);
stage.close();
}
/**
* sets relevant labels to patient information from the database these
* labels are set before screen is changed --- see btnPatientInfo on the
* ReceptionistHomePageController for more info ---
*
* @param patient
*/
public void setPatientInfo(Patient patient) {
nhsNumberLabel.setText(patient.getNhsNumber());
titleLabel.setText(patient.getTitle());
firstNameLabel.setText(patient.getFirstName());
lastNameLabel.setText(patient.getLastName());
streetNumberLabel.setText(patient.getStreetNumber());
streetNameLabel.setText(patient.getStreetName());
cityLabel.setText(patient.getCity());
postCodeLabel.setText(patient.getPostCode());
}
}
package app;
import java.util.LinkedList;
import java.util.List;
public class Queue implements Comparable<Patient> {
/**
* linked list of patient objects to represent queue
*/
public static List<Patient> queue = new LinkedList<Patient>();
/**
* method to add a patient to the queue
*
* @param p
*/
public static List<Patient> addToQueue(Patient p) {
// check to see if queue is full
if (queue.size() < 10) {
// add patient if there is room in queue
queue.add(p);
} else {
// queue may be full
System.out.println("Queue is full");
// alert on call team and hospital manager
}
return queue;
//test.displayQueue(queue);
}
/**
* method to remove a patient from the queue
*
* @param p
*/
public static void removefromQueue(Patient p) {
// remove patient from queue
queue.remove(p);
}
/**
* overriden method to allow comparison by triage status
*/
@Override
public int compareTo(Patient o) {
return 0;
}
}
package controllers;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
import app.Patient;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
public class QueueTabPageController implements Initializable {
@FXML
private TableView<Patient> tableView = new TableView<Patient>();
@FXML
private TableColumn<Patient, String> firstNameColumn;
@FXML
private TableColumn<Patient, String> lastNameColumn;
@FXML
private TableColumn<Patient, String> postCodeColumn;
private ObservableList<Patient> tableData;
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
assert tableView != null : "fx:id=\"tableView\" was not injected: check your FXML file 'FXMLQueueTabPage.fxml'";
firstNameColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("firstName"));
lastNameColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("lastName"));
postCodeColumn.setCellValueFactory(new PropertyValueFactory<Patient, String>("postCode"));
}
public void displayQueue(List<Patient> queue) {
tableData = FXCollections.observableArrayList();
System.out.println("Starting display queue method in qtc + value of firstNameColumn = " + firstNameColumn);
for (Patient patient : queue) {
System.out.println(patient.getFirstName());
System.out.println(patient.getLastName());
System.out.println(patient.getPostCode());
System.out.println(patient.getTriage());
// tableData.addAll(queue);
tableData.add(patient);
System.out.println(tableData);
}
tableView.setItems(tableData);
refreshTable();
}
void refreshTable() {
final List<Patient> items = tableView.getItems();
if( items == null || items.size() == 0) return;
final Patient item = tableView.getItems().get(0);
items.remove(0);
Platform.runLater(new Runnable(){
@Override
public void run() {
items.add(0, item);
}
});
}
}
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="770.0" prefWidth="1000.0" stylesheets="@../styles/QueueTabPage.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.QueueTabPageController">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#517da6" height="156.0" stroke="BLACK" strokeType="INSIDE" styleClass="rectangle-pane" width="1065.0" />
<Label layoutX="349.0" layoutY="62.0" styleClass="label-queueTitle" stylesheets="@../styles/QueueTabPage.css" text="Accident & Emergency Queue">
<font>
<Font size="30.0" />
</font>
</Label>
<TableView fx:id="tableView" layoutX="242.0" layoutY="276.0" prefHeight="384.0" prefWidth="718.0">
<columns>
<TableColumn fx:id="firstNameColumn" prefWidth="122.0" text="First name" />
<TableColumn fx:id="lastNameColumn" prefWidth="144.0" text="Last name" />
<TableColumn fx:id="postCodeColumn" prefWidth="158.0" text="Time waiting" />
</columns>
</TableView>
</children>
</AnchorPane>
@FXML
private TableView<Patient> tableView = new TableView<Patient>();
@FXML
private TableView<Patient> tableView;