java計(jì)算代碼 java編寫簡單計(jì)算器代碼

java 計(jì)算器代碼

這個(gè)是最合適你了!

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:國際域名空間、虛擬空間、營銷軟件、網(wǎng)站建設(shè)、定海網(wǎng)站維護(hù)、網(wǎng)站推廣。

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Calculator extends JFrame {

private Container container;

private GridBagLayout layout;

private GridBagConstraints constraints;

private JTextField displayField;//計(jì)算結(jié)果顯示區(qū)

private String lastCommand;//保存+,-,*,/,=命令

private double result;//保存計(jì)算結(jié)果

private boolean start;//判斷是否為數(shù)字的開始

public Calculator() {

super("計(jì)算器");

container=getContentPane();

layout=new GridBagLayout();

container.setLayout(layout);

constraints=new GridBagConstraints();

start=true;

result=0;

lastCommand = "=";

displayField=new JTextField(20);

displayField.setText("0.0");

displayField.setcolor(red);

displayField.setHorizontalAlignment(JTextField.RIGHT);

constraints.gridx=0;

constraints.gridy=0;

constraints.gridwidth=4;

constraints.gridheight=1;

constraints.fill=GridBagConstraints.BOTH;

constraints.weightx=100;

constraints.weighty=100;

layout.setConstraints(displayField,constraints);

container.add(displayField);

ActionListener insert = new InsertAction();

ActionListener command = new CommandAction();

addButton("7",0,2,1,1,insert);

addButton("8",1,2,1,1,insert);

addButton("9",2,2,1,1,insert);

addButton("/",3,5,1,1,command);

addButton("4",0,3,1,1,insert);

addButton("5",1,3,1,1,insert);

addButton("6",2,3,1,1,insert);

addButton("*",3,4,1,1,command);

addButton("1",0,4,1,1,insert);

addButton("2",1,4,1,1,insert);

addButton("3",2,4,1,1,insert);

addButton("-",3,3,1,1,command);

addButton("0",1,5,1,1,insert);

addButton("=",2,5,1,1,command);

addButton(".",0,5,1,1,insert);

addButton("+",3,2,1,1,command);

setSize(180,200);

setVisible(true);

}

private void addButton(String label,int row,int column,int with,int height,ActionListener listener) {

JButton button=new JButton(label);

constraints.gridx=row;

constraints.gridy=column;

constraints.gridwidth=with;

constraints.gridheight=height;

constraints.fill=GridBagConstraints.BOTH;

button.addActionListener(listener);

layout.setConstraints(button,constraints);

container.add(button);

}

private class InsertAction implements ActionListener {

public void actionPerformed(ActionEvent event) {

String input=event.getActionCommand();

if (start) {

displayField.setText("");

start=false;

displayField.setText(displayField.getText()+input);

}

}

}

private class CommandAction implements ActionListener {

public void actionPerformed(ActionEvent evt) {

String command=evt.getActionCommand();

if(start) {

lastCommand=command;

}else {

calculate(Double.parseDouble(displayField.getText()));

lastCommand=command;

start=true;

}

}

}

public void calculate(double x) {

if (lastCommand.equals("+")) result+= x;

else if (lastCommand.equals("-")) result-=x;

else if (lastCommand.equals("*")) result*=x;

else if (lastCommand.equals("/")) result/=x;

else if (lastCommand.equals("=")) result=x;

displayField.setText(""+ result);

}

public static void main(String []args) {

Calculator calculator=new Calculator();

calculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

JAVA簡單咋做,計(jì)算器代碼

簡單寫了下,代碼如下請參照:

/**

*?計(jì)算器類

*?

*?@author?Administrator

*

*/

public?class?Calculator?extends?JFrame?implements?ActionListener?{

private?static?final?long?serialVersionUID?=?3868243398506940702L;

//?文本框

private?JTextField?result;

//?按鈕數(shù)組

private?JButton[]?buttons;

//?按鈕文本

private?final?String[]?characters?=?{?"7",?"8",?"9",?"/",?"4",?"5",?"6",

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

//?是否為第一個(gè)輸入的數(shù)字

private?boolean?isFirstDigit?=?true;

//?運(yùn)算結(jié)果

private?double?resultNum?=?0.0;

//?運(yùn)算符

private?String?operator?=?"=";

public?Calculator(String?title)?{

//?設(shè)置標(biāo)題欄

super(title);

//?初始化各組件

init();

//?注冊各組件監(jiān)聽器

registerListener();

//?顯示窗體

setVisible(true);

}

/**

*?初始化各組件

*/

private?void?init()?{

//?常用屬性初始化

setSize(220,?200);

setResizable(false);

setLocationRelativeTo(null);

setDefaultCloseOperation(EXIT_ON_CLOSE);

/*?文本框?qū)ο蟪跏蓟?*/

result?=?new?JTextField("0");

//?文本右對齊

result.setHorizontalAlignment(JTextField.RIGHT);

//?設(shè)置是否可編輯

result.setEditable(false);

/*?按鈕初始化?*/

buttons?=?new?JButton[characters.length];

for?(int?i?=?0;?i??buttons.length;?i++)?{

buttons[i]?=?new?JButton(characters[i]);

buttons[i].setFocusable(false);?//?不允許按鈕定位焦點(diǎn)

}

/*?將文本框與按鈕添加到窗體中?*/

add(result,?BorderLayout.NORTH);

JPanel?pnl?=?new?JPanel(new?GridLayout(4,?4,?5,?5));

for?(JButton?jButton?:?buttons)?{

pnl.add(jButton);

}

add(pnl);

this.getContentPane().setFocusable(true);

}

/**

*?注冊監(jiān)聽器

*/

private?void?registerListener()?{

for?(JButton?jButton?:?buttons)?{

jButton.addActionListener(this);

}

//?注冊鍵盤事件

this.getContentPane().addKeyListener(new?KeyAdapter()?{

@Override

public?void?keyPressed(KeyEvent?e)?{

String?text?=?String.valueOf(e.getKeyChar());

if?(Character.isDigit(text.charAt(0))?||?".".equals(text))?{?//?數(shù)字或小數(shù)點(diǎn)

handleNumber(text);

}?else?if?("+-*/=".indexOf(text)?!=?-1)?{?//?運(yùn)算符

handleOperator(text);

}?else?if?(e.getKeyCode()?==?8)?{?//?退格鍵

String?tmp?=?result.getText().trim();

if?(tmp.length()?==?1)?{

result.setText("0");

isFirstDigit?=?true;

}?else?{

result.setText(tmp.substring(0,?tmp.length()?-?1));

}

}

}

});

}

@Override

public?void?actionPerformed(ActionEvent?e)?{

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

String?text?=?btn.getText().trim();

if?(Character.isDigit(text.charAt(0))?||?".".equals(text))?{?//?處理數(shù)字和小數(shù)點(diǎn)

handleNumber(text);

}?else?{?//?處理運(yùn)算符

handleOperator(text);

}

}

/**

*?處理數(shù)字和小數(shù)點(diǎn)

*?

*?@param?text

*/

private?void?handleNumber(String?text)?{

if?(isFirstDigit)?{?//?第一次輸入

if?(".".equals(text))?{

this.result.setText("0.");

}?else?{

this.result.setText(text);

}

}?else?if?("0".equals(text)??"0".equals(this.result.getText()))?{

isFirstDigit?=?true;

return;

}?else?if?(".".equals(text)??this.result.getText().indexOf(".")?==?-1)?{

this.result.setText(this.result.getText()?+?".");

}?else?if?(!".".equals(text))?{

this.result.setText(this.result.getText()?+?text);

}

isFirstDigit?=?false;

}

/**

*?處理運(yùn)算符

*?

*?@param?text

*/

private?void?handleOperator(String?text)?{

switch?(operator)?{?//?處理各項(xiàng)運(yùn)算??適用于JDK1.7版本的

case?"+":

resultNum?+=?Double.parseDouble(this.result.getText());

break;

case?"-":

resultNum?-=?Double.parseDouble(this.result.getText());

break;

case?"*":

resultNum?*=?Double.parseDouble(this.result.getText());

break;

case?"/":

resultNum?/=?Double.parseDouble(this.result.getText());

break;

case?"=":

resultNum?=?Double.parseDouble(this.result.getText());

break;

}

//?將文本框的值修改為運(yùn)算結(jié)果

this.result.setText(String.valueOf(resultNum));

//?將點(diǎn)擊的運(yùn)算符放入operator保存

operator?=?text;

//?下一個(gè)數(shù)字第一次點(diǎn)擊

isFirstDigit?=?true;

}

public?static?void?main(String[]?args)?{

?new?Calculator("My?Calculator");

?}

}

運(yùn)行結(jié)果如下:

java代碼計(jì)算?

經(jīng)過實(shí)際運(yùn)行發(fā)現(xiàn)10和的之間還有一個(gè)空格,這樣長度就是11.如果中間沒有這個(gè)空格的話結(jié)果就是10.其實(shí)重點(diǎn)不在于算不算這個(gè)空格,而在于計(jì)算字符串的長度。

java 兩數(shù)相加 計(jì)算代碼 給個(gè)答案唄

如果是一般的兩個(gè)數(shù)求和,用 long類型 初始化 就可以了~~~

import java.util.Scanner;

public class Demo1 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("請輸入兩個(gè)數(shù): ");

long n1,n2;

n1 = input.nextLong();

n2 = input.nextLong();

System.out.println("兩個(gè)數(shù)的和是: ");

System.out.println(n1+ n2);

}

}

運(yùn)行結(jié)果:

請輸入兩個(gè)數(shù):

213152454

238547571234

兩個(gè)數(shù)的和是:

238760723688

如果兩個(gè)數(shù)很大,超出了long表示范圍,用大數(shù)BigInteger 初始化 就OK了~~~

import java.math.BigInteger;

import java.util.Scanner;

public class 大數(shù)相加 {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println("請輸入兩個(gè)大數(shù): ");

Scanner input = new Scanner(System.in);

BigInteger b1 = input.nextBigInteger();

BigInteger b2 = input.nextBigInteger();

System.out.println("兩個(gè)大數(shù)的和是: ");

System.out.println(b1.add(b2));

}

}

