1. 首页 > 科技

java加减乘除计算器界面编程? java计算器程序代码

java加减乘除计算器界面编程?java计算器程序代码

用Java编写一个简单的计算器,可以实现加减乘除的计算,并且有一个归零按钮,其他不需要什么复杂的东

简单的啊,我有个自己编的完美的,不过给你改成简单的吧。有注释。 import java.awt.*; import javax.swing.*; import javax.swing.border.*; import java.awt.event.*; import java.text.*; public class Calculator extends JFrame implements ActionListener { int m=0,i,n=0; float sum=0,s1,s2,equ; String v=""; JPanel delete_main = new JPanel(); JPanel delete = new JPanel(); JPanel buttons = new JPanel(); JTextField text = new JTextField("0"); JButton backspace = new JButton("Backspace"); JButton c = new JButton("C"); JButton ce = new JButton("CE"); JButton bt1= new JButton("1"); JButton bt2= new JButton("2"); JButton bt3= new JButton("3"); JButton bt4= new JButton("+"); JButton bt5 = new JButton("4"); JButton bt6= new JButton("5"); JButton bt7= new JButton("6"); JButton bt8= new JButton("-"); JButton bt9= new JButton("7"); JButton bt10= new JButton("8"); JButton bt11= new JButton("9"); JButton bt12= new JButton("*"); JButton bt13= new JButton("0"); JButton bt14= new JButton("."); JButton bt15= new JButton("="); JButton bt16= new JButton("/"); public Calculator() { super("简易计算器--超人不会飞荣誉出品"); delete.setLayout(new GridLayout(1, 3, 15, 15)); delete.add(backspace); delete.add(c); delete.add(ce); delete.setBorder(new LineBorder(delete.getBackground(), 5));//添加边框 c.addActionListener(this); ce.addActionListener(this); backspace.addActionListener(this); text.setFont(new Font("宋体", Font.BOLD +Font.ITALIC, 20)); // 设置显示字体 text.setBackground(Color.getHSBColor(44, 3, 87)); text.setBorder(new LineBorder(Color.ORANGE, 1)); text.setHorizontalAlignment(SwingConstants.RIGHT); // 设置鼠标靠右 text.setEditable(false); // 屏蔽键盘输入,防止非法字符 delete_main.setLayout(new GridLayout(2, 1, 10, 10)); delete_main.add(text, BorderLayout.NORTH); delete_main.add(delete, BorderLayout.SOUTH); buttons.setLayout(new GridLayout(4, 5, 10, 20)); bt1.addActionListener(this); // 为各个按钮添加事件监听 buttons.add(bt1); bt2.addActionListener(this); buttons.add(bt2); bt3.addActionListener(this); buttons.add(bt3); bt4.addActionListener(this); buttons.add(bt4); bt5.addActionListener(this); buttons.add(bt5); bt6.addActionListener(this); buttons.add(bt6); bt7.addActionListener(this); buttons.add(bt7); bt8.addActionListener(this); buttons.add(bt8); bt9.addActionListener(this); buttons.add(bt9); bt10.addActionListener(this); buttons.add(bt10); bt11.addActionListener(this); buttons.add(bt11); bt12.addActionListener(this); buttons.add(bt12); bt13.addActionListener(this); buttons.add(bt13); bt14.addActionListener(this); buttons.add(bt14); bt15.addActionListener(this); buttons.add(bt15); bt16.addActionListener(this); buttons.add(bt16); buttons.setBorder(new LineBorder(delete.getBackground(), 5));//边框 this.setLayout(new BorderLayout()); this.add(delete_main, BorderLayout.NORTH); this.add(buttons, BorderLayout.SOUTH); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //添加关闭窗口事件监听器 pack(); //自动设置窗体大小 setResizable(false); // 设置面板大小不可变 setVisible(true); Toolkit tk = this.getToolkit(); Dimension de = tk.getScreenSize(); setBounds((de.width - this.getWidth()) / 2,(de.height - this.getHeight()) / 2, this.getWidth(), this.getHeight()); //使之居于屏幕正中央 } public void actionPerformed(ActionEvent e) { //事件响应 //Object source = e.getSource(); if(e.getSource()==backspace) //退格键 { v=v.substring(0,v.length() - 1); text.setText(v); } if(e.getSource()==c||e.getSource()==ce) //清空键 { m=0; sum=0; v="";s1=0;s2=0;i=0; text.setText("0"); } if(e.getSource()==bt1) { if(m==1) v=""; v=v+"1"; text.setText(v); m=0;n=1; } if(e.getSource()==bt2) { if(m==1) v=""; v=v+"2"; text.setText(v); m=0;n=1; } if(e.getSource()==bt3) { if(m==1) v=""; v=v+"3"; text.setText(v); m=0;n=1; } if(e.getSource()==bt4) // +按钮 { if(n==1) //如果按之前按了0~9数字键,就运算 { sum=Float.parseFloat(v); } else //如果按之前没按0~9数字键,直接按了运算符,不做任何操作 { } i=1; m=1;n=0; } if(e.getSource()==bt5) { if(m==1) v=""; v=v+"4"; text.setText(v); m=0;n=1; } if(e.getSource()==bt6) { if(m==1) v=""; v=v+"5"; text.setText(v); m=0;n=1; } if(e.getSource()==bt7) { if(m==1) v=""; v=v+"6"; text.setText(v); m=0;n=1; } if(e.getSource()==bt8) // -按钮 { if(n==1) { sum=Float.parseFloat(v); } else { } i=2; m=1;n=0; } if(e.getSource()==bt9) { if(m==1) v=""; v=v+"7"; text.setText(v); m=0;n=1; } if(e.getSource()==bt10) { if(m==1) v=""; v=v+"8"; text.setText(v); m=0;n=1; } if(e.getSource()==bt11) { if(m==1) v=""; v=v+"9"; text.setText(v); m=0;n=1; } if(e.getSource()==bt12) //*按钮 { if(n==1) { sum=Float.parseFloat(v); } else { } i=3; m=1;n=0; } if(e.getSource()==bt13) { if(m==1) v=""; v=v+"0"; text.setText(v); m=0;n=1; } if(e.getSource()==bt14) { } if(e.getSource()==bt15) //等于按钮 { if(m==1) // 如果输入了+=等非法输入,不做任何操作 { } else { s1=sum; s2=Float.parseFloat(v); switch(i) { case 0: //如果按过数字键后直接按等号,直接输出 equ=Float.parseFloat(v); break; case 1: equ=s1+s2; break; case 2: equ=s1-s2; break; case 3: equ=s1*s2; break; case 4: equ=s1/s2; break; } sum=0;v=""; //清空运算数 v=String.valueOf(equ); text.setText(String.valueOf(equ)); i=0; } } if(e.getSource()==bt16) // 除按钮 { if(n==1) { sum=Float.parseFloat(v); } else { } i=4; m=1;n=0; } } public static void main(String[] args) { Calculator bt=new Calculator(); } }

求简单java写计算器代码加减乘除

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class Calculator extends JFrame implements ActionListener

{

private boolean dotExist, operated, equaled; // 帮助运算的布尔变量

private double storedNumber; // 目前的结果

private char lastOperator; // 表示上一运算符

private JTextField operation; // 结果栏

private JButton dot, plus, minus, multi, div, sqrt, equal, changePN, clear; // 运算符

private JButton[] numbers; // 数字

// 构造者

public Calculator()

{

setTitle("Calculator");

// 初始化变量

dotExist = false; // 表示当前的数是否有小数点

operated = false; // 表示任意运算符是否被按下

equaled = false; // 表示等号是否被按下

storedNumber = 0;

lastOperator = '?';

// 初始化窗口变量

operation = new JTextField("0");

operation.setEditable(false);

numbers = new JButton[10];

for (int i = 0; i < 10; i++)

numbers[i] = new JButton("" + i);

dot = new JButton(".");

plus = new JButton("+");

minus = new JButton("-");

multi = new JButton("*");

div = new JButton("/");

sqrt = new JButton("√");

equal = new JButton("=");

changePN = new JButton("±");

clear = new JButton("AC");

// 将窗口物体放入窗口

GridBagLayout layout = new GridBagLayout();

getContentPane().setLayout(layout);

addComponent(layout, operation, 0, 0, 4, 1);

addComponent(layout, numbers[1], 1, 0, 1, 1);

addComponent(layout, numbers[2], 1, 1, 1, 1);

addComponent(layout, numbers[3], 1, 2, 1, 1);

addComponent(layout, numbers[4], 2, 0, 1, 1);

addComponent(layout, numbers[5], 2, 1, 1, 1);

addComponent(layout, numbers[6], 2, 2, 1, 1);

addComponent(layout, numbers[7], 3, 0, 1, 1);

addComponent(layout, numbers[8], 3, 1, 1, 1);

addComponent(layout, numbers[9], 3, 2, 1, 1);

addComponent(layout, dot, 4, 0, 1, 1);

addComponent(layout, numbers[0], 4, 1, 1, 1);

addComponent(layout, sqrt, 4, 2, 1, 1);

addComponent(layout, plus, 1, 3, 1, 1);

addComponent(layout, minus, 2, 3, 1, 1);

addComponent(layout, multi, 3, 3, 1, 1);

addComponent(layout, div, 4, 3, 1, 1);

addComponent(layout, equal, 5, 0, 2, 1);

addComponent(layout, changePN, 5, 2, 1, 1);

addComponent(layout, clear, 5, 3, 1, 1);

}

// 对按钮进行反应的方法

public void actionPerformed(ActionEvent e)

{

JButton btn = (JButton)e.getSource();

if (btn == clear)

{

operation.setText("0");

dotExist = false;

storedNumber = 0;

lastOperator = '?';

}

else if (btn == equal)

{

operate('=');

equaled = true;

}

else if (btn == plus)

{

operate('+');

equaled = false;

}

else if (btn == minus)

{

operate('-');

equaled = false;

}

else if (btn == multi)

{

operate('*');

equaled = false;

}

else if (btn == div)

{

operate('/');

equaled = false;

}

else if (btn == changePN)

{

operate('p');

operate('=');

equaled = true;

}

else if (btn == sqrt)

{

operate('s');

operate('=');

equaled = true;

}

else

{

if (equaled)

storedNumber = 0;

for (int i = 0; i < 10; i++)

if (btn == numbers[i])

{

if (operation.getText().equals("0"))

operation.setText("" + i);

else if(! operated)

operation.setText(operation.getText() + i);

else

{

operation.setText("" + i);

operated = false;

}

}

if (btn == dot && ! dotExist)

{

operation.setText(operation.getText() + ".");

dotExist = true;

}

}

}

// 进行运算的方法

private void operate(char operator)

{

double currentNumber = Double.valueOf(operation.getText()).doubleValue();

if (lastOperator == '?')

storedNumber = currentNumber;

else if (lastOperator == '+')

storedNumber += currentNumber;

else if (lastOperator == '-')

storedNumber -= currentNumber;

else if (lastOperator == '*')

storedNumber *= currentNumber;

else if (lastOperator == '/')

storedNumber /= currentNumber;

else if (lastOperator == 'p')

storedNumber *= -1;

else if (lastOperator == 's')

storedNumber = Math.sqrt(currentNumber);

else if (lastOperator == '=' && equaled)

storedNumber = currentNumber;

operation.setText("" + storedNumber);

operated = true;

lastOperator = operator;

}

// 快捷使用GridBagLayout的方法

private void addComponent(GridBagLayout layout, Component component, int row, int col, int width, int height)

{

GridBagConstraints constraints = new GridBagConstraints();

constraints.fill = GridBagConstraints.BOTH;

constraints.insets = new Insets(10, 2, 10, 2);

constraints.weightx = 100;

constraints.weighty = 100;

constraints.gridx = col;

constraints.gridy = row;

constraints.gridwidth = width;

constraints.gridheight = height;

layout.setConstraints(component, constraints);

if (component instanceof JButton)

((JButton)component).addActionListener(this);

getContentPane().add(component);

}

// 主方法初始化并显示窗口

public static void main(String[] args)

{

Calculator calc = new Calculator();

calc.setSize(290, 400);

calc.setVisible(true);

}

}

java:编写一个计算器小程序,要求可以做加减乘除运算

kankan我的

import java.awt.BorderLayout;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.math.BigDecimal;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class TestCalc implements ActionListener {

JFrame jf = new JFrame("计算器");

JPanel jp = new JPanel();

JTextField jtf = new JTextField("0.", 200);

JButton[] jb = new JButton[20];

private int tag = 0;

private double a;

private double b;

private String operator;

StringBuilder sb1 = new StringBuilder();

StringBuilder sb2 = new StringBuilder();

public TestCalc() {

jf.add(jtf, BorderLayout.NORTH);

// jtf.requestFocus();

jtf.setEditable(false);

jtf.setCaretPosition(jtf.getText().length() - 1);

jf.add(jp);

jp.setLayout(new GridLayout(5, 4, 4, 4));

String[] str = { "Back", "CE", "C", "+", "7", "8", "9", "-", "4", "5",

"6", "*", "1", "2", "3", "/", "0", "+/-", ".", "=" };

int i = 0;

for (i = 0; i < str.length; i++) {

jb[i] = new JButton(str[i]);

jp.add(jb[i]);

jb[i].addActionListener(this);

}

jf.setSize(300, 240);

// jf.setLocation(300,200);

jf.setLocationRelativeTo(null);

jf.setVisible(true);

// jf.pack();//自动调整大小;

jf.setResizable(false);// 不允许别人调大小;

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

TestCalc tc = new TestCalc();

}

public void actionPerformed(ActionEvent e) {

String command = e.getActionCommand();

if (command.matches("^[[0-9].]$")) {

if (tag == 0) {

sb1.append(command);

jtf.setText(sb1.substring(0));

} else {

sb2.append(command);

jtf.setText(sb2.substring(0));

}

} else if (command.matches("^[-/*+]$")) {

tag = 1;

operator = command;

} else {

if (command.matches("=")) {

String str1 = sb1.substring(0);

String str2 = sb2.substring(0);

if (str1 == null) {

a = 0.0;

} else {

a = Double.parseDouble(str1);

}

if (str2 == null) {

b = 0.0;

} else {

b = Double.parseDouble(str2);

}

if (operator.equals("+")) {

jtf.setText("" + (a + b));

} else if (operator.equals("-")) {

BigDecimal bd1 = new BigDecimal(Double.toString(a)); // 必须使用String做参数才可以精62616964757a686964616fe59b9ee7ad9431333264643163确运算

BigDecimal bd2 = new BigDecimal(Double.toString(b));

Double yu1 = bd1.subtract(bd2).doubleValue();

jtf.setText("" + (yu1));

} else if (operator.equals("*")) {

jtf.setText("" + (a * b));

} else if (operator.equals("/")) {

BigDecimal bd1 = new BigDecimal(Double.toString(a)); // 必须使用String做参数才可以精确运算

BigDecimal bd2 = new BigDecimal(Double.toString(b));

Double yu1 = bd1.divide(bd2).doubleValue();

jtf.setText("" + yu1);

}

tag = 0;

sb1.delete(0, sb1.length());

sb2.delete(0, sb2.length());

} else if (command.matches("C")) {

tag = 0;

sb1.delete(0, sb1.length());

sb2.delete(0, sb2.length());

jtf.setText("0.");

jtf.setCaretPosition(jtf.getText().length() - 1);

} else if (command.matches("CE")) {

tag = 0;

sb2.delete(0, sb2.length());

jtf.setText(sb1.substring(0));

} else if (command.matches("Back")) {//Back功能键的实现;

if (tag == 0) {

sb1.deleteCharAt(sb1.length() - 1);

jtf.setText(sb1.substring(0));

} else {

sb2.deleteCharAt(sb2.length() - 1);

jtf.setText(sb2.substring(0));

}

} else if (command.matches("\\+/-")) {

if (tag == 0) {

if(sb1.substring(0,1).equals("-")){

sb1.replace(0,1,"+");

}else{

sb1.insert(0, "-");

}

jtf.setText(sb1.substring(0));

} else {

if(sb2.substring(0,1).equals("-")){

sb2.replace(0,1,"+");

}else{

sb2.insert(0, "-");

}

jtf.setText(sb2.substring(0));

}

}else {

}

}

}

}

求用Java 编写的简单计算器...支持加减乘除就可以~ 尽量使代 码简单....谢了~

加减乘除括号都有了,自己改一下就OK

----------------------

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JTextField;

class Stack_Float

{

float nums[];

int top;

Stack_Float()

{

nums = new float[50];

top = -1;

}

boolean IsEmpty()

{

if (top == -1)

return true;

else

return false;

}

float Pop_Stack()

{

if (top == -1)

{

return 0;

}

top--;

return nums[top + 1];

}

float GetTop()

{

return nums[top];

}

void Push_Stack(float num)

{

if (top == 49)

return;

top++;

nums[top] = num;

}

}

class Stack_Char

{

char str[];

int top;

Stack_Char()

{

str = new char[50];

top = -1;

}

boolean CanPush(char c)

{

int temp = top;

if (c == '(')

{

while (temp != -1)

{

if (str[temp] == '(')

{

return false;

}

temp--;

}

}

temp = top;

if (c == '[')

{

while (temp != -1)

{

if (str[temp] == '[' || str[temp] == '(')

{

return false;

}

temp--;

}

}

if (c == '{')

{

while (temp != -1)

{

if (str[temp] == '{' || str[temp] == '[' || str[temp] == '(')

{

return false;

}

temp--;

}

}

return true;

}

boolean IsEmpty()

{

if (top == -1)

return true;

else

return false;

}

void Push_Stack(char ch)

{

if (top == 49)

return;

top++;

str[top] = ch;

}

char Pop_Stack()

{

if (top == -1)

return '\0';

top--;

return str[top + 1];

}

char GetTop()

{

if (top == -1)

{

System.out.print("error");

System.exit(0);

}

return str[top];

}

}

public class jisuanqi extends javax.swing.JFrame implements ActionListener

{

JTextField text = new JTextField();

JTextField text1 = new JTextField();

JButton jButton1 = new JButton();

JButton jButton2 = new JButton();

JButton jButton3 = new JButton();

JButton jButton4 = new JButton();

JButton jButton5 = new JButton();

JButton jButton6 = new JButton();

JButton jButton7 = new JButton();

JButton jButton8 = new JButton();

JButton jButton9 = new JButton();

JButton jButton10 = new JButton();

JButton jButton11 = new JButton();

JButton jButton12 = new JButton();

JButton jButton13 = new JButton();

JButton jButton14 = new JButton();

JButton jButton15 = new JButton();

JButton jButton16 = new JButton();

JButton jButton17 = new JButton();

JButton jButton18 = new JButton();

JButton jButton19 = new JButton();

JButton jButton20 = new JButton();

JButton jButton21 = new JButton();

JButton jButton22 = new JButton();

String show = "";

public jisuanqi()

{

initComponents();

}

char[] TranSmit(char str[])

{

char houzhui[] = new char[50]; // 存放后缀表达式的字符串

int i = 0, j = 0;

char c = str[i];

Stack_Char s = new Stack_Char(); // 存放运算符的栈

while (c != '=') // 对算术表达式扫描未结束时

{

if (c >= '0' && c <= '9')

{

while (c >= '0' && c <= '9')// 数字直接入栈

{

houzhui[j] = c;

j++;

i++;

c = str[i];

}

houzhui[j] = '#';// 用#隔开数字

j++;

}

switch (c) // 扫描到运算符时

{

case '+':

case '-':

case '*':

case '/':

case '(':

case '[':

case '{':

if (s.IsEmpty() == true) // 栈空,直接入栈

{

s.Push_Stack(c);

i++;

c = str[i];

break;

}

if (ComPare(s.GetTop(), c) == -1) {

s.Push_Stack(c); // 入栈

i++;

c = str[i];

break;

}

if (ComPare(s.GetTop(), c) == 1) {

houzhui[j] = s.Pop_Stack();// 出栈元素存入后缀表达式

j++;

break;

}

case ')': // 扫描到 )

while (s.GetTop() != '(') // 未扫描到 ( 时,出栈

{

houzhui[j] = s.Pop_Stack();

j++;

}

s.Pop_Stack(); // '(' 出栈

i++;

c = str[i];

break;

case ']': // 扫描到 ]

while (s.GetTop() != '[') // 未扫描到 [ 时,出栈

{

houzhui[j] = s.Pop_Stack();

j++;

}

s.Pop_Stack(); // '[' 出栈

i++;

c = str[i];

break;

case '}': // 扫描到 }

while (s.GetTop() != '{') // 未扫描到 { 时,出栈

{

houzhui[j] = s.Pop_Stack();

j++;

}

s.Pop_Stack(); // '{' 出栈

i++;

c = str[i];

break;

}

}

while (s.IsEmpty() != true)// 把剩余的运算符直接出栈

{

houzhui[j] = s.Pop_Stack();

j++;

}

houzhui[j] = '=';// 后缀表达式后面加 =

j++;

houzhui[j] = '\0';

j++;

return houzhui;

}

float Count(char str[])

{

Stack_Float s = new Stack_Float();// 定义存放数字的栈

char c = str[0];

int i = 0;

float result = 0, temp, left, right;

while (c != '=') // 未扫描到 = 时

{

if (c >= '0' && c <= '9')// 扫描到数字

{

temp = 0;

while (c != '#')// 未读到分隔符时

{

temp = temp * 10 + c - '0';

i++;

c = str[i];

}

s.Push_Stack(temp);// 进栈

}

switch (c)// 扫描到运算符时

{

case '+':

{

result = s.Pop_Stack() + s.Pop_Stack();// 2个数字出栈相加

s.Push_Stack(result);// 最后得数进栈

break;

}

case '-':

{

right = s.Pop_Stack();// 右操作数出栈

left = s.Pop_Stack();// 左操作数出栈

result = left - right;

s.Push_Stack(result);

break;

}

case '*':

{

result = s.Pop_Stack() * s.Pop_Stack();// 2个数字出栈相乘

s.Push_Stack(result);

break;

}

case '/':

{

right = s.Pop_Stack();// 右操作数出栈

left = s.Pop_Stack();// 左操作数出栈

result = left / right;

s.Push_Stack(result);

break;

}

}

i++;

c = str[i];

}

return result;

}

int ComPare(char a, char b) // 判断运算符的优先级函数

{

int s[][] = {// 栈顶元素高于算术表达式中的元素时, 返回 1,否则返回 -1

{ 1, 1, -1, -1, -1, 1, -1, 1, -1, 1 },

{ 1, 1, -1, -1, -1, 1, -1, 1, -1, 1 },

{ 1, 1, 1, 1, -1, 1, -1, 1, -1, 1 },

{ 1, 1, 1, 1, -1, 1, -1, 1, -1, 1 },

{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },

{ 1, 1, 1, 1, -1, 1, -1, -1, -1, -1 },

{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },

{ 1, 1, 1, 1, -1, -1, -1, -1, -1, 1 },

{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },

{ 1, 1, 1, 1, -1, -1, -1, -1, -1, -1 } };

char x1[] = { '+', '-', '*', '/', '(', ')', '[', ']', '{', '}' };// 栈顶元素

char x2[] = { '+', '-', '*', '/', '(', ')', '[', ']', '{', '}' };// 算术表达式中的元素

int k = 0, m, n = 0;

for (m = 0; m < 10; m++) // 查找2个进行比较的运算符在表中的位置,并返回比较结果

{

for (n = 0; n < 10; n++)

{

if (x1[m] == a && x2[n] == b)

{

k = 1;

break; // 找到比较结果后,跳出循环

}

}

if (k == 1)

break;

}

return s[m][n];// 返回比较结果

}

public void actionPerformed(ActionEvent e)

{

if (e.getSource() == jButton1)

{

show += "1";

text.setText(show);

}

if (e.getSource() == jButton2)

{

show += "2";

text.setText(show);

}

if (e.getSource() == jButton3)

{

show += "3";

text.setText(show);

}

if (e.getSource() == jButton4)

{

show += "4";

text.setText(show);

}

if (e.getSource() == jButton5)

{

show += "5";

text.setText(show);

}

if (e.getSource() == jButton6)

{

show += "6";

text.setText(show);

}

if (e.getSource() == jButton7)

{

show += "7";

text.setText(show);

}

if (e.getSource() == jButton8)

{

show += "8";

text.setText(show);

}

if (e.getSource() == jButton9)

{

show += "9";

text.setText(show);

}

if (e.getSource() == jButton10)

{

show += "0";

text.setText(show);

}

if (e.getSource() == jButton11)

{

show += "+";

text.setText(show);

}

if (e.getSource() == jButton12)

{

show += "-";

text.setText(show);

}

if (e.getSource() == jButton13)

{

show += "*";

text.setText(show);

}

if (e.getSource() == jButton14)

{

show += "/";

text.setText(show);

}

if (e.getSource() == jButton15)

{

show += "(";

text.setText(show);

}

if (e.getSource() == jButton16)

{

show += ")";

text.setText(show);

}

if (e.getSource() == jButton17)

{

show += "[";

text.setText(show);

}

if (e.getSource() == jButton18)

{

show += "]";

text.setText(show);

}

if (e.getSource() == jButton19)

{

show += "{";

text.setText(show);

}

if (e.getSource() == jButton20)

{

show += "}";

text.setText(show);

}

if (e.getSource() == jButton21)

{

show = "";

text.setText("");

text1.setText("");

}

if (e.getSource() == jButton22)

{

show += "=";

text.setText(show);

char str1[] = new char[50];

char str2[] = new char[50];

float result = 0;

str1 = show.toCharArray();

str2 = TranSmit(str1);

result = Count(str2);

text1.setText((new String(str2)).trim());

text.setText("" + result);

show = "";

}

}

private void initComponents()

{

text.setBounds(10, 10, 270, 30);

text1.setBounds(10, 50, 270, 30);

jButton1.setBounds(10, 90, 60, 25);

jButton2.setBounds(80, 90, 60, 25);

jButton3.setBounds(150, 90, 60, 25);

jButton4.setBounds(220, 90, 60, 25);

jButton5.setBounds(10, 120, 60, 25);

jButton6.setBounds(80, 120, 60, 25);

jButton7.setBounds(150, 120, 60, 25);

jButton8.setBounds(220, 120, 60, 25);

jButton9.setBounds(10, 150, 60, 25);

jButton10.setBounds(80, 150, 60, 25);

jButton11.setBounds(150, 150, 60, 25);

jButton12.setBounds(220, 150, 60, 25);

jButton13.setBounds(10, 180, 60, 25);

jButton14.setBounds(80, 180, 60, 25);

jButton15.setBounds(150, 180, 60, 25);

jButton16.setBounds(220, 180, 60, 25);

jButton17.setBounds(150, 210, 60, 25);

jButton18.setBounds(220, 210, 60, 25);

jButton19.setBounds(10, 210, 60, 25);

jButton20.setBounds(80, 210, 60, 25);

jButton21.setBounds(10, 240, 60, 25);

jButton22.setBounds(80, 240, 60, 25);

jButton1.setText("1");

jButton2.setText("2");

jButton3.setText("3");

jButton4.setText("4");

jButton5.setText("5");

jButton6.setText("6");

jButton7.setText("7");

jButton8.setText("8");

jButton9.setText("9");

jButton10.setText("0");

jButton11.setText("+");

jButton12.setText("-");

jButton13.setText("*");

jButton14.setText("/");

jButton15.setText("(");

jButton16.setText(")");

jButton17.setText("[");

jButton18.setText("]");

jButton19.setText("{");

jButton20.setText("}");

jButton21.setText("CE");

jButton22.setText("=");

jButton1.addActionListener(this);

jButton2.addActionListener(this);

jButton3.addActionListener(this);

jButton4.addActionListener(this);

jButton5.addActionListener(this);

jButton6.addActionListener(this);

jButton7.addActionListener(this);

jButton8.addActionListener(this);

jButton9.addActionListener(this);

jButton10.addActionListener(this);

jButton11.addActionListener(this);

jButton12.addActionListener(this);

jButton13.addActionListener(this);

jButton14.addActionListener(this);

jButton15.addActionListener(this);

jButton16.addActionListener(this);

jButton17.addActionListener(this);

jButton18.addActionListener(this);

jButton19.addActionListener(this);

jButton20.addActionListener(this);

jButton21.addActionListener(this);

jButton22.addActionListener(this);

add(text);

add(text1);

add(jButton1);

add(jButton2);

add(jButton3);

add(jButton4);

add(jButton5);

add(jButton6);

add(jButton7);

add(jButton8);

add(jButton9);

add(jButton10);

add(jButton11);

add(jButton12);

add(jButton13);

add(jButton14);

add(jButton15);

add(jButton16);

add(jButton17);

add(jButton18);

add(jButton19);

add(jButton20);

add(jButton21);

add(jButton22);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLayout(null);

setBounds(300, 300, 300, 300);

setVisible(true);

}

public static void main(String args[])

{

new jisuanqi();

}

}