




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import java.util.*;public class SuperCalculator extends JFrame implements ActionListenerprivate JLabel heading;private JPanel headerPanel;private JTextField number1 = null; private JComboBox op = null; private JTextField number2 = null; private JButton eq = null;private JButton clear = null;private JButton a1 = null;private JButton a2 = null;private JButton a3 = null;private JButton a4 = null;private JTextField result = null;public SuperCalculator()this.setLayout(new FlowLayout(FlowLayout.CENTER);this.add(heading = new JLabel(“ “);this.add(heading = new JLabel(“SUPER CALCULATOR“);this.add(heading = new JLabel(“ “);this.add(heading = new JLabel(“ “);this.add(heading = new JLabel(“ “);/this.setLayout(null);/ this.add(heading = new JLabel(“ “);this.add(heading = new JLabel(“Numner1“);number1 = new JTextField(5);op = new JComboBox(new String“+“,“-“,“,“);number2 = new JTextField(5);eq = new JButton(“Exit“);eq.addActionListener(this);a1 = new JButton(“Add“);a1.addActionListener(this);a2 = new JButton(“Subtract“);a2.addActionListener(this);a3 = new JButton(“Multiple“);a3.addActionListener(this);a4 = new JButton(“Divide“);a4.addActionListener(this);clear = new JButton(“Clear“);clear.addActionListener(this);result = new JTextField(5);this.add(number1);this.add(heading = new JLabel(“Numner2“);this.add(number2);this.add(heading = new JLabel(“Result“);this.add(result);/this.result.disable();this.add(heading = new JLabel(“ “);this.add(heading = new JLabel(“ “);this.add(a1);this.add(a2);this.add(a3);this.add(a4);this.add(heading = new JLabel(“ “);this.add(clear); this.add(eq);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setSize(480, 280);this.setLocationRelativeTo(null);this.setTitle(“Super Calculator“);this.setResizable(false);this.setVisible(true);public static void main(String args) new SuperCalculator();Overridepublic void actionPerformed(ActionEvent arg0) if(arg0.getSource() = eq)System.exit(0); if(arg0.getSource() = a1)double n1 = 0.0;double n2 = 0.0;tryn1 = Double.parseDouble(number1.getText();catch(NumberFormatException nfe)JOptionPane.showMessageDialog(null, “number1 is not correct form“);tryn2 = Double.parseDouble(number2.getText();catch(NumberFormatException nfe)JOptionPane.showMessageDialog(null, “number2 is not correct form“);result.setText(String.valueOf(n1+n2);if(arg0.getSource() = a2)double n1 = 0.0;double n2 = 0.0;tryn1 = Double.parseDouble(number1.getText();catch(NumberFormatException nfe)JOptionPane.showMessageDialog(null, “number1 is not correct form“);tryn2 = Double.parseDouble(number2.getText();catch(NumberFormatException nfe)JOptionPane.showMessageDialog(null, “number2 is not correct form“);result.setText(String.valueOf(n1-n2);if(arg0.getSource() = a3)double n1 = 0.0;double n2 = 0.0;tryn1 = Double.parseDouble(number1.getText();catch(NumberFormatException nfe)JOptionPane.showMessageDialog(null, “number1 is not correct form“);tryn2 = Double.parseDouble(number2.getText();catch(NumberFormatException nfe)JOptionPane.showMessageDialog(null, “number2 is not correct form“);result.setText(String.valueOf(n1*n2);if(arg0.getSource() = a4)double n1 = 0.0;double n2 = 0.0;tryn1 = Double.parseDouble(number1.getText();catch(NumberFormatException nfe)JOptionPane.showMessageDialog(null, “number1 is not correct form“);tryn2 = Double.parseDouble(number2.getText();catch(NumberFormatException nfe)JOptionPane.showMessageDialog(null, “number2 is not correct form“);if(n2 != 0)result.setText(String.valueOf(n1/n2);elseJOptionPane.showMessageDialog(null, “you cannot divide a num
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年中国南水北调集团中线有限公司夏季招聘4人笔试历年参考题库附带答案详解
- 仙桃市事业单位2025年统一公开招聘笔试历年典型考题及考点剖析附带答案详解
- 海南省万宁市2025年事业单位公开招聘工作人员(第5号)笔试历年典型考题及考点剖析附带答案详解
- 毕节市事业单位2025年面向社会公开招聘笔试联考笔试历年典型考题及考点剖析附带答案详解
- 2025年铜陵市铜官区事业单位公开招聘笔试原始笔试历年典型考题及考点剖析附带答案详解
- 2025年新公共营养师三级真题及答案解析大全
- 小学生秋冬保健知识课件
- 2025年能源行业智能电网在数字化转型中的智能运维与故障预测报告
- 信息工程招标管理办法
- 人才工作标识管理办法
- 劳务派遣与服务协议
- 消费者权益保护培训课件
- DB11T 2454-2025 职业健康检查质量控制规范 生物样本化学物质检测
- 贸易公司员工职业操守行为准则制度
- 电气安全基础知识安全培训
- 部门保密培训课件
- 福建省南平市2024-2025学年八年级下学期期末考试数学试卷(含答案)
- 电网工程设备材料信息参考价2025年第一季度
- SLAP损伤的治疗课件
- 以理解为中心的历史教育 西安张汉林 全国历史教育专家2016年夏高考研讨会最新材料
- 拆除锅炉施工方案
评论
0/150
提交评论