关键词不能为空

当前您在: 主页 > 英语 >

《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版 梁勇 著)第三十六章练习题答案的相关文章

  • 爱心与尊严的高中作文题库

    1.关于爱心和尊严的作文八百字 我们不必怀疑富翁的捐助,毕竟普施爱心,善莫大焉,它是一 种美;我们也不必指责苛求受捐者的冷漠的拒绝,因为人总是有尊 严的,这也是一种美。

    小学作文
  • 爱心与尊严高中作文题库

    1.关于爱心和尊严的作文八百字 我们不必怀疑富翁的捐助,毕竟普施爱心,善莫大焉,它是一 种美;我们也不必指责苛求受捐者的冷漠的拒绝,因为人总是有尊 严的,这也是一种美。

    小学作文
  • 爱心与尊重的作文题库

    1.作文关爱与尊重议论文 如果说没有爱就没有教育的话,那么离开了尊重同样也谈不上教育。 因为每一位孩子都渴望得到他人的尊重,尤其是教师的尊重。可是在现实生活中,不时会有

    小学作文
  • 爱心责任100字作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
  • 爱心责任心的作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
  • 爱心责任作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

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