運(yùn)行結(jié)果:

請輸入兩個(gè)大數(shù):

236547625754751312371

1237527547543547124751254

兩個(gè)大數(shù)的和是:

1237764095169301876063625

望采納~~~~~~~~~~

java編一個(gè)計(jì)算器的代碼

界面漂亮堪比系統(tǒng)自帶計(jì)算器,功能完美加減乘除開平方等等全部具備,還有清零按鈕,小數(shù)點(diǎn)的使用,連加連乘功能完全參考系統(tǒng)官方計(jì)算器經(jīng)過長期調(diào)試改進(jìn)而成,馬上拷貝代碼拿去試試看吧,絕不后悔!

代碼如下:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

public class Counter {

public static void main(String[] args) {

CounterFrame frame = new CounterFrame();

frame.show();

}

}

class CounterFrame extends JFrame {

public CounterFrame() {

JMenuBar menuBar = new JMenuBar();

JMenu menuFile = new JMenu();

JMenu menuFile1 = new JMenu();

JMenu menuFile2 = new JMenu();

JMenu menuFile3 = new JMenu();

JMenuItem menuFileExit = new JMenuItem();

menuFile.setText("文件");

menuFile1.setText("編輯");

menuFile2.setText("查看");

menuFile3.setText("幫助");

menuFileExit.setText("退出");

menuFileExit.addActionListener

(

new ActionListener() {

public void actionPerformed(ActionEvent e) {

CounterFrame.this.windowClosed();

}

}

);

menuFile.add(menuFileExit);

menuBar.add(menuFile);

menuBar.add(menuFile1);

menuBar.add(menuFile2);

menuBar.add(menuFile3);

setTitle("計(jì)算器");

setJMenuBar(menuBar);

setSize(new Dimension(400, 280));

this.getContentPane().add(new Allpanel());

this.addWindowListener

(

new WindowAdapter() {

public void windowClosing(WindowEvent e) {

CounterFrame.this.windowClosed();

}

}

);

}

protected void windowClosed() {

System.exit(0);

}

}

