《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx

上传人:b****6 文档编号:13011353 上传时间:2023-06-10 格式:DOCX 页数:171 大小:406.08KB
下载 相关 举报
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第1页
第1页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第2页
第2页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第3页
第3页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第4页
第4页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第5页
第5页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第6页
第6页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第7页
第7页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第8页
第8页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第9页
第9页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第10页
第10页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第11页
第11页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第12页
第12页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第13页
第13页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第14页
第14页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第15页
第15页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第16页
第16页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第17页
第17页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第18页
第18页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第19页
第19页 / 共171页
《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx_第20页
第20页 / 共171页
亲,该文档总共171页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx

《《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx》由会员分享,可在线阅读,更多相关《《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx(171页珍藏版)》请在冰点文库上搜索。

《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案.docx

《Java语言程序设计基础篇》第10版梁勇著第十六章练习题答案

Java语言程序设计(基础篇)》(第10版梁勇著)

第十六章练习题答案

16.1

importjavafx.application.Application;

importjavafx.geometry.Pos;

importjavafx.scene.Scene;

importjavafx.scene.control.Button;

importjavafx.scene.control.RadioButton;

importjavafx.scene.control.ToggleGroup;

importjavafx.scene.layout.BorderPane;

importjavafx.scene.layout.HBox;

importjavafx.scene.layout.Pane;

importjavafx.scene.paint.Color;

importjavafx.scene.text.Font;

importjavafx.scene.text.Text;

importjavafx.stage.Stage;

extendsApplication{

publicclassExercise16_01

privatedoublepaneWidth=500;

privatedoublepaneHeight=150;

@Override//OverridethestartmethodintheApplicationclasspublicvoidstart(StageprimaryStage){

Texttext=newText(20,40,"Programmingisfun");

text.setFont(newFont("Times",20));

PanepaneForText=newPane();

paneForText.getChildren().add(text);

paneForText.setStyle("-fx-border-color:

gray");

newRadioButton("Red");

 

newRadioButton("Green");

ToggleGroupgroup=newToggleGroup();

rbRed.setToggleGroup(group);rbYellow.setToggleGroup(group);rbBlack.setToggleGroup(group);rbBlack.setSelected(true);rbOrange.setToggleGroup(group);

rbGreen.setToggleGroup(group);

HBoxhBox=newHBox(5);

hBox.getChildren().addAll(rbRed,rbYellow,rbBlack,rbOrange,rbGreen);hBox.setAlignment(Pos.CENTER);

ButtonbtLeft=newButton("<=");

ButtonbtRight=newButton("=>");

HBoxhBoxForButtons=newHBox(5);

hBoxForButtons.getChildren().addAll(btLeft,btRight);hBoxForButtons.setAlignment(Pos.CENTER);

BorderPaneborderPane=newBorderPane();

borderPane.setTop(hBox);

borderPane.setCenter(paneForText);borderPane.setBottom(hBoxForButtons);

//Createasceneandplaceitinthestage

Scenescene=newScene(borderPane,paneWidth,paneHeight+40);

primaryStage.setTitle("Exercise16_01");//SetthestagetitleprimaryStage.setScene(scene);//PlacethesceneinthestageprimaryStage.show();//Displaythestage

rbRed.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->text.setStroke(Color.GREEN));

btLeft.setOnAction(e->text.setX(text.getX()-1));btRight.setOnAction(e->text.setX(text.getX()+1));

}

/**

*ThemainmethodisonlyneededfortheIDEwithlimited

*JavaFXsupport.Notneededforrunningfromthecommandline.

*/

publicstaticvoidmain(String[]args){

launch(args);

}

}

16.1附加

importjavafx.application.Application;

importjavafx.scene.Scene;

importjavafx.scene.layout.*;

importjavafx.scene.paint.Color;

importjavafx.scene.control.*;

importjavafx.stage.Stage;

importjavafx.geometry.Pos;

