基于AWT及SWINIG的GUI及事件处理实验报告

上传人:仙*** 文档编号:28188664 上传时间:2021-08-23 格式:DOC 页数:7 大小:182KB
返回 下载 相关 举报
基于AWT及SWINIG的GUI及事件处理实验报告_第1页
第1页 / 共7页
基于AWT及SWINIG的GUI及事件处理实验报告_第2页
第2页 / 共7页
基于AWT及SWINIG的GUI及事件处理实验报告_第3页
第3页 / 共7页
点击查看更多>>
资源描述
实 验 报 告实验课程名称: 基于AWT及SWINIG的GUI及事件处理实验 学 生 姓 名: 朱军 班 级 软件122 学 号 12477229 学 院(系): 信息数理学院 指 导 教 师: 杨亚南 成 绩: 实 验 时 间: 2014 年 10 月 17 日 2014 年 10 月 17 日一 实验目的1 熟悉JAVA的图形用户界面的基本组件,以及它们的层次关系和使用方法。2 掌握常见的布局管理设计器,如FlowLayout,GridLayout,BorderLayout。学会如何进行布局设计。3 掌握事件驱动原理,使GUI中的基本组件能够响应用户的操作。二实验原理 在应用程序的开发中,开发出友好的图形用户界面是极为重要的。在Java中有AWT(Abstract Windows Toolkit 抽象窗口工具集)和Swing两类工具集,其中AWT和本地代码有关并不完全独立于平台,而Swing成为轻量级组件完全支持跨平台。但是两者的机制完全一样,例如事件处理机制都采用监听方式;都提供了容器、布局管理器的机制。三实验内容1 编写程序,包括一个标签、文本框和命令按钮。当用户单击按钮时,程序把文本框中的内容复制到当前的位置。2 编写程序,利用JtextField和JpasswordField分别接收用户输入的用户名和密码,并对用户输入的密码进行检验。对于每个用户名有三次密码输入机会。3 编写程序实现一个计算器,包括10个数字(0-9)按钮和4个运算符(加、减、乘、除)按钮,以及等号和清空两个辅助按钮,还有一个显示输入输出的文本框。主要代码:package calculate;import java.util.*;/* * * author _USER_ */public class calculator extends javax.swing.JFrame private float s, t;private int op;/* Creates new form calculator */public calculator() initComponents();private void jButton20ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:jTextField1.setText();private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:s = new Float(jTextField1.getText().floatValue();op = 7;jTextField1.setText();private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:s = new Float(jTextField1.getText().floatValue();op = 6;jTextField1.setText();private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:s= new Float(jTextField1.getText().floatValue();op = 5;jTextField1.setText();private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:s = new Float(jTextField1.getText().floatValue();op = 4;jTextField1.setText();private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:s = new Float(jTextField1.getText().floatValue();op = 3;jTextField1.setText();private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:s = new Float(jTextField1.getText().floatValue();op = 2;jTextField1.setText();private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:s = new Float(jTextField1.getText().floatValue();op = 1;jTextField1.setText();private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:double result = 0;switch (op) case 1:t= new Float(jTextField1.getText().floatValue();result = s + t;break;case 2:t= new Float(jTextField1.getText().floatValue();result = s - t;break;case 3:t= new Float(jTextField1.getText().floatValue();result = s * t;break;case 4:t= new Float(jTextField1.getText().floatValue();result = s / t;break;case 5:result = 1 / (s);break;case 6:t= new Float(jTextField1.getText().floatValue();result = (int) s % (int) t;break;case 7:t= new Float(jTextField1.getText().floatValue();result = Math.pow(s, t);jTextField1.setText( + result);private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:jButton1ActionPerformed(evt);private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:jButton1ActionPerformed(evt);private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:jButton1ActionPerformed(evt);private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:jButton1ActionPerformed(evt);private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:jButton1ActionPerformed(evt);private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:jButton1ActionPerformed(evt);private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:jButton1ActionPerformed(evt);private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:jButton1ActionPerformed(evt);private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:jButton1ActionPerformed(evt);private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:jButton1ActionPerformed(evt);private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here:String d = evt.getActionCommand();jTextField1.setText(jTextField1.getText() + d);/* * param args the command line arguments */public static void main(String args) java.awt.EventQueue.invokeLater(new Runnable() public void run() new calculator().setVisible(true););运行结果: Page7
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 办公文档


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!