java图形用户界面设计实验报告(共10篇) 南京工程学院实验报告课程名称JAVA基础实验项目名称图形用户界面设计实验学生班级实验学生姓名学号同组学生姓名无实验时间XX年11月实验地点实验成绩评定指导教师签字年月日一、实验目的和要求 :掌握javaAWT及Swing组件的使用方法,包括窗口、框架、对话框、布局方式、面板、文本编辑器、按钮、组合框等,合理利用委托事件处理模型,掌握不同组件,不同事件的事件处理方法,设计出能够响应事件的java图形用户界面。 :设计图形用户界面,事件处理,异常处理并弹出对话框,提示重新输入信息。二、实验题目验证哥德巴赫猜想,添加图形用户界面三、实验方法与步骤 import*; import*; import*; lassGDBHextendsFrameimplementsActionListener//窗口框架响应单击事件,利用awt组件设计框架{ privateButtonbutton;//按钮 privateTextFieldtext1;//文本行 privateTextAreatext2;//文本区 publicGDBH() { super("验证哥德巴赫猜想");//设置框架窗口标题(450,200,350,400);//设置框架的位置和尺寸(false);//设置框架大小不可改变();//设置窗口背景颜色(newFlowLayout());//默认窗口流布局中对齐(newLabel("输入一个整数")); text1=newTextField("",20); (text1); button=newButton("验证哥德巴赫猜想"); (button); (this);//为按钮注册单击事件***,委托当前对象处理事件(newFlowLayout());//默认中对齐 text2=newTextArea(20,25); (false); (text2); (true);//设置组件可见(newWinClose());//为框架注册窗口事件***,委托WinClose对象处理事件} ***接口 publicvoidactionPerformed(ActionEvente)//单击事件处理方法,实现ActionListener接口{ Stringstr=();//获得文本行的字符串 try { longnum=(str);//将字符串转化成长整形(yz(num)); } catch(NumberFormatExceptionn) { (this,"\""+str+"\"字符串不能转换成整数,请重新输入!!"); return; } } classWinCloseimplementsWindowListener//实现窗口事件***接口{ publicvoidwindowClosing(WindowEvente)//窗口关闭事件处理方法{ (0);//程序运行结束} publicvoidwindowOpened(WindowEvente){} publicvoidwindowClosed(WindowEvente){} publicvoidwindowIconified(WindowEvente){} publicvoidwindowDeiconified(WindowEvente){} publicvoidwindowActivated(WindowEvente){} publicvoidwindowDeactivated(WindowEvente){} } ,将弹出对话框“字符串不能转换成整数,请重新输入!!";另外如果所输入的整数为小于等于2或大于2小于等于5 也会弹出一个对话框“输入错误!必须是大于2的偶数或大于5的奇数!!”函数中)。 try { longnum=(str); (yz(num)); } catch(NumberFormatExceptionn) { (this,"\""+str+"\"字符串不能转换成整数,请重新输入!!");弹出对话框 return; } 四、实验原始纪录源程序如下 import*; import*; import*; lassGDBHextendsFrameimplementsActionListener { privateButtonbutton; privateTextFieldtext1; privateTextAreatext2; publicGDBH() { super("验证哥德巴赫猜想");(450,200,350,400);(false);();(newFlowLayout());(newLabel("输入一个整数"));te
java图形用户界面设计实验报告(共10篇) 来自淘豆网www.taodocs.com转载请标明出处.