我正在重写我的问题,因为我很难找到这个解决方案.我已经做了一个简单的表格来注册一些你知道姓名,姓氏等的学生的基本信息.它还可以选择filechooser类从文件系统中查找图片.
我们来看看这段代码.
@FXML
public void onBrowserPhoto() throws IOException {
File file = fileChooser.showOpenDialog(stage);
if (file != null) {
is = new FileInputStream(file);
Image image = new Image(is);
imageView.setImage(image);
}
}
Run Code Online (Sandbox Code Playgroud)
在当用户点击按钮这一点,他们将选择一个图片然后我创建了一个新的FileInputStream,并说明是变量,它是一个对象inputream.
private void businessOnSave() {
if (currentStudent.getId() == 0) {
try {
currentStudent.setIs(is);
currentStudent
.setGenger(buttonMale.isSelected() == true ? buttonMale.getText() : buttonFemale.getText());
if (!checkStudent(currentStudent)) {
service.saveStudent(currentStudent);
studentUnBind(currentStudent);
sweep();
listView.getItems().add(currentStudent.getNickname());
buttonNew.disableProperty().setValue(false);
is.close();
} else {
return;
}
} catch (ServiceException | IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
当使用点击保存按钮时,将调用此方法,并且currentStudent变量接收该输入流(是)接下来它将执行一些操作然后我将其与服务对象一起保存.Everithing是完美的学生obj得救.
这是保存新学生的方法
@Override …Run Code Online (Sandbox Code Playgroud) javafx-8 ×1