class Tool {

public static Tool instance;

private JTextField field;

private Tool() {

this.field=new JTextField(30);

this.field.setHorizontalAlignment(JTextField.RIGHT);

}

public static Tool getinstance()

{

if(instance==null)

{

instance=new Tool();

}

return instance;

}

public JTextField getfield()

{

return (this.field);

}

}

class Allpanel extends JPanel {

public Allpanel() {

this.setLayout(new BorderLayout(0,7));

Northpanel np=new Northpanel();

Centerpanel cp=new Centerpanel();

this.add(np,BorderLayout.NORTH);

this.add(cp,BorderLayout.CENTER);

}

}

class Centercenter extends JPanel {

static Vector Vec=new Vector();

static Vector vc=new Vector();

static Vector vc1=new Vector();

static Vector vc2=new Vector();

static Vector vc3=new Vector();

static String begin="yes";

static double add;

static double jq;

static double cs;

static double cq;

static double dy;

static String jg;

static String what;

static double tool=0;

static String to="yes";

/**

* Method Centercenter

*

*

*/

public Centercenter() {

// TODO: Add your code here

final JTextField text=Tool.getinstance().getfield();

this.setLayout(new GridLayout(4,5,3,3));

String arg[] ={"7","8","9","/","sqrt","4","5","6","*","%","1","2","3","-","1/x","0","+/-",".","+","="};

for(int i=0;i20;i++)

{

final JButton b=new JButton(arg[i]);

//this.add(new JButton(arg[i]));

this.add(b);

if(i==0||i==1||i==2||i==5||i==6||i==7||i==10||i==11||i==12||i==15)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String mark=b.getText();

String ma=text.getText();

if(vc3.contains("v3"))

{

text.setText("0."+mark);

vc3.clear();

}

else if(vc.contains("a"))

{

if(vc2.contains("v2"))

{

text.setText("0."+mark);

vc.clear();

vc2.clear();

}

else

{

text.setText(mark);

vc.clear();

Vec.clear();

Vec.add(mark);

}

}

else

{

text.setText(ma.trim()+mark);

Vec.add(mark);

}

begin="no";

to="yes";

}

});

}

