1、java语言程序设计基础篇第十版第十四章练习答案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 i
2、n 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(
3、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
4、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); 02i
5、mport 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 met
6、hod 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 stat
7、us = (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、setScen
8、e(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 jav
9、afx、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 star
10、t(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 p
11、ane = 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 t
12、he 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 runn
13、ing 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、FontPos
14、ture;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); F
15、ont font = Font、font(Times New Roman, FontWeight、BOLD, FontPosture、ITALIC, 22); for (int i = 0; i 5; i+) Text txt = new Text(Java); txt、setRotate(90); txt、setFont(font); txt、setFill(new Color(Math、random(), Math、random(), Math、random(), Math、random(); pane、getChildren()、add(txt); / Create a scene an
16、d place it in the stage Scene scene = new Scene(pane, 200, 100); primaryStage、setTitle(Exercise14_04); / 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 sup
17、port、 Not needed for running from the command line、 */ public static void main(String args) launch(args); 05import javafx、application、Application;import javafx、scene、Scene;import javafx、scene、layout、Pane;import javafx、scene、text、Font;import javafx、scene、text、FontPosture;import javafx、scene、text、Font
18、Weight;import javafx、scene、text、Text;import javafx、stage、Stage;public class Exercise14_05 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) Pane pane = new Pane(); Font font = Font、font(Times New Roman, FontWeight、BOLD, FontPostur
19、e、REGULAR, 35); String s = WELCOME TO JAVA ; double radius = 80; for (int i = 0; i s、length(); i+) double alpha = 2 * Math、PI * (s、length() - i) / s、length(); Text txt = new Text(radius * Math、cos(alpha) + 120, 120 - radius * Math、sin(alpha), s、charAt(i) + ); txt、setFont(font); txt、setRotate(360 * i
20、 / s、length() + 90); pane、getChildren()、add(txt); / Create a scene and place it in the stage Scene scene = new Scene(pane, 240, 240); primaryStage、setTitle(Exercise14_05); / Set the stage title primaryStage、setScene(scene); / Place the scene in the stage primaryStage、show(); / Display the stage /* *
21、 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); 05import javafx、application、Application;import javafx、scene、Scene;import javafx、scene、layout、Pane;import javafx、scene、text、Fo
22、nt;import javafx、scene、text、FontPosture;import javafx、scene、text、FontWeight;import javafx、scene、text、Text;import javafx、stage、Stage;public class Exercise14_05 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) Pane pane = new Pane(
23、); Font font = Font、font(Times New Roman, FontWeight、BOLD, FontPosture、REGULAR, 35); String s = WELCOME TO JAVA ; double radius = 80; for (int i = 0; i s、length(); i+) double alpha = 2 * Math、PI * (s、length() - i) / s、length(); Text txt = new Text(radius * Math、cos(alpha) + 120, 120 - radius * Math、
24、sin(alpha), s、charAt(i) + ); txt、setFont(font); txt、setRotate(360 * i / s、length() + 90); pane、getChildren()、add(txt); / Create a scene and place it in the stage Scene scene = new Scene(pane, 240, 240); primaryStage、setTitle(Exercise14_05); / Set the stage title primaryStage、setScene(scene); / Place
25、 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); 06import javafx、application、Application;import javafx、sc
26、ene、Scene;import javafx、scene、layout、Pane;import javafx、scene、paint、Color;import javafx、stage、Stage;import javafx、scene、shape、Rectangle;public class Exercise14_06 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) double WIDTH = 20
27、0; double HEIGHT = 200; Pane pane = new Pane(); for (int i = 0; i 8; i+) boolean isWhite = i % 2 = 0; for (int j = 0; j 8; j+) Rectangle rectangle = new Rectangle(i * WIDTH / 8, j * HEIGHT / 8, WIDTH / 8, HEIGHT / 8); rectangle、setStroke(Color、BLACK); if (isWhite) rectangle、setFill(Color、WHITE); els
28、e rectangle、setFill(Color、BLACK); isWhite = !isWhite; pane、getChildren()、add(rectangle); / Create a scene and place it in the stage Scene scene = new Scene(pane, WIDTH, HEIGHT); primaryStage、setTitle(Exercise14_06); / Set the stage title primaryStage、setScene(scene); / Place the scene in the stage p
29、rimaryStage、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); 07import javafx、application、Application;import javafx、geometry、Pos;import javafx、
30、scene、Scene;import javafx、scene、control、TextField;import javafx、scene、layout、GridPane;import javafx、stage、Stage;public class Exercise14_07 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) double WIDTH = 200; double HEIGHT = 200; GridPane pane = new GridPane(); for (int i = 0; i 10; i+) for (int j = 0; j 10; j+) TextField tf = new Te
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1