欢迎来到天天文库
浏览记录
ID:12806768
大小:541.50 KB
页数:77页
时间:2018-07-19
《java语言程序设计基础篇课后答案-机械工业出版社》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Java语言程序设计1/81&[编程练习题答案]Java语言程序设计(基础篇)(进阶篇)第13、14、15、24、25、26、28、29、30、31章部分习题答案,奇数题和部分双数题是我自己做的,在此和大家分享(^_^~Chapter13Exercise13.2/13.8/13.11importjavax.swing.*;importjava.awt.*;publicclassExercise13_2extendsJFrame{//CreatetwobuttonsprivateOvalButtonjbtOk=newOvalButton("OK");priva
2、teOvalButtonjbtCancel=newOvalButton("Cancel");/**Defaultconstructor*/publicExercise13_2(){//SetthewindowtitlesetTitle("Exercise13_2");//SetFlowLayoutmanagertoarrangethecomponentsJava语言程序设计2/81//insidetheframegetContentPane().setLayout(newFlowLayout());//AddbuttonstotheframegetConte
3、ntPane().add(jbtOk);getContentPane().add(jbtCancel);}/**Mainmethod*/publicstaticvoidmain(String[]args){Exercise13_2frame=newExercise13_2();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.pack();frame.setVisible(true);}}classOvalButtonextendsJButton{publicOvalButton(){}pu
4、blicOvalButton(Stringtext){super(text);}protectedvoidpaintComponent(Graphicsg){//Drawanovalsuper.paintComponent(g);g.drawOval(5,5,getWidth()-10,getHeight()-10);}/**OverridegetmethodforpreferredSize*/publicDimensiongetPreferredSize(){returnnewDimension(100,50);}/**Overridegetmethodf
5、orminimumSize*/publicDimensiongetMinimumSize(){returnnewDimension(100,50);}}Java语言程序设计3/81importjava.awt.*;importjavax.swing.*;publicclassExercise13_8extendsJFrame{publicstaticvoidmain(String[]args){JFrameframe=newExercise13_8();frame.setSize(300,300);frame.setTitle("Exercise13_8")
6、;frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}publicExercise13_8(){getContentPane().add(newOctagonPanel());}}classOctagonPanelextendsJPanel{protectedvoidpaintComponent(Graphicsg){super.paintComponent(g);intxCenter=getWidth()/2;intyCenter=getHeight()/
7、2;intradius=(int)(Math.min(getWidth(),getHeight())*0.4);//CreateaPolygonobjectPolygonpolygon=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)));polygo
8、n.addPoint((int)(xCenter+r
此文档下载收益归作者所有