Anonymní profil goddard – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

Anonymní profil goddard – Programujte.comAnonymní profil goddard – Programujte.com

 

Příspěvky odeslané z IP adresy 89.102.5.–

goddard
Java › prepinanie obrazkov
24. 2. 2013   #171987

ahoj,

tady je priklad jak by to slo udelat v JavaFX (priklad funguje pokud si nastavis cestu k obrazkum):

package animatedlabel;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.animation.TimelineBuilder;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 *
 * @author jiri - www.dredwerkz.cz
 */
public class AnimatedLabel extends Application {

  @Override
  public void start(Stage primaryStage) {
    Image p1 = new Image("file:///home/jiri/NetBeansProjects/AnimatedLabel/p1.jpg");
    Image p2 = new Image("file:///home/jiri/NetBeansProjects/AnimatedLabel/p2.jpg");
    Image p3 = new Image("file:///home/jiri/NetBeansProjects/AnimatedLabel/p3.jpg");
    final Image[] imgs = {p1, p2, p3};
    final ImageView view = new ImageView();
    
    TimelineBuilder.create()
      .keyFrames(new KeyFrame(Duration.seconds(1), new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent ae) {
          view.setImage(imgs[0]);
        }
      }),
      new KeyFrame(Duration.seconds(2), new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent ae) {
          view.setImage(imgs[1]);
        }
      }),
      new KeyFrame(Duration.seconds(3), new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent ae) {
          view.setImage(imgs[2]);
        }
      }))
      .cycleCount(Timeline.INDEFINITE)
      .build()
      .play();

    Label l = new Label("I'm your animated label", view);
    StackPane root = new StackPane();
    root.getChildren().add(l);

    Scene scene = new Scene(root, 500, 500);

    primaryStage.setTitle("Animated Label");
    primaryStage.setScene(scene);
    primaryStage.show();
  }

  /**
   * The main() method is ignored in correctly deployed JavaFX application.
   * main() serves only as fallback in case the application can not be launched
   * through deployment artifacts, e.g., in IDEs with limited FX support.
   * NetBeans ignores main().
   *
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    launch(args);
  }
}
goddard
Java › JavaFX 3D Early Access
19. 2. 2013   #171705
goddard
Java › JavaFX na mobilu
13. 2. 2013   #171475

 

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý