200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > java图形用户界面设计实验_java图形用户界面设计实验报告(共10篇).doc

java图形用户界面设计实验_java图形用户界面设计实验报告(共10篇).doc

时间:2021-04-30 15:37:44

相关推荐

java图形用户界面设计实验_java图形用户界面设计实验报告(共10篇).doc

java图形用户界面设计实验报告(共10篇)

java图形用户界面设计实验报告(共10篇) java图形用户界面实验报告

南京工程学院

实 验 报 告

课程名称 JAVA基础

实验项目名称 图形用户界面设计

实验学生班级

实验学生姓名

学 号

同组学生姓名 无

实验时间 11月

实验地点

实验成绩评定

指导教师签字年 月 日

一、实验目的和要求

1.目的:掌握java AWT及Swing组件的使用方法,包括窗口、框架、对话框、布局方式、面板、文本编辑器、按钮、组合框等,合理利用委托事件处理模型,掌握不同组件,不同事件的事件处理方法,设计出能够响应事件的java图形用户界面。

2.要求:设计图形用户界面,事件处理,异常处理并弹出对话框,提示重新输入信息。

二、实验题目

验证哥德巴赫猜想,添加图形用户界面

三、实验方法与步骤(需求分析、算法设计思路、流程图等)

1.添加图形用户界面

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class GDBH extends Frame implements ActionListener //窗口框架响应单击事件,利用awt组件设计框架

{

private Button button; //按钮

private TextField text1; //文本行

private TextArea text2;//文本区

public GDBH()

{

super(验证哥德巴赫猜想); //设置框架窗口标题

this.setBounds(450, 200, 350, 400); //设置框架的位置和尺寸 this.setResizable(false); // 设置框架大小不可改变 this.setBackground(Color.lightGray); // 设置窗口背景颜色

this.setLayout(new FlowLayout()); // 默认窗口流布局 中对齐 this.add(new Label(输入一个整数));

text1=new TextField(,20);

this.add(text1);

button=new Button(验证哥德巴赫猜想);

this.add(button);

button.addActionListener(this); //为按钮注册单击事件监听器,委托当前对象处理事件

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

text2=new TextArea(20,25);

text2.setEditable(false);

this.add(text2);

this.setVisible(true); //设置组件可见

this.addWindowListener(new WinClose());// 为框架注册窗口事件监听器,委托WinClose对象处理事件

}

2.实现单击事件和窗口事件监听器接口

public void actionPerformed(ActionEvent e) //单击事件处理方法,实现ActionListener接口

{

String str =text1.getText();//获得文本行的字符串

try

{

long num = Long.parseLong(str); // 将字符串转化成长整形

text2.setText(yz(num));

}

catch(NumberFormatException n)

{

JOptionPane.showMessageDialog(this, \+str+\字符串不能转换成整数,请重新输入!!);

return;

}

}

class WinClose implements WindowListener //实现窗口事件监听器接口

{

public void windowClosing(WindowEvent e) // 窗口关闭事件处理方法

{

System.exit(0); //程序运行结束

}

public void windowOpened(WindowEvent e) {}

public void windowClosed(WindowEvent e) {}

public void windowIconified(WindowEvent e) {}

public void windowDeiconified(WindowEvent e) {}

public void windo

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。