java图形实验报告docWord文档格式.docx
- 文档编号:13994040
- 上传时间:2022-10-16
- 格式:DOCX
- 页数:5
- 大小:16.58KB
java图形实验报告docWord文档格式.docx
《java图形实验报告docWord文档格式.docx》由会员分享,可在线阅读,更多相关《java图形实验报告docWord文档格式.docx(5页珍藏版)》请在冰豆网上搜索。
jButton2=new;
jButton3=new;
jButton4=new;
jButton5=new;
jButton6=new;
jButton7=new;
jButton8=new;
jButton9=new;
jButton10=new;
jButton11=new;
jButton12=new;
jButton13=new;
jButton14=new;
jButton15=new;
jTextField1=new;
jButton1.setText("
3"
);
jButton1.addActionListener(new{
publicvoid
actionPerformed(evt){
jButton2.setText("
1"
jButton2.addActionListener(new});
}jButton1ActionPerformed(evt);
{
jButton3.setText("
5"
jButton3.addActionListener(new});
}jButton2ActionPerformed(evt);
jButton4.setText("
2"
jButton4.addActionListener(new});
}jButton3ActionPerformed(evt);
jButton5.setText("
6"
});
}jButton4ActionPerformed(evt);
jButton5.addActionListener(new{
jButton6.setText("
8"
jButton6.addActionListener(new});
}jButton5ActionPerformed(evt);
jButton7.setText("
4"
jButton7.addActionListener(new});
}jButton6ActionPerformed(evt);
jButton8.setText("
7"
jButton8.addActionListener(new});
}jButton7ActionPerformed(evt);
jButton9.setText("
0"
jButton9.addActionListener(new});
}jButton8ActionPerformed(evt);
jButton10.setText("
9"
jButton10.addActionListener(new});
}jButton9ActionPerformed(evt);
jButton11.setText("
\u00f7"
jButton11.addActionListener(new});
}jButton10ActionPerformed(evt);
jButton12.setText("
\u00d7"
jButton12.addActionListener(new});
}jButton11ActionPerformed(evt);
jButton13.setText("
-"
jButton13.addActionListener(new});
}jButton12ActionPerformed(evt);
篇二:
JAVA实验报告
附件2:
实验报告封皮
20—学年第学期
课程
实验报告
学院:
计算机科学技术
专业:
软件工程
班级:
姓名:
学号:
任课教师:
王薇
实验日期:
XX年11月02日
-1-
-2-
实验日期:
XX年11月06日
-3-
-4-
篇三:
java图形用户界面实验报告
南京工程学院
课程名称JAVA基础
实验项目名称图形用户界面设计
实验学生班级
实验学生姓名
学号
同组学生姓名无
实验时间XX年11月
实验地点
实验成绩评定
指导教师签字年月日
一、实验目的和要求
1.目的:
掌握javaAWT及Swing组件的使用方法,包括窗口、框架、对话框、布局方式、面板、文本编辑器、按钮、组合框等,合理利用委托事件处理模型,掌握不同组件,不同事件的事件处理方法,设计出能够响应事件的java图形用户界面。
2.要求:
设计图形用户界面,事件处理,异常处理并弹出对话框,提示重新输入信息。
二、实验题目
验证哥德巴赫猜想,添加图形用户界面
三、实验方法与步骤(需求分析、算法设计思路、流程图等)
1.添加图形用户界面
importjava.awt.*;
import;
importjavax.swing.*;
publicclassGDBHextendsFrameimplementsActionListener//窗口框架响应单击事件,利用awt组件设计框架
{
privateButtonbutton;
//按钮
privateTextFieldtext1;
//文本行
privateTextAreatext2;
//文本区
publicGDBH()
super("
验证哥德巴赫猜想"
//设置框架窗口标题
this.setBounds(450,200,350,400);
//设置框架的位置和尺寸this.setResizable(false);
//设置框架大小不可改变this.setBackground(Color.lightGray);
//设置窗口背景颜色
this.setLayout(newFlowLayout());
//默认窗口流布局中对齐this.add(newLabel("
输入一个整数"
));
text1=newTextField("
"
20);
this.add(text1);
button=newButton("
this.add(button);
button.addActionListener(this);
//为按钮注册单击事件监听器,委托当前对象处理事件
//默认中对齐
text2=newTextArea(20,25);
text2.setEditable(false);
this.add(text2);
this.setVisible(true);
//设置组件可见
this.addWindowListener(newWinClose());
//为框架注册窗口事件监听器,委托WinClose对象处理事件
}
2.实现单击事件和窗口事件监听器接口
publicvoidactionPerformed(ActionEvente)//单击事件处理方法,实现ActionListener接口
Stringstr=text1.getText();
//获得文本行的字符串
try
longnum=Long.parseLong(str);
//将字符串转化成长整形
text2.setText(yz(num));
catch(NumberFormatExceptionn)
JOptionPane.showMessageDialog(this,"
\"
+str+"
字符串不能转换成整数,请重新输入!
!
return;
classWinCloseimplementsWindowListener//实现窗口事件监听器接口
publicvoidwindowClosing(WindowEvente)//窗口关闭事件处理方法
System.exit(0);
//程序运行结束
publicvoidwindowOpened(WindowEvente){}
publicvoidwindowClosed(WindowEvente){}
publicvoidwindowIconified(WindowEvente){}
publicvoidwindowDeiconified(WindowEvente){}
publicvoidwindowActivated(WindowEvente){}
publicvoidwindowDeactivated(WindowEvente){}
3.异常处理
若文本行中的字符串不能转化成长整形,将弹出对话框“字符串不能转换成整数,请重新输入!
;
另外如果所输入的整数为小于等于2或大于2小于等于5
也会弹出一个对话框“输入错误!
必须是大于2的偶数或大于5的奇数!
”(该窗口代码设置在yz()函数中)。
long
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 图形 实验 报告 doc
![提示](https://static.bdocx.com/images/bang_tan.gif)