我正在尝试使用JavaFX的Image和ImageView类显示图像,但它不起作用。
try {
String workingDir = System.getProperty("user.dir");
final File f = new File(workingDir, "src/chk.hrn.nye.movieplayer/img.png");
// System.out.println(workingDir);
// File file = new File(loadImage.class.getResource("img1.jpg").toString());
Image img = new Image(f.toURI().toString());
ImageView imv = new ImageView(img);
Group root = new Group();
root.getChildren().add(imv);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
System.out.println(e);
}