1、java图形实验报告java图形实验报告篇一:java实验报告实验六Java图形用户界面信 息 工 程 学 院Java程序设计 实习报告JAVA图形用户界面实验六Java图形用户界面1实验目的(1)把握图形用户界面大体组件。(2)了解如何利用布局治理器对组件进行治理。(3)把握Java事件处置机制。2实验内容实验题1 编写一个模拟计算器的程序,利用面板和网格布局,添加一个文本框,10个数字按钮(0-9),4个加减乘除按钮,一个等号按钮,一个清除按钮,要求将计算公式和结果显示在文本框中。运行结果:实验报告的内容与格式按任课教师的要求书写。加法:要紧代码:private void initComp
2、onents() setStub(null); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton(); jButton8 =
3、 new javax.swing.JButton(); jButton9 = new javax.swing.JButton(); jButton10 = new javax.swing.JButton(); jButton11 = new javax.swing.JButton(); jButton12 = new javax.swing.JButton(); jButton13 = new javax.swing.JButton(); jButton14 = new javax.swing.JButton(); jButton15 = new javax.swing.JButton();
4、jTextField1 = new javax.swing.JTextField(); jButton1.setText(3); jButton1.addActionListener(new java.awt.event.ActionListener() public voidactionPerformed(java.awt.event.ActionEvent evt) jButton2.setText(1); jButton2.addActionListener(new); jButton1ActionPerformed(evt); java.awt.event.ActionListener
5、() public voidactionPerformed(java.awt.event.ActionEvent evt) jButton3.setText(5); jButton3.addActionListener(new); jButton2ActionPerformed(evt); java.awt.event.ActionListener() public voidactionPerformed(java.awt.event.ActionEvent evt) jButton4.setText(2); jButton4.addActionListener(new); jButton3A
6、ctionPerformed(evt); java.awt.event.ActionListener() public voidactionPerformed(java.awt.event.ActionEvent evt) jButton5.setText(6);); jButton4ActionPerformed(evt); jButton5.addActionListener(new java.awt.event.ActionListener() public voidactionPerformed(java.awt.event.ActionEvent evt) jButton6.setT
7、ext(8); jButton6.addActionListener(new); jButton5ActionPerformed(evt); java.awt.event.ActionListener() public voidactionPerformed(java.awt.event.ActionEvent evt) jButton7.setText(4); jButton7.addActionListener(new); jButton6ActionPerformed(evt); java.awt.event.ActionListener() public voidactionPerfo
8、rmed(java.awt.event.ActionEvent evt) jButton8.setText(7); jButton8.addActionListener(new); jButton7ActionPerformed(evt); java.awt.event.ActionListener() public voidactionPerformed(java.awt.event.ActionEvent evt) jButton9.setText(0); jButton9.addActionListener(new); jButton8ActionPerformed(evt); java
9、.awt.event.ActionListener() public voidactionPerformed(java.awt.event.ActionEvent evt) jButton10.setText(9); jButton10.addActionListener(new); jButton9ActionPerformed(evt); java.awt.event.ActionListener() public voidactionPerformed(java.awt.event.ActionEvent evt) jButton11.setText(u00f7); jButton11.
10、addActionListener(new); jButton10ActionPerformed(evt); java.awt.event.ActionListener() public voidactionPerformed(java.awt.event.ActionEvent evt) jButton12.setText(u00d7); jButton12.addActionListener(new); jButton11ActionPerformed(evt); java.awt.event.ActionListener() public voidactionPerformed(java
11、.awt.event.ActionEvent evt) jButton13.setText(-); jButton13.addActionListener(new); jButton12ActionPerformed(evt); java.awt.event.ActionListener() public voidactionPerformed(java.awt.event.ActionEvent evt) 篇二:JAVA实验报告附件2:实验报告封皮 20 学年第学期 课程 实 验 报 告 学 院: 运算机科学技术 专 业: 软件工程班 级:姓 名:学 号: 任课教师: 王薇实验日期:XX年
12、11 月 02 日-1-2- 实验日期:XX年 11 月 06 日 -3-4-篇三:java图形用户界面实验报告 南京工程学院 实 验 报 告 课程名称 JAVA基础 实验项目名称 图形用户界面设计 实验学生班级 实验学生姓名学 号同组学生姓名 无实验时刻 XX年11月实验地址 实验成绩评定 指导教师签字年 月 日一、实验目的和要求1.目的:把握java AWT及Swing组件的利用方式,包括窗口、框架、对话框、布局方式、面板、文本编辑器、按钮、组合框等,合理利用委托事件处置模型,把握不同组件,不同事件的事件处置方式,设计出能够响应事件的java图形用户界面。2.要求:设计图形用户界面,事件处
13、置,异样处置并弹出对话框,提示从头输入信息。二、实验题目验证哥德巴赫猜想,添加图形用户界面三、实验方式与步骤(需求分析、算法设计思路、流程图等)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;/文本区pu
14、blic 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 But
15、ton(验证哥德巴赫猜想);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对象处置事件public v
16、oid actionPerformed(ActionEvent e) /单击事件处置方式,实现ActionListener接口String str =text1.getText();/取得文本行的字符串trylong num = Long.parseLong(str); / 将字符串转化成长整形text2.setText(yz(num);catch(NumberFormatException n)JOptionPane.showMessageDialog(this, +str+字符串不能转换成整数,请从头输入!);return; class WinClose implements Window
17、Listener /实现窗口事件监听器接口 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 windowActivated(Windo
18、wEvent e) public void windowDeactivated(WindowEvent e) 假设文本行中的字符串不能转化成长整形,将弹出对话框“字符串不能转换成整数,请从头输入!;另外若是所输入的整数为小于等于2或大于2小于等于5也会弹出一个对话框“输入错误!必需是大于2的偶数或大于5的奇数!”(该窗口代码设置在yz()函数中)。trylong num = Long.parseLong(str);text2.setText(yz(num);catch(NumberFormatException n)JOptionPane.showMessageDialog(this, +st
19、r+字符串不能转换成整数,请从头输入!); 弹出对话框return;四、实验原始纪录(源程序、数据结构等)源程序如下import java.awt.*;import java.awt.event.*;import javax.swing.*;public class GDBH extends Frame implements ActionListenerprivate Button button;private TextField text1;private TextArea text2;public GDBH() super(验证哥德巴赫猜想); this.setBounds(450, 20
20、0, 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=n
21、ew TextArea(20,25); text2.setEditable(false); this.add(text2); this.setVisible(true); this.addWindowListener(new WinClose();public static void main(String args)new GDBH();public void actionPerformed(ActionEvent e)String str =text1.getText(); try long num = Long.parseLong(str);text2.setText(yz(num); catch(NumberFormatException n) JOptionPane.showMessageDialog(this, +str+字符串不能转换成整数,请从头输入!);return;public String yz(long num) String str1 = ; if(num2&num%2=0) for (long i = 2;i j5&num%2!=0) for(long i=2;inum;i+) for(long j=i;jnum;j+)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1