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

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

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

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

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

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

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

第十五章练习题答案

15.1

importjavafx.application.Application;

importjavafx.geometry.Pos;

importjavafx.scene.Scene;

importjavafx.scene.control.Button;

importjavafx.scene.image.ImageView;

importjavafx.scene.layout.BorderPane;

importjavafx.scene.layout.HBox;

importjavafx.stage.Stage;

importjava.util.ArrayList;

publicclassExercise15_01extendsApplication{

@Override

//OverridethestartmethodintheApplicationclass

publicvoidstart(StageprimaryStage){

//Therearetwowaysforshuffling.Oneistousethehintinthebook.

//Theotherwayistousethestaticshufflemethodinthejava.util.Collectionsclass.

ArrayListlist=newArrayList<>();

for(inti=1;i<=52;i++){

list.add(i);

}

java.util.Collections.shuffle(list);

HBpxhBox=newHBox(5);

hBox.setAlignment(Pos.CENTER);

hBox.getChildren().add(

new

ImageView(

"image/card/"

+list.get(0)+

".png"));

hBox.getChildren().add(

new

ImageView(

"image/card/"

+list.get

(1)+

".png"));

hBox.getChildren().add(

new

ImageView(

"image/card/"

+list.get

(2)+

".png"));

hBox.getChildren().add(

new

ImageView(

"image/card/"

+list.get(3)+

".png"));

//Createabutton

ButtonbtRefresh=newButton("Refresh");

btRefresh.setOnAction(e->{

java.util.Collections.shuffle(list);

 

hBox.getChildren().clear();

hBox.getChildren().add(

newImageView(

"image/card/"

+list.get(0)+

".png"));

hBox.getChildren().add(

newImageView(

"image/card/"

+list.get

(1)+

".png"));

hBox.getChildren().add(

newImageView(

"image/card/"

+list.get

(2)+

".png"));

hBox.getChildren().add(

newImageView(

"image/card/"

+list.get(3)+

.png"));

});

newBorderPane();

BorderPanepane=pane.setCenter(hBox);

pane.setBottom(btRefresh);

BorderPane.setAlignment(btRefresh,Pos.TOP_CENTER);

//Createasceneandplaceitinthestage

Scenescene=newScene(pane,250,150);

primaryStage.setTitle("Exercise15_01");//Setthestagetitle

primaryStage.setScene(scene);//Placethesceneinthestage

primaryStage.show();//Displaythestage

}

/**

*ThemainmethodisonlyneededfortheIDEwithlimited

*JavaFXsupport.Notneededforrunningfromthecommandline.

*/

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

}

}

15.1附加

importimportimportimportimportimportimportimportimport

javafx.application.Application;

javafx.geometry.Pos;

javafx.scene.Scene;

javafx.scene.control.Button;

javafx.scene.layout.BorderPane;javafx.scene.layout.GridPane;javafx.scene.text.Font;

javafx.scene.text.Text;

javafx.stage.Stage;

publicclassExercise15_01ExtraextendsApplication{

privateText[][]texts=newText[10][10];

@Override//OverridethestartmethodintheApplicationclasspublicvoidstart(StageprimaryStage){

//CreateUI

GridPanepane=newGridPane();

pane.setAlignment(Pos.CENTER);

pane.setHgap(10);

pane.setVgap(10);

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

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

pane.add(texts[i][j]=newText((int)(Math.random()*2)+""),j,i);

}

}

ButtonbtRefresh=newButton("Refresh");

BorderPaneborderPane=newBorderPane();

borderPane.setCenter(pane);

borderPane.setBottom(btRefresh);

BorderPane.setAlignment(btRefresh,Pos.CENTER);

btRefresh.setOnAction(e->{

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

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

texts[i][j].setText((int)(Math.random()*2)+"");

}

}

});

//Createasceneandplaceitinthestage

Scenescene=newScene(borderPane,200,350);

primaryStage.setTitle("Exercise15_01");//Settitle

primaryStage.setScene(scene);//Placethesceneinthestage

primaryStage.show();//Displaythestage

}

classCellextendsText{

Cell(){

setFont(Font.font("TimesRoman",35));super.setText("H");

this.setOnMouseClicked(e->{

if(getText().equals("H")){setText("T");

}else{setText("H");

}});

}

}

/**

*ThemainmethodisonlyneededfortheIDEwithlimited

*JavaFXsupport.Notneededforrunningfromthecommandline.

*/

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

}

}

15.2

importjavafx.application.Application;

importjavafx.geometry.Pos;

importjavafx.scene.Scene;

importjavafx.scene.control.Button;

importjavafx.scene.layout.BorderPane;

importjavafx.scene.layout.StackPane;

importjavafx.scene.paint.Color;

importjavafx.scene.shape.Rectangle;

importjavafx.stage.Stage;

publicclassExercise15_02extendsApplication{privatedoubleangle=0;

@Override

//OverridethestartmethodintheApplicationclasspublicvoidstart(StageprimaryStage){StackPanestackPane=newStackPane();

Rectanglerectangle=newRectangle(30,30,30,60);

rectangle.setFill(Color.WHITE);

rectangle.setStroke(Color.BLACK);

stackPane.getChildren().add(rectangle);

//Createabutton

ButtonbtRotate=newButton("Rotate");

btRotate.setOnAction(e->{

angle+=15;

rectangle.setRotate(angle);

});

BorderPanepane=newBorderPane();

pane.setCenter(stackPane);

pane.setBottom(btRotate);

BorderPane.setAlignment(btRotate,Pos.TOP_CENTER);

//Createasceneandplaceitinthestage

Scenescene=newScene(pane,200,150);

primaryStage.setTitle("Exercise15_02");//Setthestagetitle

primaryStage.setScene(scene);//Placethesceneinthestage

primaryStage.show();//Displaythestage

}

