java语言程序设计基础篇第十版第十四章练习答案_第1页
java语言程序设计基础篇第十版第十四章练习答案_第2页
java语言程序设计基础篇第十版第十四章练习答案_第3页
java语言程序设计基础篇第十版第十四章练习答案_第4页
java语言程序设计基础篇第十版第十四章练习答案_第5页
已阅读5页,还剩105页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、java语言程序设计基础篇第十版第十四章练习答案 1/93 01 import 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 Exercise 14_01 extends Application Override / / Overrid

2、e the start method in the Application class public void start(Stage primaryStage) GridPane pane = new GridPaneQ; pane.setAlignment(Pos.CENTER); pane.setHgap(5); pane.setVgap(5); ImageView imageView 1 = new ImageView(Himage/uk.gif1); ImageView imageView2 = new ImageView(Mimage/ca.gifH); ImageView ima

3、geView3 = new ImageView(Himage/china. gifH); ImageView imageView4 = new ImageView(Himage/us. gifu); java语言程序设计基础篇第十版第十四章练习答案 2/93 pane.add(imageViewl, 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 =

4、 new Scene(pane); primaryStage.setTitle(Exercise 14_01 ); / / Set the stage title primaryStage.setScene(scene); / / Place the scene in the stage primaryStage.show(); / / Display the stage I * * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the

5、command line. V public static void main(String args) launch(args); java语言程序设计基础篇第十版第十四章练习答案 3/93 02 import 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; imp

6、ort javafx.scene.image.Image; public class Exercise 14_02 extends Application Override / / Override the start method in the Application class public void start(Stage primaryStage) Image imageX = new Image(nimage/x. gifH); Image imageO = new Image(Himage/o.gifM); GridPane pane = new GridPaneQ; pane.s

7、etAlignmentfPos.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) java语言程序设计基础篇第十版第十四章练习答案 4/93 pane.addfnew ImageView(imageX), j, i); | else if (status = 1) pane.addfnew ImageView(imageO), j, i); / / C

8、reate a scene and place it in the stage Scene scene = new Scene(pane); primaryStage.setTitle(Exercisel4_02); / / Set the stage title primaryStage.setScene(scene); / / Place the scene in the stage primaryStage.show(); / / Display the stage I * * The main method is only needed for the IDE with limited

9、 * JavaFX support. Not needed for running from the command line. java语言程序设计基础篇第十版第十四章练习答案 5/93 */ public static void main(String args) 6/93 java语言程序设计基础篇第十版第十四章练习答案 launch(args); 03 import j ava. util. Array Lis t; import javafx.application.Application; import javafx.geometry.Pos; import javafx.scen

10、e.Scene; import javafx.scene.layout.HBox; import javafx. stage. Stage; import javafx. scene.image.ImageView; public class Exercise 14_03 extends Application Override / / Override the start method in the Application class public void start(Stage primaryStage) / / There are two ways for shuffling. One

11、 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(); 7/93 for (int i = 1; i = 52; i+) java语言程序设计基础篇第十版第十四章练习答案 list.add(i); java.util. Collections .shuffle(list); HBox pane = new HBox(5); pane.set

