全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 农村客运站地震应急预案
- 企业内部控制与制度设计 第3版 课件 项目七 成本费用控制
- 上海市师范大学第二附属中学2023-2024学年高三第六次模拟考试化学试卷含解析
- 北京市西城区第四中学2024届高三第六次模拟考试化学试卷含解析
- 内蒙古呼和浩特市第六中学2023-2024学年高考仿真卷化学试题含解析
- 安徽师范大学附中2024年高三最后一卷化学试卷含解析
- 山东临沂市第十九中学2024年高三下学期联考化学试题含解析
- 2023年湖南省益阳市【中考】数学真题【带答案】
- 幼儿园的毕业演讲稿 15篇
- 计算机行业OpenAI发布会分析报告:GPTsAI应用
- 垃圾焚烧的利与弊
- 朗致集团逻辑测评试卷2024
- 2023年四川烟草招聘考试真题
- 2024年安徽省合肥市蜀山区中考一模道德与法治试题
- 心肺复苏机完整版本
- 楚雄牛肝菌保育促繁技术规程-编制说明
- 无尘车间保洁方案
- 《高中生职业生涯规划教育研究》课题研究方案
- 设备管理的人员培训与素质提升
- 幼儿权利的保护
- 舞蹈行业痛点分析
评论
0/150
提交评论