/**

*ThemainmethodisonlyneededfortheIDEwithlimited

*JavaFXsupport.Notneededforrunningfromthecommandline.

*/

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

}

}

15.2附加

import

javafx.application.Application;

import

javafx.geometry.Pos;

import

javafx.scene.Scene;

import

javafx.scene.control.Button;

import

javafx.scene.layout.BorderPane;

import

javafx.scene.layout.Pane;

import

javafx.scene.shape.Line;

import

javafx.stage.Stage;

public

classExercise15_02Extra

extendsApplication{

private

static

Panepane=newPane();

private

static

doublepaneWidth=400;

private

static

doublepaneHeight=250;

@Override//OverridethestartmethodintheApplicationclasspublicvoidstart(StageprimaryStage){

drawARandomArrowLine();

ButtonbtDrawArrowLine=newButton("Drawarandomarrowline");

BorderPaneborderPane=newBorderPane();

borderPane.setCenter(pane);

borderPane.setBottom(btDrawArrowLine);

BorderPane.setAlignment(btDrawArrowLine,Pos.CENTER);

btDrawArrowLine.setOnAction(e->drawARandomArrowLine());

//Createasceneandplaceitinthestage

Scenescene=newScene(borderPane,400,250);

primaryStage.setTitle("Exercise15_02");//Setthestagetitle

primaryStage.setScene(scene);//Placethesceneinthestage

primaryStage.show();//Displaythestage

}

privatestaticvoiddrawARandomArrowLine(){pane.getChildren().clear();

doublex1=Math.random()*(paneWidth-12);

doubley1=Math.random()*(paneHeight-12);

doublex2=Math.random()*(paneWidth-12);

doubley2=Math.random()*(paneHeight-12);

drawArrowLine(x1,y1,x2,y2,pane);

}

publicstaticvoiddrawArrowLine(doublex1,doubley1,doublex2,doubley2,Panepane){

pane.getChildren().add(newLine(x1,y1,x2,y2));

//findslopeofthislinedoubleslope=((((double)y1)-(double)y2))

/(((double)x1)-(((double)x2)));

doublearctan=Math.atan(slope);

//Thiswillflipthearrow45offofa

//perpendicularlineatptx2

doubleset45=1.57/2;

//arrowsshouldalwayspointtowardsi,noti+1

if(x1

//add90degreestoarrowlinesset45=-1.57*1.5;

}

//setlengthofarrowsintarrlen=15;

//drawarrowsonline

pane.getChildren().add(newLine(x2,y2,(x2+(Math.cos(arctan+set45)*

arrlen)),

((y2))+(Math.sin(arctan+set45)*arrlen)));

pane.getChildren().add(newLine(x2,y2,(x2+(Math.cos(arctan-set45)*

arrlen)),

((y2))+(Math.sin(arctan-set45)*arrlen)));

}

/**

*ThemainmethodisonlyneededfortheIDEwithlimited

*JavaFXsupport.Notneededforrunningfromthecommandline.

*/

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

}

}

15.3

importjavafx.application.Application;

importjavafx.geometry.Pos;

importjavafx.scene.Scene;

importjavafx.scene.control.Button;

importjavafx.scene.layout.BorderPane;

importjavafx.scene.layout.HBox;

importjavafx.scene.layout.Pane;

importjavafx.scene.paint.Color;

importjavafx.scene.shape.Circle;

importjavafx.stage.Stage;

publicclassExercise15_03extendsApplication{

@Override

//OverridethestartmethodintheApplicationclasspublicvoidstart(StageprimaryStage){

Panepane=newPane();

Circlecircle=newCircle(40,50,20);

circle.setFill(Color.WHITE);

circle.setStroke(Color.BLACK);

pane.getChildren().add(circle);

//Createfourbuttons

HBoxhBox=newHBox(5);

ButtonbtLeft=

ButtonbtRight=

ButtonbtUp=

ButtonbtDown=

newButton("Left");

newButton("Right");

newButton("Up");

newButton("Down");

hBox.setAlignment(Pos.CENTER);

hBox.getChildren().addAll(btLeft,btRight,btUp,btDown);

BorderPaneborderPane=newBorderPane();

borderPane.setCenter(pane);

borderPane.setBottom(hBox);

BorderPane.setAlignment(hBox,Pos.TOP_CENTER);

//Createasceneandplaceitinthestage

Scenescene=newScene(borderPane,200,150);

primaryStage.setTitle("Exercise15_03");//Setthestagetitle

primaryStage.setScene(scene);//Placethesceneinthestage

primaryStage.show();//Displaythestage

btLeft.setOnAction(e->{circle.setCenterX(circle.getCenterX()>0?

circle.getCenterX()-2:

0);

});

btRight.setOnAction(e->{

circle.setCenterX(circle.getCenterX()

circle.getCenterX()+2:

0);});

btUp.setOnAction(e->{circle.setCenterY(circle.getCenterY()>0?

circle.getCenterY()-2:

0);

});

btDown.setOnAction(e->{

circle.setCenterY(circle.getCe

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

当前位置:首页 > 自然科学 > 物理

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

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