12、AlignmentfPos.CENTER); pane. getChildrenQ. add (new ImageView(pimage/card/M + list.get(O) + .png); pane.getChildren().add(new ImageView(nimage/card/M + list.get(l) + .png); pane.getChildren().add(new ImageView(pimage/card/M + list.get(2) + .png); / / Create a scene and place it in the stage Scene sc

13、ene = new Scene(pane); primaryStage.setTitle(Exercisel4_03); / Set the stage title primaryStage.setScene(scene); / / Place the scene in the stage primaryStage.show(); / / Display the stagejava语言程序设计基础篇第十版第十四章练习答案 8/93 The main method is only needed for the IDE with limited JavaFX support. Not needed

14、 for running from the command line. */ public static void main(String args) launch(args); 04 import 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

15、.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import javafx.stage. Stage; public class Exercise 14_04 extends Application Override / / Override the start method in the Application java语言程序设计基础篇第十版第十四章练习答案 9/93 class public void start(Stage primaryStage)

16、 HBox pane = new HBoxQ; pane.setAlignment(Pos.CENTER); Font font = Font.font(Times New Roman, F ontW eight. BOLD, FontPosture.ITALIC, 22); for (int i = 0; i 5; i+) Text txt = new Text(Java); txt.s etRotat e(90); txt.s etF ont(font); txt.setFillfnew Color(Math.random(), Math.randomQ, Math.randomQ, Ma

17、th.randomQ); pane.getChildrenQ.add(txt); / / Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 100); primaryStage.setTitle(nExercisel4_04H); / Set the stage title java语言程序设计基础篇第十版第十四章练习答案 10/93 primaryStage.setScene(scene); / / Place the scene in the stage11/93 java语言程序设计基础

18、篇第十版第十四章练习答案 primaryStage.show(); / / Display the stage I * * 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); 05 import javafx.application.Application; import javafx.scene.Sc

19、ene; import javafx.scene.layout.Pane; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; 12/93 import javafx. stage. Stage; public class Exercise 14_05 extends Application java语言程序设计基础篇第十版第十四章练习答案 13 / 93 Override

20、/ / Override the start method in the Application class public void start(Stage primaryStage) Pane pane = new Pane(); Font font = Font.font(Times New Roman, F ontW eight. BOLD, FontPosture.REGULAR, 35); String s = WELCOME TO JAVA double radius = 80; for (int i = 0; i s.lengthQ; i+) double alpha = 2 *

21、 Math.PI * (s.lengthf) - i) / s.length); Text txt = new Text (radius * Math. cos (alpha) + 120, 120 - radius * Math, sin(alpha), s. char At (i) + txt. s etF ont(font); txt.setRotate(360 * i / s.lengthf) + 90); pane.getChildrenQ.add(txt); / / Create a scene and place it in the stage Scene scene = new

22、 Scene(pane, 240, 240); primaryStage.setTitle(uExercisel4_05M); / Set the stage java语言程序设计基础篇第十版第十四章练习答案 14 / 93 title primaryStage.setScene(scene); / / Place the scene in the stage primaryStage.show(); / / Display the stage I * * The main method is only needed for the IDE with limited * JavaFX supp

23、ort. Not needed for running from the command line. * / public static void main(String args) launch(args); 05 import 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.te

24、xt.FontWeight; java语言程序设计基础篇第十版第十四章练习答案 15 / 93 import javafx.scene.text.Text; import javafx. stage. Stage; public class Exercise 14_05 extends Application Override / / Override the start method in the Application class public void start(Stage primaryStage) Pane pane = new Pane(); Font font = Font.f

25、ont(Times New Roman, F ontW eight.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, sin(alpha), s. ch

26、ar At (i) + ); txt.s etF ont(font); txt.setRotate(360 * i / s.lengthf) + 90); pane.getChildren().add(txt); java语言程序设计基础篇第十版第十四章练习答案 16 / 93 / / Create a scene and place it in the stage Scene scene = new Scene(pane, 240, 240); primaryStage.setTitle(Exercisel4_05); / Set the stage title primaryStage.s

27、etScene(scene); / / Place the scene in the stage primaryStage.show(); / / Display the stage I * * 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); 06 java语言程序设计基础篇第十版第十四章练习答案

28、17 / 93 import javafx.application.Application; import javafx. scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx. stage. Stage; import javafx.scene.shape.Rectangle; public class Exercise 14_06 extends Application Override / / Override the start method in the

29、 Application class public void start(Stage primaryStage) double WIDTH = 200; double HEIGHT = 200; Pane pane = new Pane(); for (int i = 0;i8; i+) boolean isWhite = i % 2 = 0; for (int j = 0; j8; j+) Rectangle rectangle = new Rectangle(i * WIDTH / 8, j * HEIGHT / 8, WIDTH / 8, HEIGHT / 8); rectangle.s

30、etStroke(Color.BLACK); java语言程序设计基础篇第十版第十四章练习答案 18 / 93 if (isWhite) rectangle.setFillfColor. WHITE); else rectangle.setFillfColor.BLACK);19 / 93 java语言程序设计基础篇第十版第十四章练习答案 | isWhite = !isWhite; pane.getChildren().add(rectangle); | / / Create a scene and place it in the stage Scene scene = new Scene(p

31、ane, WIDTH, HEIGHT); primaryStage.setTitle(Exercisel4_06); / Set the stage title primaryStage.setScene(scene); / / Place the scene in the stage primaryStage.show(); / / Display the stage I * * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the c

32、ommand line. * / 20 / 93 public static void main(String args) launch(args);java语言程序设计基础篇第十版第十四章练习答案 21 / 93 07 import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx. stag

