欢迎来到天天文库
浏览记录
ID:46880781
大小:1.29 MB
页数:81页
时间:2019-11-28
《Java 语言程序设计语言程序设计(基础篇 进阶篇)编程练习答案》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、Java语言程序设计&[编程练习题答案]Java语言程序设计(基础篇)(进阶篇)第13、14、15、24、25、26、28、29、30、31章部分习题答案,奇数题和部分双数题是我自己做的,在此和大家分享(^_^~Chapter13Exercise13.2/13.8/13.11importjavax.swing.*;importjava.awt.*;publicclassExercise13_2extendsJFrame{//CreatetwobuttonsprivateOvalButtonjbtOk
2、=newOvalButton("OK");privateOvalButtonjbtCancel=newOvalButton("Cancel");/**Defaultconstructor*/publicExercise13_2(){//SetthewindowtitlesetTitle("Exercise13_2");//SetFlowLayoutmanagertoarrangethecomponents1/81Java语言程序设计//insidetheframegetContentPane().s
3、etLayout(newFlowLayout());//AddbuttonstotheframegetContentPane().add(jbtOk);getContentPane().add(jbtCancel);}/**Mainmethod*/publicstaticvoidmain(String[]args){Exercise13_2frame=newExercise13_2();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);fram
4、e.pack();frame.setVisible(true);}}classOvalButtonextendsJButton{publicOvalButton(){}publicOvalButton(Stringtext){super(text);}protectedvoidpaintComponent(Graphicsg){//Drawanovalsuper.paintComponent(g);g.drawOval(5,5,getWidth()-10,getHeight()-10);}/**Ov
5、erridegetmethodforpreferredSize*/publicDimensiongetPreferredSize(){returnnewDimension(100,50);}/**OverridegetmethodforminimumSize*/publicDimensiongetMinimumSize(){returnnewDimension(100,50);}}2/81Java语言程序设计importjava.awt.*;importjavax.swing.*;publiccla
6、ssExercise13_8extendsJFrame{publicstaticvoidmain(String[]args){JFrameframe=newExercise13_8();frame.setSize(300,300);frame.setTitle("Exercise13_8");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}publicExercise13_8(){getCont
7、entPane().add(newOctagonPanel());}}classOctagonPanelextendsJPanel{protectedvoidpaintComponent(Graphicsg){super.paintComponent(g);intxCenter=getWidth()/2;intyCenter=getHeight()/2;intradius=(int)(Math.min(getWidth(),getHeight())*0.4);//CreateaPolygonobje
8、ctPolygonpolygon=newPolygon();//Addpointstothepolygonpolygon.addPoint(xCenter+radius,yCenter);polygon.addPoint((int)(xCenter+radius*Math.cos(2*Math.PI/8)),(int)(yCenter-radius*Math.sin(2*Math.PI/8)));polygon.addPoint((int)(xCenter+radiu
此文档下载收益归作者所有