面向对象程序设计度量衡换算器课程设计Word下载.docx
- 文档编号:13856431
- 上传时间:2022-10-14
- 格式:DOCX
- 页数:12
- 大小:18.99KB
面向对象程序设计度量衡换算器课程设计Word下载.docx
《面向对象程序设计度量衡换算器课程设计Word下载.docx》由会员分享,可在线阅读,更多相关《面向对象程序设计度量衡换算器课程设计Word下载.docx(12页珍藏版)》请在冰豆网上搜索。
设讣换算单位及换算关系
在程序中提供不同的换算单位以供选择同时放入JComboBox选择组合框中同时运用选择结构中的辻_else语句进行选择不同的换算单位在选择后利用换算公式对原数据进行数据换算得到最终需要的换算后的数据结果
设计功能选项帮助按钮和异常处理
在图形用户界面中创建一帮助按钮这里的帮助按钮只是对本程序的说明介绍了程序的一些详细信息在程序主函数中设置异常处理机制对可能出现的异常进行抛出异常和异常处理操作
课程设讣中遇到的难点及解决办法
在程序设讣中遇到的问题主要包括对面板容器的布置以及对选择结构中的
if.else语句的灵活运用在很多时候因为一点的差错导致能够选择判断语句的错误不过在成功的设置了笫一个后后面的就显得很容易了在设置对帮助中程序说明的弹出设置遇到很大的阻力后通过新建一个AboutFrame类继承JFrame中的成员方法得以解决在进行温度类型的换算时摄氏度到华氏度的转换时是上网白度猜得到的换算关系在程序设讣中有很多不明口不清楚的问题都是通过上网搜索或者询问老师得以解决的
四总结
通过这次课程设计我对java程序设计语言中的图形用户界面有了更加
深刻的理解和认识无论是对JPanel面板容器JButton按钮还是对JTextField
文本框JcomboBox组合框的应用都有了更加深刻的了解同时通过程序设计中图形用户界面以及转换功能的不断完善我的个人能力也在不断地提高我对面向对象程序设计也有了更好的掌握虽然距离熟练的掌握每一个功能操作还有一定的差距但是我相信通过不断地努力和学习我一定能做的更好更完善
五附录主要源程序代码及运行结果
importjavaawt
importcomt
importjavaxswing
publicclassConversionextendsJFrameimplementsActionListener
建立工具栏中的按钮组件
JToolBartoolBarnewJToolBar
JButtonpicLengthnewJButton"
长度L
JButtonpicSquarenewJButton"
面积S
JButtonpicVolumenewJButton"
体积V
JButtonpicTempernewJButton"
温度K
JPanelboxLengthnewJPanel
JPanelboxSquarenewJPanel
JPanelboxVolumenewJPanel
JPanelboxTempernewJPanel
JMenuBarjMenuBarnewJMenuBar
JMenuaboutMenunewJMenu"
帮助"
JMenuItemaboutItemnewJMenuItem"
程序说明"
String[]length"
厘米cm"
"
分米dm"
米千米km"
平方米m2〃String[]square〃平方厘米cm2"
平方分米dm2"
String[Jvolume"
立方厘Xcm3毫升mL"
立方分米dm3升立方米
m3"
StringE]temper〃摄氏度?
华氏度?
开尔文度?
F输入
JComboBoxjbxLengthnewJComboBoxlength
JComboBoxjbxSquarenewJComboBoxsquare
JComboBox
jbxVolume
new
volume
jbxTemper
temper
转换成
jbxLengthl
length
jbxSquare1
square
jbxVolumel
jbxTemper1
输入框
JTextField
jtfLength
JTextField20
jtfLengthlnewJTextField20
jtfSquarenewJTextField20
jtfSquarelnewJTextField20
jtfVolumenewJTextField20
jtfVolumelnewJTextField20
jtfTempernewJTextField20
jtfTemperlnewJTextField20
CardLayout
centerLayoutnewCardLayout55
JPanelcenterPanenewJPanel
privatestaticfinallongserialVersionUIDILpublicConversion
jtfLengthlsetEditablefalse
jtfSquareIsetEditablefalse
jtfVolumelsetEditablefalse
jtfTemperIsetEditablefalsesetTitle"
度量衡换算器"
setResizablefalse
setDefaultCloseOperationJFrameEXIT_ON_CLOSE
boxLengthsetLayout
newBoxLayout
boxLengthBoxLayoutY_AXIS
boxSquaresetLayoutnewBoxLayout
boxSquareBoxLayoutY_AXIS
boxVolumesetLayout
boxVolumeBoxLayoutY_AXIS
boxTempersetLayout
boxTemperBoxLayoutY_AXIS
在丄具栏中添加按钮组件
toolBaraddpicLengthtoolBaraddpicSquare
toolBaraddpicVolume
toolBaraddpicTemperpicLengthsetMnemonicLpicSquaresetMnemonicSpicVolumesetNlnemonicVpicTempersetMnemonicKboxLengthaddnewJLabel"
输入"
长度布局
boxLengthaddjbxLengthboxLengthaddjtfLength
boxLengthaddnewJLabel"
转换成"
boxLengthaddjbxLengthl
boxLengthaddjtfLengthl
boxSquareaddnewJLabel输入"
面积布局
boxSquareaddjbxSquare
boxSquareaddjtfSquare
boxSquareaddnewJLabel"
boxSquareadd
jtfSquarel
boxVolumeadd
newJLabel
〃输入"
体积布局
jtfVolume
〃转换成"
jtfVolumel
boxTemperaddnewJLabel
”输入〃温度布局
boxTemperadd
jtfTemper
〃转换成〃
jbxTemperl
jtfTemperl
centerPanesetLayoutcenterLayout设置中心区布局
centerPaneadd
Lengthpage,zboxLength
centerPaneaddz/Squarepage,zboxSquare
centerPaneadd"
Volumepage,zboxVolume
'
Temperaturepage,zboxTemperaboutMenuaddaboutItemjMenuBaraddaboutMenusetJMenuBarjMenuBar
ContainercontentPanegetContentPanecontentPaneaddtoolBarBorderLayoutNORTHcontentPaneaddcenterPaneBorderLayoutCENTERaboutltemaddActionListenernewActionListenerpublicvoidactionPerformedActionEventapAboutFrameaboutFramenewAboutFrameaboutFramesetBounds00400300aboutFramesetVisibletrue
为工具栏中组件添加监听
picLengthaddActionListenerthispicSquareaddActionListenerthispicVolumeaddActionListenerthispicTemperaddActionListenerthis
各个面板中下拉框添加监听
newActionListener
jtfLengthaddActionListenerpublicvoidactionPerformedActionEventae
indexListener1jtfLengthaddFocusListenernewFocusListenerpublicvoidfocusGain
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 面向 对象 程序设计 度量衡 换算 课程设计