publicclassExercise16_01ExtraextendsApplication{finalstaticdoublePANEL_WIDTH=400;

finalstaticdoublePANEL_HEIGHT=140;

@Override//OverridethestartmethodintheApplicationclass

publicvoidstart(StageprimaryStage){

GridPanepaneForOriginal=

GridPanepaneForInversed=

newGridPane();newGridPane();

TextField[][]tfOriginal=

TextField[][]tfInversed=

newTextField[3][3];

newTextField[3][3];

for(inti=0;i<3;i++){for(intj=0;j<3;j++){paneForOriginal.add(tfOriginal[i][j]=tfOriginal[i][j].setPrefColumnCount(4);paneForInversed.add(tfInversed[i][j]=tfInversed[i][j].setPrefColumnCount(4);

}

}

newTextField(),j,i);

newTextField(),j,i);

BorderPanep1=newBorderPane();

p1.setCenter(paneForOriginal);p1.setTop(newLabel("OriginalMatrix"));

BorderPanep2=newBorderPane();p2.setCenter(paneForInversed);

finalLabellblStatus=newLabel("InversedMatrix");p2.setTop(lblStatus);

HBoxhBox=newHBox(5);hBox.getChildren().addAll(p1,p2);

BorderPanepane=newBorderPane();pane.setCenter(hBox);

ButtonbtGetInverse=

newButton("GetInverse"

);

 

pane.setBottom(btGetInverse);

BorderPane.setAlignment(btGetInverse,Pos.CENTER);

Scenescene=newScene(pane,PANEL_WIDTH,PANEL_HEIGHT);

primaryStage.setTitle("Exercise16_01");//SetthestagetitleprimaryStage.setScene(scene);//PlacethesceneinthestageprimaryStage.show();//Displaythestage

btGetInverse.setOnAction(e->{

double[][]A=newdouble[3][3];

for(inti=0;i<3;i++)

for(intj=0;j<3;j++){

A[i][j]=Double.parseDouble(tfOriginal[i][j].getText());

}

double[][]inverseA=Exercise08_03Extra.inverse(A);

if(inverseA==null)

lblStatus.setText("Inveredmatrix:

Noinversematrix");

else{

for(inti=0;i<3;i++)

for(intj=0;j<3;j++){tfInversed[i][j].setText(inverseA[i][j]+"");

}

});

/**

*ThemainmethodisonlyneededfortheIDEwithlimited

*JavaFXsupport.Notneededforrunningfromthecommandline.*/

publicstaticvoidmain(String[]args){launch(args);

}

}

16.2

importjavafx.application.Application;

importjavafx.geometry.Pos;

importjavafx.scene.Scene;

importjavafx.scene.control.CheckBox;

importjavafx.scene.control.RadioButton;importjavafx.scene.control.ToggleGroup;

importjavafx.scene.layout.BorderPane;

importjavafx.scene.layout.HBox;

importjavafx.scene.layout.StackPane;

importjavafx.scene.paint.Color;

importjavafx.scene.shape.Circle;

importjavafx.scene.shape.Ellipse;

importjavafx.scene.shape.Rectangle;

importjavafx.stage.Stage;

publicclassExercise16_02extendsApplication{privatedoublepaneWidth=500;privatedoublepaneHeight=150;

@Override//OverridethestartmethodintheApplicationclasspublicvoidstart(StageprimaryStage){

StackPanepane=newStackPane();

Circlecircle=newCircle(20,20,50);

circle.setStroke(Color.BLACK);

circle.setFill(Color.WHITE);

Rectanglerectangle=newRectangle(20,20,80,50);

rectangle.setStroke(Color.BLACK);

Ellipseellipse=newEllipse(20,20,50,70);

ellipse.setStroke(Color.BLACK);

pane.setStyle("-fx-border-color:

gray");pane.getChildren().add(circle);

newRadioButton("Circle");

newRadioButton("Rectangle"newRadioButton("Ellipse");newCheckBox("Fill");

ToggleGroupgroup=newToggleGroup();

rbCircle.setToggleGroup(group);rbCircle.setSelected(true);rbRectangle.setToggleGroup(group);rbEllipse.setToggleGroup(group);

HBoxhBox=newHBox(5);hBox.getChildren().addAll(rbCircle,rbRectangle,rbEllipse,chkFill);hBox.setAlignment(Pos.CENTER);

newBorderPane();

BorderPaneborderPane=borderPane.setCenter(pane);borderPane.setBottom(hBox);

//Createasceneandplaceitinthestage

Scenescene=newScene(borderPane,paneWidth,paneHeight+40);

primaryStage.setTitle("Exercise16_02");//SetthestagetitleprimaryStage.setScene(scene);//PlacethesceneinthestageprimaryStage.show();//Displaythestage

rbCircle.setOnAction(e->{

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.isSelected()){

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()){

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);

}

});

}

/**

*ThemainmethodisonlyneededfortheIDEwithlimited

*JavaFXsupport.Notneededforrunningfromthecommandline.*/

publicstaticvoidmain(String[]args){launch(args);

}

}

16.2附加

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

classExercise16_02Extra

extendsApplication{

final

staticdoublePANEL_

WIDTH=400;

final

staticdoublePANEL_

HEIGHT=140;

@Override//OverridethestartmethodintheApplicationclass

publicvoidstart(StageprimaryStage){

GridPanepaneForOriginal=

GridPanepaneForInversed=

newGridPane();newGridPane();

TextField[][]tfA=newTextField[3][3];

TextField[]tfB=newTextField[3];

for(inti=0;i<3;i++){

for(intj=0;j<3;j++){

tfA[i][j]=newTextField();

tfA[i][j].setPrefColumnCount(4);

}

tfB[i]=newTextField();tfB[i].setPrefColumnCount(4);

}

HBox[]hBoxes=newHBox[3];

for(inti=0;i<3;i++){

hBoxes[i]=newHBox(5);

hBoxes[i].getChildren().addAll(tfA[i][0],newLabel("x"),tfA[i][1],newLabel("y"),tfA[i][2],newLabel("z="),tfB[i]);

}

VBoxvBox=newVBox(5);

vBox.getChildren().addAll(hBoxes[0],hBoxes[1],hBoxes[2]);

HBoxhBox=newHBox(5);

LabellblStatus=newLabel();

ButtonbtSolveEquation=newButton("SolveEquation");

hBox.getChildren().addAll(btSolveEquation,lblStatus);

BorderPanepane=newBorderPane();

pane.setCenter(vBox);pane.setBottom(hBox);

Scenescene=newScene(pane,PANEL_WIDTH,PANEL_HEIGHT);

primaryStage.setTitle("Exercise16_02");//SetthestagetitleprimaryStage.setScene(scene);//PlacethesceneinthestageprimaryStage.show();//Displaythestage

btSolveEquation.setOnAction(e->{

double[][]A=newdouble[3][3];

double[]B=newdouble[3];

for(inti=0;i<3;i++){

for(intj=0;j<3;j++){

A[i][j]=Double.parseDouble(tfA[i][j].getText());

}

B[i]=Double.parseDouble(tfB[i].getText());

}

double[]result=Exercise08_02Extra.getSolution(A,B);

if(result==

null)

lblStatus.setText(

"Nosolutions");

else

lblStatus.set

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2