3つのimageviewを並べて、1秒間隔で4つの画像を順番にずらして表示したいと思っています。
つまり、3つのimageviewに入っている画像を、入れ替えようと思っています。
3つのimageviewに入っているimageをどのように入れ替えればいいでしょうか?
Thread内では、画像を変えるための picNo0, picNo1, picNo2 を替えています。
Threadのsleepで1秒間隔は実現できると考えています。
よろしくお願い致します。
Java
1import javafx.application.*; 2import javafx.scene.*; 3import javafx.scene.layout.*; 4import javafx.scene.control.*; 5import javafx.scene.paint.*; 6import javafx.scene.image.*; 7import javafx.scene.effect.*; 8import javafx.stage.*; 9import javafx.geometry.*; 10import javafx.collections.*; 11 12public class Assignment5_3 extends Application 13{ 14 public static int picNo0 = 0; 15 public static int picNo1 = 1; 16 public static int picNo2 = 2; 17 18 public void start(Stage stage) throws Exception 19 { 20 Image[] images = new Image[4]; 21 images[0] = new Image("Food.jpg"); 22 images[1] = new Image("Cafe.jpg"); 23 images[2] = new Image("Beach.jpg"); 24 images[3] = new Image("Sunset.jpg"); 25 26 ImageView[] ivs = new ImageView[3]; 27 ivs[0] = new ImageView(images[picNo0]); 28 ivs[1] = new ImageView(images[picNo1]); 29 ivs[2] = new ImageView(images[picNo2]); 30 31 ivs[0].setImage(); 32 ivs[1].setImage(); 33 ivs[2].setImage(); 34 35 // エフェクトを生成し、画像に適用します 36 PerspectiveTransform pt0 = new PerspectiveTransform(); 37 pt0.setUlx(160.0); 38 pt0.setUly(60.0); 39 pt0.setUrx(320.0); 40 pt0.setUry(0.0); 41 pt0.setLrx(320.0); 42 pt0.setLry(240.0); 43 pt0.setLlx(160.0); 44 pt0.setLly(180.0); 45 ivs[0].setEffect(pt0); 46 47 PerspectiveTransform pt1 = new PerspectiveTransform(); 48 pt1.setUlx(0.0); 49 pt1.setUly(0.0); 50 pt1.setUrx(160.0); 51 pt1.setUry(60.0); 52 pt1.setLrx(160.0); 53 pt1.setLry(180.0); 54 pt1.setLlx(0.0); 55 pt1.setLly(240.0); 56 ivs[2].setEffect(pt1); 57 58 // レイアウト HBox を生成/設定します 59 HBox hb = new HBox(); 60 ObservableList<Node> lst = hb.getChildren(); 61 lst.addAll(ivs); 62 63 // シーンを生成/設定します 64 Scene scene = new Scene(hb); 65 66 // ステージを設定します 67 stage.setScene(scene); 68 stage.setTitle("画像"); 69 70 // ステージを表示します 71 stage.show(); 72 73 MyRunnable runnable = new MyRunnable(); 74 Thread thread = new Thread(runnable); 75 thread.start(); 76 } 77 78 public class MyRunnable implements Runnable 79 { 80 @Override 81 public void run() 82 { 83 while(true) 84 { 85 picNo0++; 86 picNo1++; 87 picNo2++; 88 89 if (picNo0 > 3) 90 { 91 picNo0 = 0; 92 // 1000ミリ秒待機する 93 try{ 94 Thread.sleep(1000); 95 }catch(InterruptedException e) 96 { 97 System.out.println(e); 98 } 99 }else if (picNo1 > 3) 100 { 101 picNo1 = 0; 102 // 1000ミリ秒待機する 103 try{ 104 Thread.sleep(1000); 105 }catch(InterruptedException e) 106 { 107 System.out.println(e); 108 } 109 }else if (picNo2 > 3) 110 { 111 picNo2 = 0; 112 // 1000ミリ秒待機する 113 try{ 114 Thread.sleep(1000); 115 }catch(InterruptedException e) 116 { 117 System.out.println(e); 118 } 119 }else 120 { 121 // 1000ミリ秒待機する 122 try{ 123 Thread.sleep(1000); 124 }catch(InterruptedException e) 125 { 126 System.out.println(e); 127 } 128 } 129 } 130 } 131 } 132 133 public static void main(String[] args) 134 { 135 launch(args); 136 } 137} 138
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。