关键词不能为空

当前您在: 主页 > 英语 >

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

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-13 19:37
tags:

-

2021年2月13日发(作者:关注英文)



Java


语言程序设计(基础篇)

< p>


(第


10


< p>


梁勇



著)



第三十六章



练习题答案




36.1



import


ation;


import



import



import



import


ea;


import


eld;


import


Pane;


import



import




public



class


Exercise36_01


extends


Application {



private


CalendarPane calendarPane =


new


CalendarPane();



private


TextField tfUnicode =


new


TextField();



private


TextArea taUnicodeCharacters =


new


TextArea();




@


Override


// Override the start method in the Application class




public



void


start(Stage primaryStage) {


HBox hBox =


new


HBox(5);


ldren().addAll(



new


Label(



), tfUnicode);


gnment();


fColumnCount(4);



BorderPane pane =


new


BorderPane();


ter(taUnicodeCharacters);


(hBox);




// Create a scene and place it in the stage



Scene scene =


new


Scene(pane, 400, 300);


le(



);


// Set the stage title



ne(scene);


// Place the scene in the stage



();


// Display the stage




ction(e -> {



int


code = nt(t().toString(), 16);


n(code);


displayUnicode(code);


});


}




private



void


displayUnicode(


int


code) {


t(


null


);



for


(


int


i = 0; i < 20; i++) {


Text(


tring(code) +



);



for


(


int


j = 0; j < 16; j++) {


Text((


char


)code +



);


code++;


}


Text(



);


}


}




/**



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


}


}




36.2



import


rmat;


import



import



import



import


ne;


import


ation;


import



import



import


ox;


import



import


eld;


import



import



import




public



class


Exercise36_02


extends


Application {



private


Locale[] availableLocales = ilableLocales();



private


String[] availableTimeZones = ilableIDs();



private


DateFormat dateFormat = eInstance();



private


DateFormat timeFormat = eInstance();



private


Date date =


new


Date();



private


TextField tfDate =


new


TextField((date));



private


TextField tfTime =


new


TextField((date));



private


ComboBox cboLocale =


new


ComboBox<>();



private


ComboBox cboTimeZone =


new


ComboBox<>();



private


ComboBox cboDateStyle =


new


ComboBox<>();



private


ComboBox cboTimeStyle =


new


ComboBox<>();




private


Locale locale =



private


String timeZone = ault().getID();




private



int


dateStyle =



private



int


timeStyle =




@


Override


// Override the start method in the Application class




public



void


start(Stage primaryStage) {



// Initialize cboLocales with all available locales



setAvailableLocales();




// Initialize cboTimeZones with all available time zones



setAvailableTimeZones();



ms().addAll(




,



,



,



);


ms().addAll(




,



,



,



);



HBox hBox1 =


new


HBox(5);


ldren().addAll(



new


Label(



), tfDate,


new


Label(



), tfTime);



HBox hBox2 =


new


HBox(5);


ldren().addAll(



new


Label(



), cboLocale,



new


Label(



), cboTimeZone);



HBox hBox3 =


new


HBox(5);


ldren().addAll(



new


Label(



), cboDateStyle,



new


Label(



), cboTimeStyle);


gnment();



VBox vBox =


new


VBox(5);


ldren().addAll(hBox1, hBox2, hBox3);




// Create a scene and place it in the stage



Scene scene =


new


Scene(vBox, 400, 200);


le(



);


// Set the stage title



ne(scene);


// Place the scene in the stage



();


// Display the stage




ction(e -> {


locale =


availableLocales[ectionModel() .getSelectedIndex()];


process();


});



ction(e -> {


timeZone =

availableTimeZones[ectionModel().getSelectedInde x()];


process();


});



ction(e -> {


dateStyle = ectionModel().getSelectedIndex();


process();


});



ction(e -> {


timeStyle = ectionModel().getSelectedIndex();


process();


});


}




private



void


process() {


dateFormat = eInstance(dateStyle, locale);


timeFormat = eInstance(timeStyle, locale);


eZone(eZone(timeZone));


eZone(eZone(timeZone));



t((


new


Date()));


t((


new


Date()));


}




private



void


setAvailableLocales() {



for


(


int


i = 0; i < i++)


ms().add(availableLocales[i]


.getDisplayName() +



+ availableLocales[i].toString());



ectionModel().selectFirst();


}




private



void


setAvailableTimeZones() {



// Sort time zones



(availableTimeZones);



for


(


int


i = 0; i < i++) {


ms().add(availableTimeZones[i]);


}


ectionModel().selectFirst();


}




/**



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


}


}




36.3



import


rmat;


import


rmatSymbols;


import


DateFormat;


import


ar;


import


ianCalendar;


import



import


ne;


import


me;


import


ne;


import


ation;


import


Event;


import


andler;


import



import



import



import


Pane;


import


ne;


import



import



import


ignment;


import



import


on;



public



class


Exercise36_03


extends


Application {



@


Override


// Override the start method in the Application class




public



void


start(Stage primaryStage) {


HBox hBox =


new


HBox(5);


ldren().addAll(



new


CalendarPane(),


new


WorldClock());




// Create a scene and place it in the stage



Scene scene =


new


Scene(hBox, 500, 200);


le(



);


// Set the stage title



ne(scene);


// Place the scene in the stage



();


// 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


WorldClock


extends


BorderPane {




private


TimeZone timeZone = eZone(



);



private


Locale locale = ault();



private


ClockPane clock =


new


ClockPane();


// Still clock




private


Label lblDigitTime =


new


Label();




public


WorldClock() {


setCenter(clock);


setBottom(lblDigitTime);


gnment(lblDigitTime, );



EventHandler eventHandler = e -> {


setCurrentTime();


// Set a new clock time



};




// Create an animation for a running clock



Timeline animation =


new


Timeline(



new


KeyFrame((1000), eventHandler));


leCount(NITE);


();


// Start animation





// Resize the clock



widthProperty().addListener(ov -> (getWidth()));


heightProperty().addListener(ov -> (getHeight()));


}




public



void


setTimeZone(TimeZone timeZone) {



this


.timeZone = timeZone;


}




public



void


setLocale(Locale locale) {



this


.locale = locale;


}




private



void


setCurrentTime() {


Calendar calendar =


new


GregorianCalendar(timeZone, locale);


r(());


ute(());


ond(());




// Display digit time on the label



DateFormat


formatter


=


eTimeInstance(,


, locale);


eZone(timeZone);


t((e()));


}


}




class


CalendarPane


extends


BorderPane {



// The header label





private


Label lblHeader =


new


Label();




// Maximum number of labels to display day names and days




private


Label[] lblDay =


new


Label[49];




private


Calendar calendar;



private



int


month;


// The specified month




private



int


year;


// The specified year




private


Locale locale =




public


CalendarPane() {



// Create labels for displaying days




for


(


int


i = 0; i < 49; i++) {


lblDay[i] =


new


Label();


lblDay[i].setTextAlignment();


}



showDayNames();


// Display day names for the locale




GridPane dayPane =


new


GridPane();


gnment();



p(10);


p(10);



for


(


int


i = 0; i < 49; i++) {


(lblDay[i], i % 7, i / 7);


}




// Place header and calendar body in the pane




this


.setTop(lblHeader);


gnment(lblHeader, );



this


.setCenter(dayPane);




// Set current month and year



calendar =


new


GregorianCalendar();


month = ();


year = ();


updateCalendar();




// Show calendar



showHeader();


showDays();


}




/**



* Update the day names based on locale



*/




private



void


showDayNames() {


DateFormatSymbols dfs =


new


DateFormatSymbols(locale);


String dayNames[] = kdays();




// jlblDay[0], jlblDay[1], ..., jlblDay[6] for day names




for


(


int


i = 0; i < 7; i++) {


lblDay[i].setText(dayNames[i + 1]);


}


}




/**



* Update the header based on locale



*/




private



void


showHeader() {


SimpleDateFormat sdf =



new


SimpleDateFormat(



, locale);


String header = (e());


t(header);


}




public



void


showDays() {



// Get the day of the first day in a month




int


startingDayOfMonth = (_OF_WEEK);




// Fill the calendar with the days before this month



Calendar cloneCalendar = (Calendar) ();


(, -1);


// Becomes preceding month




int


daysInPrecedingMonth = ualMaximum(


_OF_MONTH);




for


(


int


i = 0; i < startingDayOfMonth - 1; i++) {


lblDay[i + 7].setTextFill(RAY);


lblDay[i + 7].setText(daysInPrecedingMonth


- startingDayOfMonth + 2 + i +



);


}




// Display days of this month




int


daysInCurrentMonth = ualMaximum(


_OF_MONTH);



for


(


int


i = 1; i <= daysInCurrentMonth; i++) {


lblDay[i - 2 + startingDayOfMonth + 7].setTextFill();


lblDay[i - 2 + startingDayOfMonth + 7].setText(i +



);


}




// Fill the calendar with the days after this month




int


j = 1;



for


(


int


i = daysInCurrentMonth - 1 + startingDayOfMonth + 7;


i < 49; i++) {


lblDay[i].setTextFill(RAY);


lblDay[i].setText(j++ +



);


}


}




/**



* Set the calendar to the first day of the specified month and year



*/




public



void


updateCalendar() {


(, year);


(, month);


(, 1);


}




public



int


getMonth() {



return


month;


}




public



void


setMonth(


int


newMonth) {


month = newMonth;


updateCalendar();


showHeader();


showDays();


}




public



int


getYear() {



return


year;


}




public



void


setYear(


int


newYear) {


year = newYear;


updateCalendar();


showHeader();


showDays();


}




public



void


setLocale(Locale locale) {



this


.locale = locale;


updateCalendar();


showDayNames();


showHeader();


showDays();


}


}


}