33、e. Stage; public class Exercise 14_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 GridPaneQ; for (int i = 0; i 10; i+) for (int j = 0; j 10; j+) TextField tf = n

34、ew TextField(int)(Math.random() + 0.5) java语言程序设计基础篇第十版第十四章练习答案 22 / 93 tf.setPrefColumnCount(l); tf.setAlignment(Pos.CENTER); pane.addftf, j, i); / / Create a scene and place it in the stage Scene scene = new Scene(pane, WIDTH, HEIGHT); primaryStage.setTitle(Exercisel4_07); / / Set the stage title

35、primaryStage. setScene(scene); / / Place the scene in the stage primaryStage.show(); / / Display the stage I * * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. java语言程序设计基础篇第十版第十四章练习答案 23 / 93 * / public static void main(String

36、 args) launch(args); 08 import j avafx. application .Application; import javafx.scene.Scene; import javafx.scene.image.ImageView; import javafx.scene.layout.GridPane; import javafx. stage. Stage; public class Exercise 14_08 extends Application Override / / Override the start method in the Applicatio

37、n class public void start(Stage primaryStage) GridPane pane = new GridPaneQ; for (int i = 0; i 6; i+) for (int j = 0; j 9; j+) pane.add(new ImageView(nimage/card/M + (i * 6 + j + 1) + H-png), j, i); | java语言程序设计基础篇第十版第十四章练习答案 24 / 93 / / Create a scene and place it in the stage Scene scene = new Sce

38、ne(pane, 600, 600); primaryStage.setTitle(MExercisel4_08H); / Set the stage title primaryStage.setScene(scene); / / Place the scene in the stage primaryStage.show(); / / Display the stage I * * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the

39、command line. */ public static void main(String args) launch(args); 09 import javafx.application.Application; java语言程序设计基础篇第十版第十四章练习答案 25 / 93 import javafx. scene.Scene; import javafx.scene.layout.GridPane; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.

40、Arc; import javafx. scene.shape.ArcType; import javafx.scene.shape.Circle; import javafx.stage. Stage; public class Exercise 14_09 extends Application Override / / Override the start method in the Application class public void start(Stage primaryStage) GridPane pane = new GridPaneQ; pane.addfnew Fan

41、Panef), 0, 0); pane.add(new FanPaneQ, 1, 0); pane.addfnew FanPaneQ, 0, 1); pane.addfnew FanPaneQ, 1, 1); / / Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); primaryStage.setTitle(Exercisel4_09); / Set the stage java语言程序设计基础篇第十版第十四章练习答案 26 / 93 title primaryStage.set

42、Scene(scene); / / Place the scene in the stage primaryStage.show(); / / Display the stage I * * 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); class FanPane extends Pane dou

43、ble radius = 50; public FanPaneQ Circle circle = new Circle(60, 60, radius); circle. setStroke(Color. BLACK); circle.setFill(Color. WHITE); get Children (). add (circle); java语言程序设计基础篇第十版第十四章练习答案 27 / 93 Arc arcl = new Arc(60, 60, 40, 40, 30, 35); arcl.setFill(Color.RED); / Set fill color arc 1. set

44、Type(ArcType. ROUND); Arc arc2 = new Arc(60, 60, 40, 40, 30 + 90, 35); arc2.setFill(Color.RED); / / Set fill color arc2.setType(ArcType.ROUND); Arc arc3 = new Arc(60, 60, 40, 40, 30 + 180, 35); arc3.setFill(Color.RED); / Set fill color arc3.setType(ArcType. ROUND); Arc arc4 = new Arc(60, 60, 40, 40,

45、 30 + 270, 35); arc4.setFill(Color.RED); / Set fill color arc4. setType(ArcType. ROUND); getChildrenQ .addAll(arc 1, arc2, arc3, arc4); 10 import javafx.application.Application; import javafx. scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Ar

46、c; java语言程序设计基础篇第十版第十四章练习答案 28 / 93 import javafx.scene.shape.Ellipse; import javafx. scene.shape.Line; import javafx. stage. Stage; public class Exercise 14_ 10 extends Application Override / / Override the start method in the Application class public void start(Stage primaryStage) Pane pane = new

47、Pane(); Ellipse ellipse = new Ellipsefl00, 40, 50, 20); ellipse.setFill(Color. WHITE); ellipse.setStroke(Color.BLACK); Arc arcl = new ArcflOO, 140, 50, 20, 0, 180); arcl .setFill(Color.WHITE); arcl. set StrokefColor. BLACK); arc 1.getStrokeDashArray().addAll(6.0, 21.0); Arc arc2 = new ArcflOO, 140,

