java语言程序设计基础篇第十版第十四章练习答案

上传人:1395****376 文档编号:49677414 上传时间:2022-01-18 格式:DOC 页数:33 大小:168.50KB
返回 下载 相关 举报
java语言程序设计基础篇第十版第十四章练习答案_第1页
第1页 / 共33页
java语言程序设计基础篇第十版第十四章练习答案_第2页
第2页 / 共33页
java语言程序设计基础篇第十版第十四章练习答案_第3页
第3页 / 共33页
点击查看更多>>
资源描述
精品文档,仅供学习与交流,如有侵权请联系网站删除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);12import 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 Exercise14_12 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) Pane pane = new Pane(); double height = 300; double paneHeight = 150; Rectangle r1 = new Rectangle(10, paneHeight - height * 0.2, 100, height * 0.2); r1.setFill(Color.RED); Text text1 = 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, paneHeight - 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); r4.setFill(Color.ORANGE); Text text4 = new Text(10 + 330, paneHeight - height * 0.4 - 10, Final - 40%); pane.getChildren().addAll(r1, text1, r2, text2, r3, text3, r4, text4); / Create a scene and place it in the stage Scene scene = new Scene(pane, 500, paneHeight); primaryStage.setTitle(Exercise14_12); / 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);13import 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.ArcType;import javafx.scene.text.Text;import javafx.stage.Stage;public class Exercise14_13 extends Application Override / Override the start method in the Application class public void start(Stage primaryStage) Pane pane = new Pane(); Arc arc1 = new Arc(100, 100, 80, 80, 0, 360 * 0.2); arc1.setFill(Color.RED); arc1.setType(ArcType.ROUND); Text text1 = new Text(110, 80, Project - 20%); Arc arc2 = new Arc(100, 100, 80, 80, 360 * 0.2, 360 * 0.1); arc2.setFill(Color.BLUE); arc2.setType(ArcType.ROUND); Text text2 = new Text(80, 15, Quiz - 10%); Arc arc3 = new Arc(100, 100, 80, 80, 360 * 0.2 + 360 * 0.1, 36
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 中学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!