Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在JavaFX中切换图像 我现在的问题是,我目前在用java和JavaFX和图形进行比较,我仍然认为自己是个业余爱好者,我正在制作一个小像素游戏,只是为了提高我的图形知识和经验。我想在几个图像之间切换,只是为了模拟我创建的像素角色的“反弹”,只是为了给程序增加一点活力,但我在想如何做到这一点上遇到了很多困难,我花了相当长的时间试图找到解决我的特定问题的方法,但没有用。如果您能提供任何帮助,我将不胜感激。如果您愿意的话,请提供有关改进我的代码以及我所犯错误的提示。谢谢你抽出时间。对不起,如果我粘贴错误的代码,第一时间 package view; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.TextAlignment; import javafx.stage.Stage; // import JavaFX classes: Application, Stage, Scene, HBox, and Label. public class JavaFXTesting extends Application { Stage window; Scene sceneIntro, sceneFBM; public static void main(String[] args) { // Launch the application. launch(args); } @Override public void start(Stage primaryStage) throws Exception { window = primaryStage; int loop = 0; primaryStage.getIcons().add(new Image("file:PixelChar.png")); Image pixelScene1 = new Image("file:PixelScene.png"); Image pixelScene2 = new Image("file:PixelScene2.png"); ImageView pixScene1 = new ImageView(pixelScene1); ImageView pixScene2 = new ImageView(pixelScene2); pixScene1.setPreserveRatio(true); pixScene2.setPreserveRatio(true); pixScene1.setFitWidth(400); pixScene1.setFitHeight(350); pixScene2.setFitWidth(400); pixScene2.setFitHeight(350); Label promptWelcome = new Label(":Welcome To Meme Adventure!:"); Label promptIntro = new Label("You are currently playing the pre pre pre pre Alpha version\n" + " of Meme Adventrue, which involves you memeing on various enemies.\nEnjoy!"); Label promptAction = new Label("Oh no! a wild FeelsBadMan as appeared!\n Quickly! Attack it."); promptWelcome.setFont(new Font("Impact", 20)); promptIntro.setTextAlignment(TextAlignment.CENTER); promptAction.setTextAlignment(TextAlignment.CENTER); promptIntro.setFont(new Font("Franklin Gothic Demi", 13)); promptAction.setFont(new Font("Franklin Gothic Demi", 13)); promptIntro.setWrapText(true); promptAction.setWrapText(true); Button switchButton = new Button("Meme!"); switchButton.setOnAction(e -> window.setScene(sceneFBM)); Button testButton = new Button("Attack!"); testButton.setOnAction(e -> window.setScene(sceneIntro)); Button exitOption1 = new Button("Exit Program"); exitOption1.setOnAction(e -> window.close()); Button exitOption2 = new Button("Exit Program"); exitOption2.setOnAction(e -> window.close()); HBox buttonLayout2 = new HBox(10, exitOption1, switchButton); VBox intro = new VBox(10, pixScene1, promptWelcome, promptIntro, buttonLayout2); HBox buttonLayout1 = new HBox(10, exitOption2, testButton); VBox intro2 = new VBox(10, pixScene2, promptAction, buttonLayout1); intro.setAlignment(Pos.CENTER); intro.setPadding(new Insets(10)); intro2.setAlignment(Pos.CENTER); buttonLayout1.setAlignment(Pos.CENTER); buttonLayout2.setAlignment(Pos.CENTER); intro2.setPadding(new Insets(10)); sceneIntro = new Scene(intro); sceneFBM = new Scene(intro2); window.setScene(sceneIntro); window.setTitle("Meme Adventures"); window.show(); } }_Java_Image_Javafx_Imageview_Scene - Fatal编程技术网

如何在JavaFX中切换图像 我现在的问题是,我目前在用java和JavaFX和图形进行比较,我仍然认为自己是个业余爱好者,我正在制作一个小像素游戏,只是为了提高我的图形知识和经验。我想在几个图像之间切换,只是为了模拟我创建的像素角色的“反弹”,只是为了给程序增加一点活力,但我在想如何做到这一点上遇到了很多困难,我花了相当长的时间试图找到解决我的特定问题的方法,但没有用。如果您能提供任何帮助,我将不胜感激。如果您愿意的话,请提供有关改进我的代码以及我所犯错误的提示。谢谢你抽出时间。对不起,如果我粘贴错误的代码,第一时间 package view; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.TextAlignment; import javafx.stage.Stage; // import JavaFX classes: Application, Stage, Scene, HBox, and Label. public class JavaFXTesting extends Application { Stage window; Scene sceneIntro, sceneFBM; public static void main(String[] args) { // Launch the application. launch(args); } @Override public void start(Stage primaryStage) throws Exception { window = primaryStage; int loop = 0; primaryStage.getIcons().add(new Image("file:PixelChar.png")); Image pixelScene1 = new Image("file:PixelScene.png"); Image pixelScene2 = new Image("file:PixelScene2.png"); ImageView pixScene1 = new ImageView(pixelScene1); ImageView pixScene2 = new ImageView(pixelScene2); pixScene1.setPreserveRatio(true); pixScene2.setPreserveRatio(true); pixScene1.setFitWidth(400); pixScene1.setFitHeight(350); pixScene2.setFitWidth(400); pixScene2.setFitHeight(350); Label promptWelcome = new Label(":Welcome To Meme Adventure!:"); Label promptIntro = new Label("You are currently playing the pre pre pre pre Alpha version\n" + " of Meme Adventrue, which involves you memeing on various enemies.\nEnjoy!"); Label promptAction = new Label("Oh no! a wild FeelsBadMan as appeared!\n Quickly! Attack it."); promptWelcome.setFont(new Font("Impact", 20)); promptIntro.setTextAlignment(TextAlignment.CENTER); promptAction.setTextAlignment(TextAlignment.CENTER); promptIntro.setFont(new Font("Franklin Gothic Demi", 13)); promptAction.setFont(new Font("Franklin Gothic Demi", 13)); promptIntro.setWrapText(true); promptAction.setWrapText(true); Button switchButton = new Button("Meme!"); switchButton.setOnAction(e -> window.setScene(sceneFBM)); Button testButton = new Button("Attack!"); testButton.setOnAction(e -> window.setScene(sceneIntro)); Button exitOption1 = new Button("Exit Program"); exitOption1.setOnAction(e -> window.close()); Button exitOption2 = new Button("Exit Program"); exitOption2.setOnAction(e -> window.close()); HBox buttonLayout2 = new HBox(10, exitOption1, switchButton); VBox intro = new VBox(10, pixScene1, promptWelcome, promptIntro, buttonLayout2); HBox buttonLayout1 = new HBox(10, exitOption2, testButton); VBox intro2 = new VBox(10, pixScene2, promptAction, buttonLayout1); intro.setAlignment(Pos.CENTER); intro.setPadding(new Insets(10)); intro2.setAlignment(Pos.CENTER); buttonLayout1.setAlignment(Pos.CENTER); buttonLayout2.setAlignment(Pos.CENTER); intro2.setPadding(new Insets(10)); sceneIntro = new Scene(intro); sceneFBM = new Scene(intro2); window.setScene(sceneIntro); window.setTitle("Meme Adventures"); window.show(); } }