48、50, 20, 180, 180); arc2. setFill(Color.WHITE); arc2.setStroke(Color.BLACK); pane.getChildren().addAll(ellipse, arcl, arc2, new Line(50, 40, 50, 140), new Line(150, 40, 150, 140); java语言程序设计基础篇第十版第十四章练习答案 29 / 93 / / Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); pr

49、imaryStage.setTitle(Exercisel4_10); / Set the stage title primaryStage.setScene(scene); / / Place the scene in the stage primary Stage. show(); / / Display the stage I * * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. * / publ

50、ic static void main(String args) launch(args); 11 import javafx.application.Application; import javafx. scene.Scene; import javafx.scene.layout.Pane; java语言程序设计基础篇第十版第十四章练习答案 30 / 93 import javafx.scene.paint.Color; import javafx.scene.shape.Arc; import javafx.scene.shape.Circle; import javafx.scene

51、.shape.Ellipse; import javafx.scene.shape.Line; import javafx. stage. Stage; public class Exercise 14_11 extends Application Override / / Override the start method in the Application class public void start(Stage primaryStage) Pane pane = new Pane(); Circle circle = new Circlet 100, 100, 80); circle

52、.setFill(Color. WHITE); circle. setStroke(Color. BLACK); Circle circle 1 = new Circle(70, 70, 10); Circle circle2 = new Circlefl30, 70, 10); Ellipse ellipse 1 = new Ellipse(70, 70, 20, 15); ellipsel .setFill(Color.WHITE); ellipsel.setStroke(Color.BLACK); java语言程序设计基础篇第十版第十四章练习答案 31 / 93 Ellipse elli

53、pse2 = new Ellipse(130, 70, 20, 15); ellipse2.setFill(Color. WHITE); ellipse2.setStroke(Color.BLACK); Line linel = new Line(100, 80, 80, 120); Line line2 = new Line(80, 120, 120, 120); Line line3 = new Line(120, 120, 100, 80); Arc arc = new ArcflOO, 130, 40, 15, 180, 180); arc.setFillfColor. WHITE);

54、 arc. setStroke(Color. BLACK); pane.getChildren().addAll(circle, ellipse 1, ellipse2, circle 1, circle2, linel, line2, line3, arc); / / Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); primaryStage.setTitle(HExercise 14_ 11M); / / Set the stage title primaryStage.set

55、Scene(scene); / / Place the scene in the stage primaryStage.show() ; / / Display the stage java语言程序设计基础篇第十版第十四章练习答案 32 / 93 I * * 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);

56、 12 import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.scene.text.Text; import javafx.stage. Stage; public class Exercise 14_ 12 extends Application Override / / Overri

57、de the start method in the Application class public void start(Stage primaryStage) java语言程序设计基础篇第十版第十四章练习答案 33 / 93 Pane pane = new Pane(); double height = 300; double paneHeight = 150; Rectangle rl = new Rectangle1 10, paneHeight - height * 0.2, 100, height * 0.2); r 1 .setFill(Color.RED); Text tex

58、tl = new Text(10, paneHeight - height * 0.2 - 10, ,Project 一 20%); Rectangle r2 = new Rectangle(10 + 110, paneHeight - height * 0.1, 100, height * 0.1); r2.setFill(Color.BLUE); Text text2 = new Text(10 + 110, paneHeight - height *0.1 -10, Quiz - 10%”); Rectangle r3 = new Rectangle(10 + 220, paneHeig

59、ht - height * 0.3, 100, height * 0.3); r3. setFill(Color. GREEN); Text text3 = new Text(10 + 220, paneHeight - height * 0.3 -10, Midterm - 30%”); Rectangle r4 = new Rectangle(10 + 330, paneHeight - height * 0.4, 100, height * 0.4); java语言程序设计基础篇第十版第十四章练习答案 34 / 93 r4.setFill(Color.ORANGE); Text text

60、4 = new Text(10 + 330, paneHeight - height * 0.4 -10, Final - 40%); pane.getChildren().addAll(rl, textl, r2, text2, r3, text3, r4, text4); / / Create a scene and place it in the stage Scene scene = new Scene(pane, 500, pan eHeight); primaryStage.setTitle(Exercisel4_ 12); / / Set the stage title prim

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论