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

下载本文档

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

文档简介

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, 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 and 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 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.Font;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(); 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.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 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); 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.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(); 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.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 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.scene.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 = 200; 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); else 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 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); 07import javafx.application.Application;import javafx.geometry.Pos;import javafx.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 TextField(int)(Math.random() + 0.5) + ); tf.setPrefColumnCount(1); tf.setAlignment(Pos.CENTER); pane.add(tf, j, i); / Create a scene and place it in the stage Scene scene = new Scene(pane, WIDTH, HEIGHT); primaryStage.setTitle(Exercise14_07); / 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); 08import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.image.ImageView;import javafx.scene.layout.GridPane;import javafx.stage.Stage;public class Exercise14_08 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) GridPane pane = new GridPane(); for (int i = 0; i 6; i+) for (int j = 0; j 9; j+) pane.add(new ImageView(image/card/ + (i * 6 + j + 1) + .png), j, i); / Create a scene and place it in the stage Scene scene = new Scene(pane, 600, 600); primaryStage.setTitle(Exercise14_08); / 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); 09import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.layout.GridPane;import javafx.scene.layout.Pane;import javafx.scene.paint.Color;import javafx.scene.shape.Arc;import javafx.scene.shape.ArcType;import javafx.scene.shape.Circle;import javafx.stage.Stage;public class Exercise14_09 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) GridPane pane = new GridPane(); pane.add(new FanPane(), 0, 0); pane.add(new FanPane(), 1, 0); pane.add(new FanPane(), 0, 1); pane.add(new FanPane(), 1, 1); / Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); primaryStage.setTitle(Exercise14_09); / 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); class FanPane extends Pane double radius = 50; public FanPane() Circle circle = new Circle(60, 60, radius); circle.setStroke(Color.BLACK); circle.setFill(Color.WHITE); getChildren().add(circle); Arc arc1 = new Arc(60, 60, 40, 40, 30, 35); arc1.setFill(Color.RED); / Set fill color arc1.setType(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, 30 + 270, 35); arc4.setFill(Color.RED); / Set fill color arc4.setType(ArcType.ROUND); getChildren().addAll(arc1, arc2, arc3, arc4); 10import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.layout.Pane;import javafx.scene.paint.Color;import javafx.scene.shape.Arc;import javafx.scene.shape.Ellipse;import javafx.scene.shape.Line;import javafx.stage.Stage;public class Exercise14_10 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) Pane pane = new Pane(); Ellipse ellipse = new Ellipse(100, 40, 50, 20); ellipse.setFill(Color.WHITE); ellipse.setStroke(Color.BLACK); Arc arc1 = new Arc(100, 140, 50, 20, 0, 180); arc1.setFill(Color.WHITE); arc1.setStroke(Color.BLACK); arc1.getStrokeDashArray().addAll(6.0, 21.0); Arc arc2 = new Arc(100, 140, 50, 20, 180, 180); arc2.setFill(Color.WHITE); arc2.setStroke(Color.BLACK); pane.getChildren().addAll(ellipse, arc1, arc2, new Line(50, 40, 50, 140), new Line(150, 40, 150, 140); / Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); primaryStage.setTitle(Exercise14_10); / 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); 11import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.layout.Pane;import javafx.scene.paint.Color;import javafx.scene.shape.Arc;import javafx.scene.shape.Circle;import javafx.scene.shape.Ellipse;import javafx.scene.shape.Line;import javafx.stage.Stage;public class Exercise14_11 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) Pane pane = new Pane(); Circle circle = new Circle(100, 100, 80); circle.setFill(Color.WHITE); circle.setStroke(Color.BLACK); Circle circle1 = new Circle(70, 70, 10); Circle circle2 = new Circle(130, 70, 10); Ellipse ellipse1 = new Ellipse(70, 70, 20, 15); ellipse1.setFill(Color.WHITE); ellipse1.setStroke(Color.BLACK); Ellipse ellipse2 = new Ellipse(130, 70, 20, 15); ellipse2.setFill(Color.WHITE); ellipse2.setStroke(Color.BLACK); Line line1 = 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 Arc(100, 130, 40, 15, 180, 180); arc.setFill(Color.WHITE); arc.setStroke(Color.BLACK); pane.getChildren().addAll(circle, ellipse1, ellipse2, circle1, circle2, line1, line2, line3, arc); / Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); primaryStage.setTitle(Exercise14_11); / 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); 12i

温馨提示

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

评论

0/150

提交评论