资源预览内容
第1页 / 共45页
第2页 / 共45页
第3页 / 共45页
第4页 / 共45页
第5页 / 共45页
第6页 / 共45页
第7页 / 共45页
第8页 / 共45页
第9页 / 共45页
第10页 / 共45页
亲,该文档总共45页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
01import javafx.application.Application;import javafx.geometry.Pos;import javafx.scene.Scene;import javafx.scene.layout.GridPane;import javafx.stage.Stage;import javafx.scene.image.ImageView;public class Exercise14_01 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) GridPane pane = new GridPane(); pane.setAlignment(Pos.CENTER); pane.setHgap(5); pane.setVgap(5); ImageView imageView1 = new ImageView(image/uk.gif); ImageView imageView2 = new ImageView(image/ca.gif); ImageView imageView3 = new ImageView(image/china.gif); ImageView imageView4 = new ImageView(image/us.gif); pane.add(imageView1, 0, 0); pane.add(imageView2, 1, 0); pane.add(imageView3, 0, 1); pane.add(imageView4, 1, 1); / Create a scene and place it in the stage Scene scene = new Scene(pane); primaryStage.setTitle(Exercise14_01); / Set the stage title primaryStage.setScene(scene); / Place the scene in the stage primaryStage.show(); / Display the stage /* * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String args) launch(args); 02import javafx.application.Application;import javafx.geometry.Pos;import javafx.scene.Scene;import javafx.scene.layout.GridPane;import javafx.stage.Stage;import javafx.scene.image.ImageView;import javafx.scene.image.Image;public class Exercise14_02 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) Image imageX = new Image(image/x.gif); Image imageO = new Image(image/o.gif); GridPane pane = new GridPane(); pane.setAlignment(Pos.CENTER); pane.setHgap(5); pane.setVgap(5); for (int i = 0; i 3; i+) for (int j = 0; j 3; j+) int status = (int)(Math.random() * 3); if (status = 0) pane.add(new ImageView(imageX), j, i); else if (status = 1) pane.add(new ImageView(imageO), j, i); / Create a scene and place it in the stage Scene scene = new Scene(pane); primaryStage.setTitle(Exercise14_02); / Set the stage title primaryStage.setScene(scene); / Place the scene in the stage primaryStage.show(); / Display the stage /* * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String args) launch(args); 03import java.util.ArrayList;import javafx.application.Application;import javafx.geometry.Pos;import javafx.scene.Scene;import javafx.scene.layout.HBox;import javafx.stage.Stage;import javafx.scene.image.ImageView;public class Exercise14_03 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) / There are two ways for shuffling. One is to use the hint in the book. / The other way is to use the static shuffle method in the java.util.Collections class. ArrayList list = new ArrayList(); for (int i = 1; i = 52; i+) list.add(i); java.util.Collections.shuffle(list); HBox pane = new HBox(5); pane.setAlignment(Pos.CENTER); pane.getChildren().add(new ImageView(image/card/ + list.get(0) + .png); pane.getChildren().add(new ImageView(image/card/ + list.get(1) + .png); pane.getChildren().add(new ImageView(image/card/ + list.get(2) + .png); / Create a scene and place it in the stage Scene scene = new Scene(pane); primaryStage.setTitle(Exercise14_03); / Set the stage title primaryStage.setScene(scene); / Place the scene in the stage primaryStage.show(); / Display the stage /* * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String args) launch(args); 04import javafx.application.Application;import javafx.geometry.Pos;import javafx.scene.Scene;import javafx.scene.layout.HBox;import javafx.scene.paint.Color;import javafx.scene.text.Font;import javafx.scene.text.FontPosture;import javafx.scene.text.FontWeight;import javafx.scene.text.Text;import javafx.stage.Stage;public class Exercise14_04 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) HBox pane = new HBox(); pane.setAlignment(Pos.CENTER); Font font = Font.font(Times New Roman, FontWeight.BOLD,
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号