-


-


-


-


-


-


-


-



本文更新与2021-02-13 19:37,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/652317.html

《Java语言程序设计(基础篇)》(第10版 梁勇 著)第三十六章练习题答案的相关文章

  • 余华爱情经典语录,余华爱情句子

    余华的经典语录——余华《第七天》40、我不怕死,一点都不怕,只怕再也不能看见你——余华《第七天》4可是我再也没遇到一个像福贵这样令我难忘的人了,对自己的经历如此清楚,

    语文
  • 心情低落的图片压抑,心情低落的图片发朋友圈

    心情压抑的图片(心太累没人理解的说说带图片)1、有时候很想找个人倾诉一下,却又不知从何说起,最终是什么也不说,只想快点睡过去,告诉自己,明天就好了。有时候,突然会觉得

    语文
  • 经典古训100句图片大全,古训名言警句

    古代经典励志名言100句译:好的药物味苦但对治病有利;忠言劝诫的话听起来不顺耳却对人的行为有利。3良言一句三冬暖,恶语伤人六月寒。喷泉的高度不会超过它的源头;一个人的事

    语文
  • 关于青春奋斗的名人名言鲁迅,关于青年奋斗的名言鲁迅

    鲁迅名言名句大全励志1、世上本没有路,走的人多了自然便成了路。下面是我整理的鲁迅先生的名言名句大全,希望对你有所帮助!当生存时,还是将遭践踏,将遭删刈,直至于死亡而

    语文
  • 三国群英单机版手游礼包码,三国群英手机单机版攻略

    三国群英传7五神兽洞有什么用那是多一个武将技能。青龙飞升召唤出东方的守护兽,神兽之一的青龙。玄武怒流召唤出北方的守护兽,神兽之一的玄武。白虎傲啸召唤出西方的守护兽,

    语文
  • 不收费的情感挽回专家电话,情感挽回免费咨询

    免费的情感挽回机构(揭秘情感挽回机构骗局)1、牛牛(化名)向上海市公安局金山分局报案,称自己为了挽回与女友的感情,被一家名为“实花教育咨询”的情感咨询机构诈骗4万余元。

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