if(i==17)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String mar=b.getText();

String m=text.getText();

if("yes".equals(begin))

{

vc3.add("v3");

}

if(vc1.contains("v1"))

{

vc2.add("v2");

vc1.clear();

}

if(!Vec.contains(".")!vc.contains("a"))

{

text.setText(m.trim()+mar);

Vec.add(".");

}

}

});

}

if(i==18)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

add=Double.parseDouble(ma);

if(what==null)

{

tool=add;

what="add";

}

else

{

tool=tool+add;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="+";

}

});

}

if(i==13)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

jq=Double.parseDouble(ma);

if(what==null)

{

tool=jq;

what="jq";

}

else

{

tool=tool-jq;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="-";

}

});

}

if(i==3)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cq=Double.parseDouble(ma);

if(what==null)

{

tool=cq;

what="cq";

}

else

{

tool=tool/cq;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="/";

}

});

}

if(i==4)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cq=Double.parseDouble(ma);

text.setText(String.valueOf(Math.sqrt(cq)));

}

});

}

if(i==8)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cs=Double.parseDouble(ma);

if(what==null)

{

tool=cs;

what="cs";

}

else

{

tool=tool*cs;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="*";

}

});

}

if(i==19)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

dy=Double.parseDouble(ma);

if(what=="add")

{

jg=String.valueOf((tool+dy));

}

if(what=="jq")

{

jg=String.valueOf((tool-dy));

}

if(what=="cs")

{

jg=String.valueOf((tool*dy));

}

if(what=="cq")

{

jg=String.valueOf((tool/dy));

}

if(what==null)