如何在JavaFX中切换图像 我现在的问题是,我目前在用java和JavaFX和图形进行比较,我仍然认为自己是个业余爱好者,我正在制作一个小像素游戏,只是为了提高我的图形知识和经验。我想在几个图像之间切换,只是为了模拟我创建的像素角色的“反弹”,只是为了给程序增加一点活力,但我在想如何做到这一点上遇到了很多困难,我花了相当长的时间试图找到解决我的特定问题的方法,但没有用。如果您能提供任何帮助,我将不胜感激。如果您愿意的话,请提供有关改进我的代码以及我所犯错误的提示。谢谢你抽出时间。对不起,如果我粘贴错误的代码,第一时间 package view; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.TextAlignment; import javafx.stage.Stage; // import JavaFX classes: Application, Stage, Scene, HBox, and Label. public class JavaFXTesting extends Application { Stage window; Scene sceneIntro, sceneFBM; public static void main(String[] args) { // Launch the application. launch(args); } @Override public void start(Stage primaryStage) throws Exception { window = primaryStage; int loop = 0; primaryStage.getIcons().add(new Image("file:PixelChar.png")); Image pixelScene1 = new Image("file:PixelScene.png"); Image pixelScene2 = new Image("file:PixelScene2.png"); ImageView pixScene1 = new ImageView(pixelScene1); ImageView pixScene2 = new ImageView(pixelScene2); pixScene1.setPreserveRatio(true); pixScene2.setPreserveRatio(true); pixScene1.setFitWidth(400); pixScene1.setFitHeight(350); pixScene2.setFitWidth(400); pixScene2.setFitHeight(350); Label promptWelcome = new Label(":Welcome To Meme Adventure!:"); Label promptIntro = new Label("You are currently playing the pre pre pre pre Alpha version\n" + " of Meme Adventrue, which involves you memeing on various enemies.\nEnjoy!"); Label promptAction = new Label("Oh no! a wild FeelsBadMan as appeared!\n Quickly! Attack it."); promptWelcome.setFont(new Font("Impact", 20)); promptIntro.setTextAlignment(TextAlignment.CENTER); promptAction.setTextAlignment(TextAlignment.CENTER); promptIntro.setFont(new Font("Franklin Gothic Demi", 13)); promptAction.setFont(new Font("Franklin Gothic Demi", 13)); promptIntro.setWrapText(true); promptAction.setWrapText(true); Button switchButton = new Button("Meme!"); switchButton.setOnAction(e -> window.setScene(sceneFBM)); Button testButton = new Button("Attack!"); testButton.setOnAction(e -> window.setScene(sceneIntro)); Button exitOption1 = new Button("Exit Program"); exitOption1.setOnAction(e -> window.close()); Button exitOption2 = new Button("Exit Program"); exitOption2.setOnAction(e -> window.close()); HBox buttonLayout2 = new HBox(10, exitOption1, switchButton); VBox intro = new VBox(10, pixScene1, promptWelcome, promptIntro, buttonLayout2); HBox buttonLayout1 = new HBox(10, exitOption2, testButton); VBox intro2 = new VBox(10, pixScene2, promptAction, buttonLayout1); intro.setAlignment(Pos.CENTER); intro.setPadding(new Insets(10)); intro2.setAlignment(Pos.CENTER); buttonLayout1.setAlignment(Pos.CENTER); buttonLayout2.setAlignment(Pos.CENTER); intro2.setPadding(new Insets(10)); sceneIntro = new Scene(intro); sceneFBM = new Scene(intro2); window.setScene(sceneIntro); window.setTitle("Meme Adventures"); window.show(); } },java,image,javafx,imageview,scene,Java,Image,Javafx,Imageview,Scene,一个可能的错误是,在构建图像时,将文件:放在文件名之前。这可以通过在创建图像后添加这行代码来证明 System.out.println(pixelScene1.isError()); 即使文件存在,也会返回true。尝试删除您在第37、39和39行看到的文件

一个可能的错误是,在构建图像时,将
文件:
放在文件名之前。这可以通过在创建图像后添加这行代码来证明

System.out.println(pixelScene1.isError());
即使文件存在,也会返回true。尝试删除您在第37、39和39行看到的
文件