java迷你计算机程序,Java计算机程序.doc

Java计算机程序

Java程序设计课程设计报告

Java简易计算器程序设计

专业 信息与计算科学

姓名 任航

班级 70803

学号 7080308

指导教师王薇

日期2011年4月12日

1.题目:Java简易计算器程序设计

2. 课程设计内容:

通过GUI界面的计算机程序,设计简易计算器,可以进行简单的加,减,乘运算。

3.功能简介

1.按下数字键在文本框上会显示数字,这是计算器最基本的功能;

2.上面一个文本框显示计算过程,下面一个文本框显示输入的数字

4.当按下的运算符号时前面已经按下过运算符号时,下面一个文本框显示上一个运算符号以及两个数之间的运算结果。

4.程度界面

5. 程序代码

import java.awt.*;

import java.awt.event.*;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

class calculator extends JFrame implements ActionListener

{

JTextField tf= new JTextField(25);

JButton b0 = new JButton("0");

JButton b1 = new JButton("1");

JButton b2 = new JButton("2");

JButton b3 = new JButton("3");

JButton b4 = new JButton("4");

JButton b5 = new JButton("5");

JButton b6 = new JButton("6");

JButton b7 = new JButton("7");

JButton b8 = new JButton("8");

JButton b9 = new JButton("9");

JButton bPoint = new JButton(".");

JButton bDiv = new JButton("/");

JButton bMul = new JButton("*");

JButton bSub = new JButton("-");

JButton bAdd = new JButton("+");

JButton bCal = new JButton("=");

int op;

String s1;

String s2;

public calculator()

{

this.setTitle("计算器");

JPanel jpDisplay = new JPanel();

JPanel jpInput = new JPanel();

JPanel jpLeft = new JPanel();

JPanel jpRight = new JPanel();

tf.setText(" ");

tf.setHorizontalAlignment(JTextField.RIGHT);

jpDisplay.add(tf);

jpLeft.setLayout(new GridLayout(5, 1));

JPanel p2 = new JPanel();

b0.addActionListener(this);

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

b4.addActionListener(this);

b5.addActionListener(this);

b6.addActionListener(this);

b7.addActionListener(this);

b8.addActionListener(this);

b9.addActionListener(this);

bPoint.addActionListener(this);

bDiv.addActionListener(this);

bMul.addActionListener(this);

bSub.addActionListener(this);

bAdd.addActionListener(this);

bCal.addActionListener(thi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以计算加减乘除的计算器小程序package zj lec1; import java awt BorderLayout; import java awt FlowLayout; import java awt GridLayout; import java awt event ActionEvent; import java awt event ActionListener; import java math BigInteger; import javax swing JButton; import javax swing JFrame; import javax swing JLabel; import javax swing JPanel; import javax swing JTextField; public class 简易计算机 extends JFrame implements ActionListener { JTextField a b c d; JButton ok exit; public 简易计算机 { this setLayout new FlowLayout ; this add a new JTextField 10 ; a setText "0" ; a setHorizontalAlignment JTextField RIGHT ; this add b new JTextField 1 ; this add c new JTextField 10 ; c setText "0" ; c setHorizontalAlignment JTextField RIGHT ; this add ok new JButton " " ; this add d new JTextField 10 ; this add exit new JButton "Exit" ; a addActionListener this ; b addActionListener this ; c addActionListener this ; exit addActionListener this ; ok addActionListener this ; this setSize 540 70 ; this setTitle "简易计算机" ; this setVisible true ; this setResizable false ; } public static void main String[] args { new 简易计算机 ; } @Override public void actionPerformed ActionEvent e { if e getSource ok || e getSource c || e getSource a { BigInteger ia new BigInteger a getText ; BigInteger ic new BigInteger c getText ; String ib b getText ; 判断是用加法 还是减法 还是乘法 除法 if ib contains "+" { BigInteger id ia add ic ; d setText id toString ; } else if ib contains " " { BigInteger id ia subtract ic ; d setText id toString ; } else if ib contains " " { BigInteger id ia multiply ic ; d setText id toString ; } else if ib contains " " { BigInteger id ia divide ic ; d setText id toString ; } } else if e getSource exit { System exit 0 ; } } }">可以计算加减乘除的计算器小程序package zj lec1; import java awt BorderLayout; import java awt FlowLayout; import java awt GridLayout; import java awt event ActionEvent; import java awt event ActionListener; import java math BigInteger; import javax swing JButton; import javax swing J [更多]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值