如何在JavaFX中更新图像

时间:2013-08-31 02:47:44

标签: function imageview javafx-2 javafx

我想更改嵌入在JavaFX边框窗格中的图像,将根据在buildData_timer函数中计算的月相选择和设置图像。

如何从定时器功能设置图像。我不知道怎么样?

    @Override public void init() {
....

    buildData_timer = new AnimationTimer() {
                @Override public void handle(long now) {
                    if (now > buildData_lastTimerCall + 1000000_000_000l) {

                        try {
                            buildData_calculate();
                        } catch (Exception ex) {
                            Logger.getLogger(JavaFXApplication4.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        buildData_lastTimerCall = now;
                    }
                }
            };
    }

这是启动功能

 @Override public void start(Stage stage) {

....
        BorderPane Moonpane = new BorderPane();
        Moonpane.setId("prayertime_pane");
        Moonpane.setPadding(new Insets(10, 10, 10, 10));
        Moonpane.setMaxSize(380,70);
        Moonpane.setMinSize(380,70);

        Phase_Label.setId("moon-text-english");
        Moonpane.setRight(Phase_Label);

        ImageView Moon_img = new ImageView(new Image(getClass().getResourceAsStream("/Images/Moon/0%.png")));      
        Moon_img.setFitWidth(100);
        Moon_img.setFitHeight(100);
        Moon_img.setPreserveRatio(true);
        Moon_img.setSmooth(true);
        Moonpane.setCenter(Moon_img);   

        Moon_Date_Label.setId("moon-text-english");
        Moonpane.setLeft(Moon_Date_Label);

        Mainpane.add(Moonpane, 9, 1,3,2);
        Mainpane.add(clock1Box, 1, 1,4,4);    
        Mainpane.add(prayertime_pane, 7, 6,7,7);

        stage.show();
        buildData_timer.start();}

这是计时器功能

public void buildData_calculate() throws Exception{

     Moon m = new Moon();  
     System.out.println("The moon is " + m.illuminatedPercentage() + "% full and " + (m.isWaning() ? "waning" : "waxing"));

     String date = new SimpleDateFormat("EEEE dd'th' MMM").format(MoonPhaseFinder.findFullMoonFollowing(Calendar.getInstance()));

     Moon_Date_Label.setText("Next Full Moon is on\n" + date);

        }    

0 个答案:

没有答案