JavaFx Stageshow 3个不同的阶段

时间:2016-09-07 12:28:02

标签: java javafx

我有3级,3级,我想做这样的事情:我想做秀舞台。有一次我显示第1阶段10秒,接下来我显示第2阶段10秒然后我显示第3阶段10秒然后我显示第1 ....但是非常重要的是3阶段必须一直工作

在摇摆中我将使用CardLayout但在这里我不知道这是怎么做的。

一个类的代码:

public class SimpleSlideShowTest extends Application{

  class SimpleSlideShow {

    StackPane root = new StackPane();
    ImageView[] slides;

    public SimpleSlideShow() {
      this.slides = new ImageView[4];

      File file1 = new File("C:/Users/022/workspace22/EkranLCD/res/images/belka.png");
      Image image1 = new Image(file1.toURI().toString());
      File file = new File("C:/Users/022/workspace22/EkranLCD/res/images/kropka.png");
      Image image2 = new Image(file.toURI().toString());


      Image image3 = new Image(file1.toURI().toString());
      Image image4 = new Image(file1.toURI().toString());
      slides[0] = new ImageView(image1);
      slides[1] = new ImageView(image2);
      slides[2] = new ImageView(image3);
      slides[3] = new ImageView(image4);

    }

    public StackPane getRoot() {
      return root;
    }

    // The method I am running in my class

    public void start() {

      SequentialTransition slideshow = new SequentialTransition();

      for (ImageView slide : slides) {

        SequentialTransition sequentialTransition = new SequentialTransition();

        FadeTransition fadeIn = getFadeTransition(slide, 0.0, 1.0, 0);
        PauseTransition stayOn = new PauseTransition(Duration.millis(2000));
        FadeTransition fadeOut = getFadeTransition(slide, 0, 0.0, 2000);

        sequentialTransition.getChildren().addAll(fadeIn, stayOn, fadeOut);
        slide.setOpacity(0);
        this.root.getChildren().add(slide);
        slideshow.getChildren().add(sequentialTransition);

      }
      slideshow.play();
    }

// the method in the Transition helper class:

    public FadeTransition getFadeTransition(ImageView imageView, double fromValue, double toValue, int durationInMilliseconds) {

      FadeTransition ft = new FadeTransition(Duration.millis(durationInMilliseconds), imageView);
      ft.setFromValue(fromValue);
      ft.setToValue(toValue);
      return ft;

    }
  }

  public static void main(String[] args) {
    launch(args);
  }

  @Override
  public void start(Stage primaryStage) throws Exception {
    SimpleSlideShow simpleSlideShow = new SimpleSlideShow();
    Text msg = new Text("java2s.com d sad adas dsa sad dsa dsa dsa dsa sdasa dsa dsa");
    msg.setFont(Font.font ("Verdana", 40));
    msg.setY(Config.ySize-(Config.ySize/6));
    Pane root1 = new Pane(msg);
    root1.setLayoutX(Config.xSize/2);
    root1.setLayoutY(Config.ySize-(Config.ySize/5));
    root1.setPrefSize(Config.xSize/2,400);
     Main2.start(msg);  
    simpleSlideShow.getRoot().getChildren().add(root1);
    Scene scene = new Scene(simpleSlideShow.getRoot());
    primaryStage.setScene(scene);
    primaryStage.show();
    simpleSlideShow.start();
  }
}

我要添加的第二堂课

public class TestURLImage4 extends Application {

    public static ArrayList<BusStop2> list = new ArrayList<>();
    public static ArrayList<PositionTilesAndURLPaths> positionTilesAndURLPathsList = new ArrayList<>();
    public static HashMap<String, Image> imgCache = new HashMap<>();
    public static double lat;
    public static double lon;
    public static double deltaY;
    public static double deltaX;
    public static double positionX;
    public static double positionY;
    public static int[] imageCount = getCountImage();
    public static int [] countImage = countImage();
    public static int []x = new int [countImage[0]];
    public static int []y = new int [countImage[1]];
    private File file = new File("C:/Users/ElteGps 022/workspace22/EkranLCD/res/images/kropka.png");
    private Image bus = new Image(file.toURI().toString());

    public TestURLImage4() {
    }
    TestURLImage4(double lat, double lon){
        int [] tiles= getTileNumber(lat, lon, Config.mapZoom);
        deltaX = tile2lon(tiles[0] + 1 , Config.mapZoom) -  tile2lon(tiles[0], Config.mapZoom);
        deltaY = tile2lat(tiles[1], Config.mapZoom) - tile2lat(tiles[1] + 1 , Config.mapZoom);
        positionX = (lon - tile2lon(tiles[0], Config.mapZoom)) * Config.imgSize/deltaX;
        positionY = (tile2lat(tiles[1], Config.mapZoom) - lat) * Config.imgSize/deltaY;
        getTiles(lat,lon);
        getImgPositionAndURLsPath(list);
    }

