简单加减乘除计算器_第1页
简单加减乘除计算器_第2页
简单加减乘除计算器_第3页
简单加减乘除计算器_第4页
简单加减乘除计算器_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论