java图形实验报告doc.docx

上传人:b****2 文档编号:1073805 上传时间:2022-10-16 格式:DOCX 页数:5 大小:16.58KB
下载 相关 举报
java图形实验报告doc.docx_第1页
第1页 / 共5页
java图形实验报告doc.docx_第2页
第2页 / 共5页
java图形实验报告doc.docx_第3页
第3页 / 共5页
java图形实验报告doc.docx_第4页
第4页 / 共5页
java图形实验报告doc.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

java图形实验报告doc.docx

《java图形实验报告doc.docx》由会员分享,可在线阅读,更多相关《java图形实验报告doc.docx(5页珍藏版)》请在冰豆网上搜索。

java图形实验报告doc.docx

java图形实验报告doc

java图形实验报告

篇一:

java实验报告实验六Java图形用户界面

  信息工程学院

  Java程序设计实习报告

  JAVA图形用户界面

  实验六Java图形用户界面

  1.实验目的

  

(1)掌握图形用户界面基本组件。

  

(2)了解如何使用布局管理器对组件进行管理。

  (3)掌握Java事件处理机制。

  2.实验内容

  实验题1编写一个模拟计算器的程序,使用面板和网格布局,添加一个文本框,10个数字按钮(0-9),4个加减乘除按钮,一个等号按钮,一个清除按钮,要求将计算公式和结果显示在文本框中。

  运行结果:

  实验报告的内容与格式按任课教师的要求书写。

  加法:

  主要代码:

  privatevoidinitComponents(){

  setStub(null);jButton1=new;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);{

  publicvoid

  actionPerformed(evt){

  jButton3.setText("5");jButton3.addActionListener(new});}jButton2ActionPerformed(evt);{

  publicvoid

  actionPerformed(evt){

  jButton4.setText("2");jButton4.addActionListener(new});}jButton3ActionPerformed(evt);{

  publicvoid

  actionPerformed(evt){

  jButton5.setText("6");});}jButton4ActionPerformed(evt);

  jButton5.addActionListener(new{

  publicvoid

  actionPerformed(evt){

  jButton6.setText("8");jButton6.addActionListener(new});}jButton5ActionPerformed(evt);{

  publicvoid

  actionPerformed(evt){

  jButton7.setText("4");jButton7.addActionListener(new});}jButton6ActionPerformed(evt);{

  publicvoid

  actionPerformed(evt){

  jButton8.setText("7");jButton8.addActionListener(new});}jButton7ActionPerformed(evt);{

  publicvoid

  actionPerformed(evt){

  jButton9.setText("0");jButton9.addActionListener(new});}jButton8ActionPerformed(evt);{

  publicvoid

  actionPerformed(evt){

  jButton10.setText("9");jButton10.addActionListener(new});}jButton9ActionPerformed(evt);{

  publicvoid

  actionPerformed(evt){

  jButton11.setText("\u00f7");jButton11.addActionListener(new});}jButton10ActionPerformed(evt);{

  publicvoid

  actionPerformed(evt){

  jButton12.setText("\u00d7");jButton12.addActionListener(new});}jButton11ActionPerformed(evt);{

  publicvoid

  actionPerformed(evt){

  jButton13.setText("-");jButton13.addActionListener(new});}jButton12ActionPerformed(evt);{

  publicvoid

  actionPerformed(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);//为按钮注册单击事件监听器,委托当前对象处理事件

  this.setLayout(newFlowLayout());//默认中对齐

  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()函数中)。

  try

  {

  long

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 初中作文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1