    /**
     * Method use to get count of image what we need 
     * @return
     */
    private static int[] getCountImage(){
        int xImageCount = (int) Math.ceil(Config.xSize/256);
        int yImageCount = (int) Math.ceil(Config.ySize/256);
        return  new int[] {xImageCount, yImageCount};
    }
    /**
     * Method use to get count of tiles
     * @return
     */
    public static int[] countImage(){
        int xImageCount = imageCount[0];
        int yImageCount = imageCount[1];
        if(xImageCount-1 %2 != 0){
            xImageCount = xImageCount + 2;
        }
        if(yImageCount-1 %2 != 0){
            yImageCount = yImageCount + 2;
        }
        return  new int[] {xImageCount, yImageCount};
    }
    /**
     * Method use to get tiles 
     * @param lat
     * @param lon
     * @return
     */
    private static  ArrayList<BusStop2> getTiles(double lat, double lon ){
        int [] numberTile = getTileNumber(lat, lon, Config.mapZoom);
        int a1 = 1;
        int a2 = 1;
        int a3 = 1;
        int a4 = 1;

        x[0] = numberTile[0];
        y[0] = numberTile[1];
          for (int i = 1; i<x.length; i++){
              if(i%2==0){
                  x[i] = numberTile[0]+(a1);
                  a1++;
              }
              else{
                  x[i] = numberTile[0]-(a2);
                  a2++;
              }
          }

          for (int i = 1; i<y.length; i++){
              if(i%2==0){
                  y[i] = numberTile[1]+(a3);
                  a3++;
              }
              else{
                  y[i] = numberTile[1]-(a4);
                  a4++;
              }
          }

          for(int i = 0 ; i<x.length ; i++){
              for (int j = 0 ;j<y.length ; j++ ){
                  list.add(new BusStop2(x[i], y[j], x[0] - x[i], y[0]-y[j]));       
              }
          }
        return list;
    }
    /**
     * 
     * @param list
     * @return
     */
    private static ArrayList<PositionTilesAndURLPaths> getImgPositionAndURLsPath(ArrayList<BusStop2> list){

        for(BusStop2 bus : list){
            positionTilesAndURLPathsList.add(new PositionTilesAndURLPaths(256*bus.getX(), 256*bus.getY(), 
                    Config.mapPath + "/" + bus.getA() + "/" + bus.getB() + ".png"));
        }
        return positionTilesAndURLPathsList;
    }

     public static int [] getTileNumber(final double lat, final double lon, final int zoom) {
           int xtile = (int)Math.floor( (lon + 180) / 360 * (1<<zoom) ) ;
           int ytile = (int)Math.floor( (1 - Math.log(Math.tan(Math.toRadians(lat)) + 1 / Math.cos(Math.toRadians(lat))) / Math.PI) / 2 * (1<<zoom) ) ;
            if (xtile < 0)
             xtile=0;
            if (xtile >= (1<<zoom))
             xtile=((1<<zoom)-1);
            if (ytile < 0)
             ytile=0;
            if (ytile >= (1<<zoom))
             ytile=((1<<zoom)-1);
            return  new int[] {xtile, ytile};
           }

     static double tile2lon(int x, int z) {
         return x / Math.pow(2.0, z) * 360.0 - 180;
      }

      static double tile2lat(int y, int z) {
        double n = Math.PI - (2.0 * Math.PI * y) / Math.pow(2.0, z);
        return Math.toDegrees(Math.atan(Math.sinh(n)));
      }
    @Override
    public void start(Stage stage) throws Exception {
        Canvas canvas = new Canvas(Config.xSize, Config.ySize);
        GraphicsContext gc = canvas.getGraphicsContext2D();

        int [] aa =getTileNumber(51.401968,16.205556, 18);
        getTiles(51.401968,16.205556);

        getImgPositionAndURLsPath(list);

        ExecutorService executor = Executors.newFixedThreadPool(10);
        ArrayList<UtlToImageConverter> threadList = new ArrayList<>(); 
        for(PositionTilesAndURLPaths url : positionTilesAndURLPathsList){
            threadList.add(new UtlToImageConverter(url.getPath()));
        }
        try {
            executor.invokeAll(threadList);
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
        System.out.println(imgCache.size());
        System.out.println( aa[0] + " " + aa[1] );

        for(PositionTilesAndURLPaths pos : getImgPositionAndURLsPath(list)){
            gc.drawImage(imgCache.get(pos.getPath()),Config.xSize/2-pos.getX()-Config.imgSize/2 ,(Config.ySize/2)- pos.getY()-Config.imgSize/2, Config.imgSize, Config.imgSize);
        }
        gc.drawImage(bus,Config.xSize/2-Config.imgSize/2-Config.markWidth/2+(int)positionX, Config.ySize/2+(int)positionY-Config.imgSize/2-Config.markHeight/2, Config.markWidth, Config.markHeight);



        Pane root = new Pane();
        root.getChildren().add(canvas);

        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();

    }
    public static void main(String[] args) 
    {

        Application.launch(args);
    }
}

0 个答案:

没有答案