{

if(to=="+")

{

tool=add;

jg=String.valueOf(tool+dy);

}

else if(to=="-")

{

tool=jq;

jg=String.valueOf(dy-tool);

}

else if(to=="*")

{

tool=cs;

jg=String.valueOf(dy*tool);

}

else if(to=="/")

{

tool=cq;

jg=String.valueOf(dy/tool);

}

else

{

jg=String.valueOf(dy);

}

}

text.setText(jg);

Vec.clear();

Vec.add(".");

vc.add("a");

vc1.add("v1");

what=null;

tool=0;

}

});

}

}

}

}

class Centernorth extends JPanel {

public Centernorth() {

final JTextField text=Tool.getinstance().getfield();

JButton jb1=new JButton("Backspace");

JButton jb2=new JButton(" CE ");

JButton jb3=new JButton(" C ");

this.add(jb1);

this.add(jb2);

this.add(jb3);

jb1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

String back=Tool.getinstance().getfield().getText();

text.setText(backmethod(back));

Centercenter.Vec.remove(Centercenter.Vec.size()-1);

}

});

jb3.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

text.setText("0.");

Centercenter.Vec.clear();

Centercenter.Vec.add(".");

Centercenter.vc.add("a");

Centercenter.begin="yes";

Centercenter.vc1.clear();

Centercenter.what=null;

Centercenter.tool=0;

}

});

}

public String backmethod(String str)

{

return str.substring(0,str.length()-1);

}

}

class Centerpanel extends JPanel {

public Centerpanel() {

this.setLayout(new BorderLayout(8,7));

Centernorth cn=new Centernorth();

Centercenter cc=new Centercenter();

Centerwest cw=new Centerwest();

this.add(cn,BorderLayout.NORTH);

this.add(cc,BorderLayout.CENTER);

this.add(cw,BorderLayout.WEST);

}

}

class Centerwest extends JPanel {

public Centerwest() {

this.setLayout(new GridLayout(4,1,3,3));

this.add(new JButton("MC"));

this.add(new JButton("MR"));

this.add(new JButton("MS"));

this.add(new JButton("M+"));

}

}

class Northpanel extends JPanel {

private JTextField tf;

public Northpanel() {

tf=Tool.getinstance().getfield();

this.add(tf);

}

}

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

=============《按你要求特意后改過的最簡單功能的代碼如下》========================

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

public class Counter2 {

public static void main(String[] args) {

CounterFrame frame = new CounterFrame();

frame.show();

}

}

class CounterFrame extends JFrame {

public CounterFrame() {

setTitle("計(jì)算器");

setSize(new Dimension(400, 280));

this.getContentPane().add(new Allpanel());

this.addWindowListener

(

new WindowAdapter() {

public void windowClosing(WindowEvent e) {

CounterFrame.this.windowClosed();

}

}

);

}

protected void windowClosed() {

System.exit(0);

}

}

class Tool {

public static Tool instance;

private JTextField field;

private Tool() {

this.field=new JTextField(30);

this.field.setHorizontalAlignment(JTextField.RIGHT);

}

public static Tool getinstance()

{

if(instance==null)

{

instance=new Tool();

}

return instance;

}

public JTextField getfield()

{

return (this.field);

}

}

class Allpanel extends JPanel {

public Allpanel() {

this.setLayout(new BorderLayout(0,7));

Northpanel np=new Northpanel();

Centerpanel cp=new Centerpanel();

this.add(np,BorderLayout.NORTH);

this.add(cp,BorderLayout.CENTER);

}

}

