《java语言程序设计基础篇第十版第十四章练习答案》由会员分享,可在线阅读,更多相关《java语言程序设计基础篇第十版第十四章练习答案(45页珍藏版)》请在金锄头文库上搜索。
1、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
2、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); ImageV
3、iew 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 primaryS
4、tage.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
5、.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 c
6、lass 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()
7、 * 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 sc
8、ene 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.Applicat
9、ion;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) /
10、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.
11、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 = n
12、ew 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 lin
13、e. */ 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
14、.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,