1、Java语言程序设计基础篇第10版梁勇著第十六章练习题答案Java 语言程序设计(基础篇) (第 10 版 梁勇 著)第十六章 练习题答案16.1import javafx.application.Application;import javafx.geometry.Pos;import javafx.scene.Scene;import javafx.scene.control.Button;import javafx.scene.control.RadioButton;import javafx.scene.control.ToggleGroup;import javafx.scene.l
2、ayout.BorderPane;import javafx.scene.layout.HBox;import javafx.scene.layout.Pane;import javafx.scene.paint.Color;import javafx.scene.text.Font;import javafx.scene.text.Text;import javafx.stage.Stage;extends Application public class Exercise16_01private double paneWidth = 500;private double paneHeigh
3、t = 150;Override / Override the start method in the Application class public void start(Stage primaryStage) Text text = new Text(20, 40, Programming is fun );text.setFont( new Font( Times , 20);Pane paneForText = new Pane();paneForText.getChildren().add(text);paneForText.setStyle( -fx-border-color:
4、gray );new RadioButton( Red );new RadioButton( Green );ToggleGroup group = new ToggleGroup();rbRed.setToggleGroup(group); rbYellow.setToggleGroup(group); rbBlack.setToggleGroup(group); rbBlack.setSelected( true ); rbOrange.setToggleGroup(group);rbGreen.setToggleGroup(group);HBox hBox = new HBox(5);h
5、Box.getChildren().addAll(rbRed, rbYellow, rbBlack, rbOrange, rbGreen); hBox.setAlignment(Pos.CENTER);Button btLeft = new Button( );HBox hBoxForButtons = new HBox(5);hBoxForButtons.getChildren().addAll(btLeft, btRight); hBoxForButtons.setAlignment(Pos.CENTER);BorderPane borderPane = new BorderPane();
6、borderPane.setTop(hBox);borderPane.setCenter(paneForText); borderPane.setBottom(hBoxForButtons);/ Create a scene and place it in the stageScene scene = new Scene(borderPane, paneWidth, paneHeight + 40);primaryStage.setTitle( Exercise16_01 ); / Set the stage title primaryStage.setScene(scene); / Plac
7、e the scene in the stage primaryStage.show(); / Display the stagerbRed.setOnAction(e - text.setStroke(Color.RED); rbYellow.setOnAction(e - text.setStroke(Color.YELLOW);rbBlack.setOnAction(e - text.setStroke(Color.BLACK); rbOrange.setOnAction(e - text.setStroke(Color.ORANGE);rbGreen.setOnAction(e - t
8、ext.setStroke(Color.GREEN);btLeft.setOnAction(e - text.setX(text.getX() - 1); btRight.setOnAction(e - text.setX(text.getX() + 1);/* 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
9、);16.1附加import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.layout.*;import javafx.scene.paint.Color;import javafx.scene.control.*;import javafx.stage.Stage;import javafx.geometry.Pos;public class Exercise16_01Extra extends Application final static double PANEL_WIDTH
10、= 400;final static double PANEL_HEIGHT = 140;Override / Override the start method in the Application classpublic void start(Stage primaryStage) GridPane paneForOriginal =GridPane paneForInversed =new GridPane(); new GridPane();TextField tfOriginal =TextField tfInversed =new TextField33;new TextField
11、33;for ( int i = 0; i 3; i+) for ( int j = 0; j double A = new double 33;for ( int i = 0; i 3; i+)for ( int j = 0; j 3; j+) Aij = Double.parseDouble(tfOriginalij.getText();double inverseA = Exercise08_03Extra.inverse(A);if (inverseA = null )lblStatus.setText( Invered matrix: No inverse matrix );else
12、 for ( int i = 0; i 3; i+)for ( int j = 0; j pane.getChildren().clear(); pane.getChildren().add(circle);if (chkFill.isSelected() circle.setFill(Color.BLACK);else circle.setFill(Color.WHITE););rbRectangle.setOnAction(e - pane.getChildren().clear(); pane.getChildren().add(rectangle);if (chkFill.isSele
13、cted() rectangle.setFill(Color.BLACK);else rectangle.setFill(Color.WHITE););rbEllipse.setOnAction(e - pane.getChildren().clear(); pane.getChildren().add(ellipse);if (chkFill.isSelected() ellipse.setFill(Color.BLACK);else ellipse.setFill(Color.WHITE););chkFill.setOnAction(e - if (chkFill.isSelected()
14、 circle.setFill(Color.BLACK);rectangle.setFill(Color.BLACK);ellipse.setFill(Color.BLACK); else circle.setFill(Color.WHITE); rectangle.setFill(Color.WHITE);ellipse.setFill(Color.WHITE););/* The main method is only needed for the IDE with limited* JavaFX support. Not needed for running from the comman
15、d line. */public static void main(String args) launch(args);16.2附加importjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.layout.*;importjavafx.scene.paint.Color;importjavafx.scene.control.*;importjavafx.stage.Stage;importjavafx.geometry.Pos;publicclass Exercise16_02Extraext
16、ends Application finalstatic double PANEL_WIDTH = 400;finalstatic double PANEL_HEIGHT = 140;Override / Override the start method in the Application classpublic void start(Stage primaryStage) GridPane paneForOriginal =GridPane paneForInversed =new GridPane(); new GridPane();TextField tfA = new TextFi
17、eld33;TextField tfB = new TextField3;for ( int i = 0; i 3; i+) for ( int j = 0; j 3; j+) tfAij = new TextField();tfAij.setPrefColumnCount(4);tfBi = new TextField(); tfBi.setPrefColumnCount(4);HBox hBoxes = new HBox3;for ( int i = 0; i double A = new double 33;double B = new double 3;for ( int i = 0; i 3; i+) for ( int j = 0; j 3; j+) Aij = Double.parseDouble(tfAij.getText();Bi = Double.parseDouble(tfBi.getText();double result = Exercise08_02Extra.getSolution(A, B);if (result =null )lblStatus.setText(No solutions );elselblStatus.set
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2