class Centercenter extends JPanel {

static Vector Vec=new Vector();

static Vector vc=new Vector();

static Vector vc1=new Vector();

static Vector vc2=new Vector();

static Vector vc3=new Vector();

static String begin="yes";

static double add;

static double jq;

static double cs;

static double cq;

static double dy;

static String jg;

static String what;

static double tool=0;

static String to="yes";

/**

* Method Centercenter

*

*

*/

public Centercenter() {

// TODO: Add your code here

final JTextField text=Tool.getinstance().getfield();

this.setLayout(new GridLayout(4,5,3,3));

String arg[] ={"7","8","9","/","4","5","6","*","1","2","3","-","0","=",".","+"};

for(int i=0;i16;i++)

{

final JButton b=new JButton(arg[i]);

//this.add(new JButton(arg[i]));

this.add(b);

if(i==0||i==1||i==2||i==4||i==5||i==6||i==8||i==9||i==10||i==12)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String mark=b.getText();

String ma=text.getText();

if(vc3.contains("v3"))

{

text.setText("0."+mark);

vc3.clear();

}

else if(vc.contains("a"))

{

if(vc2.contains("v2"))

{

text.setText("0."+mark);

vc.clear();

vc2.clear();

}

else

{

text.setText(mark);

vc.clear();

Vec.clear();

Vec.add(mark);

}

}

else

{

text.setText(ma.trim()+mark);

Vec.add(mark);

}

begin="no";

to="yes";

}

});

}

if(i==14)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String mar=b.getText();

String m=text.getText();

if("yes".equals(begin))

{

vc3.add("v3");

}

if(vc1.contains("v1"))

{

vc2.add("v2");

vc1.clear();

}

if(!Vec.contains(".")!vc.contains("a"))

{

text.setText(m.trim()+mar);

Vec.add(".");

}

}

});

}

if(i==15)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

add=Double.parseDouble(ma);

if(what==null)

{

tool=add;

what="add";

}

else

{

tool=tool+add;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="+";

}

});

}

if(i==11)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

jq=Double.parseDouble(ma);

if(what==null)

{

tool=jq;

what="jq";

}

else

{

tool=tool-jq;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="-";

}

});

}

if(i==3)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cq=Double.parseDouble(ma);

if(what==null)

{

tool=cq;

what="cq";

}

else

{

tool=tool/cq;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="/";

}

});

}

if(i==7)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

cs=Double.parseDouble(ma);

if(what==null)

{

tool=cs;

what="cs";

}

else

{

tool=tool*cs;

text.setText(String.valueOf((tool)));

}

vc.add("a");

vc1.add("v1");

to="*";

}

});

}

if(i==13)

{

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

String ma=text.getText();

dy=Double.parseDouble(ma);

if(what=="add")

{

jg=String.valueOf((tool+dy));

}

if(what=="jq")

{

jg=String.valueOf((tool-dy));

}

if(what=="cs")

{

jg=String.valueOf((tool*dy));

}

if(what=="cq")

{

jg=String.valueOf((tool/dy));

}

if(what==null)

{

if(to=="+")

{

tool=add;

jg=String.valueOf(tool+dy);

}

else if(to=="-")

{

tool=jq;

jg=String.valueOf(dy-tool);

}

else if(to=="*")

{

tool=cs;

jg=String.valueOf(dy*tool);

}

else if(to=="/")

{

tool=cq;

jg=String.valueOf(dy/tool);

}

else

{

jg=String.valueOf(dy);

}

}

text.setText(jg);

Vec.clear();

Vec.add(".");

vc.add("a");

vc1.add("v1");

what=null;

tool=0;

}

});

}

}

}

}

class Centernorth extends JPanel {

public Centernorth() {

final JTextField text=Tool.getinstance().getfield();

}

}

class Centerpanel extends JPanel {

public Centerpanel() {

this.setLayout(new BorderLayout(8,7));

Centernorth cn=new Centernorth();

Centercenter cc=new Centercenter();

Centerwest cw=new Centerwest();

this.add(cn,BorderLayout.NORTH);

this.add(cc,BorderLayout.CENTER);

this.add(cw,BorderLayout.WEST);

}

}

class Centerwest extends JPanel {

public Centerwest() {

}

}

class Northpanel extends JPanel {

private JTextField tf;

public Northpanel() {

tf=Tool.getinstance().getfield();

this.add(tf);

}

}

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

才子_輝祝您愉快!

網(wǎng)站欄目:java計(jì)算代碼 java編寫簡單計(jì)算器代碼
文章來源:http://muchs.cn/article14/doccgde.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、企業(yè)建站、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站內(nèi)鏈電子商務(wù)、網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管