Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.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 - Fatal编程技术网

JavaFX:如何为我的舞台设置背景图像

JavaFX:如何为我的舞台设置背景图像,java,Java,我正在为弹跳球程序编写代码,到目前为止一切都正常,但我不知道如何为我的舞台设置背景图像。我是java的初学者(很明显),并尝试使用ImageView类为我的舞台设置背景。但到目前为止运气不好 非常感谢你 package particlesystemexample; import javafx.application.Application; import static javafx.application.Application.launch; import javafx.event.Acti

我正在为弹跳球程序编写代码,到目前为止一切都正常,但我不知道如何为我的舞台设置背景图像。我是java的初学者(很明显),并尝试使用ImageView类为我的舞台设置背景。但到目前为止运气不好

非常感谢你

package particlesystemexample;

import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;


public class ParticleSystemExample extends Application {

@Override
public void start(Stage primaryStage) {
    ParticleAnimationPane paPane = new ParticleAnimationPane();

    // mouse actions to pause and resume animation
    //paPane.setOnMousePressed(e -> paPane.pause()); // Java 8.0
    paPane.setOnMousePressed(new EventHandler<MouseEvent>() {  
        public void handle(MouseEvent me) {  
                    paPane.init();            }  
    }); 

    // paPane.setOnMouseReleased(e -> paPane.play()); // Java 8.0
    paPane.setOnMouseReleased(new EventHandler<MouseEvent>() {  
        public void handle(MouseEvent me) {  
                    paPane.play();            }  
    }); 


    // buttons to increase and decrease animation speed
    paPane.setOnKeyPressed(e -> {
        if(e.getCode() == KeyCode.UP){
            paPane.increaseSpeed();
        }
        else if (e.getCode() == KeyCode.DOWN){
            paPane.decreaseSpeed();
        }
    });

    // Create a scene and place it on stage
    Scene scene = new Scene(paPane, 450, 350);
    primaryStage.setTitle("Particle System Example");
    primaryStage.setScene(scene);
    primaryStage.show();
    paPane.init(); // initialize the particles

    paPane.requestFocus();
}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);
}

就我个人而言,我使用BuffereImage和Image类来处理我所有的映像需求。 您可以将Image类用于此类

以下是一个例子:

try {
    Graphics.drawImage(ImageIO.read(new File("Picture.png")), fX, fY, fW, fH, sX, sY, sW, sH,null);
} catch (IOException e) {
    e.printStackTrace();
}
以F开头的东西是你要画的矩形的边界

以s开头的东西是你正在画的画的哪一部分的界限


我不太确定结尾的null对应什么。我只是忽略了它,一切都正常。

在创建场景后,您在哪里尝试使用ImageView类
try {
    Graphics.drawImage(ImageIO.read(new File("Picture.png")), fX, fY, fW, fH, sX, sY, sW, sH,null);
} catch (IOException e) {
    e.printStackTrace();
}