java計算器代碼 java計算器代碼算法

用JAVA編寫的科學(xué)計算器源代碼

import java.awt.*;

銀川網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)公司!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、自適應(yīng)網(wǎng)站建設(shè)等網(wǎng)站項目制作,到程序開發(fā),運營維護(hù)。創(chuàng)新互聯(lián)公司公司2013年成立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)公司

import javax.swing.*;

import java.awt.event.*;

class Counter extends WindowAdapter

{

static JFrame f=new JFrame("計算器");

static JTextField text1=new JTextField("0.");

static String source="";

static String cal="";

static String object="";

static boolean flag=false;

static boolean flag1=true;

static boolean flag2=false;

public void init()

{

try

{

Container c=f.getContentPane();

JPanel pan1=new JPanel();

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 b0=new JButton("0");

JButton b11=new JButton("+");

JButton b12=new JButton("-");

JButton b13=new JButton("*");

JButton b14=new JButton("/");

JButton b15=new JButton(".");

JButton b16=new JButton("=");

JButton bclar=new JButton("清零");

text1.setHorizontalAlignment(JTextField.RIGHT);

c.add(text1,"North");

c.add(pan1);

A aa=new A();

Result re=new Result();

Opertion op=new Opertion();

Clar cl=new Clar();

b1.addActionListener(aa);

b2.addActionListener(aa);

b3.addActionListener(aa);

b4.addActionListener(aa);

b5.addActionListener(aa);

b6.addActionListener(aa);

b7.addActionListener(aa);

b8.addActionListener(aa);

b9.addActionListener(aa);

b0.addActionListener(aa);

b11.addActionListener(op);

b12.addActionListener(op);

b13.addActionListener(op);

b14.addActionListener(op);

b16.addActionListener(re);

b15.addActionListener(aa);

bclar.addActionListener(cl);

pan1.add(b1);

pan1.add(b2);

pan1.add(b3);

pan1.add(b11);

pan1.add(b4);

pan1.add(b5);

pan1.add(b6);

pan1.add(b12);

pan1.add(b7);

pan1.add(b8);

pan1.add(b9);

pan1.add(b13);

pan1.add(b0);

pan1.add(b15);

pan1.add(b16);

pan1.add(b14);

pan1.add(bclar);

f.setSize(200,220);

f.setVisible(true);

}

catch(Exception e)

{

System.out.println(e.getMessage());

}

}

class A implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

String a=text1.getText();

String s=e.getActionCommand();

if(a.equals("0.")||a.equals("+")||a.equals("-")||a.equals("*")||a.equals("/"))

text1.setText(s);

else {

if(flag2)

{

text1.setText(s);

flag2=false;

}

else

text1.setText(a+s);

}

}

}

class Opertion implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

cal=e.getActionCommand();

if(flag1==true)

source=text1.getText();

text1.setText(cal);

flag1=false;

flag=true;

}

}

class Result implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

double num1;

num1=Double.parseDouble(source);

object=text1.getText();

double num2;

num2=Double.parseDouble(object);

double result=0;

if(cal.equals("+"))

result=num1+num2;

if(cal.equals("-"))

result=num1-num2;

if(cal.equals("*"))

result=num1*num2;

if(cal.equals("/"))

if(num2==0)

text1.setText("除數(shù)不能為0");

else

result=num1/num2;

String s1=Double.toString(result);

text1.setText(s1);

flag1=true;

flag2=true;

}

}

class Clar implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

text1.setText("0.");

}

}

public static void main(String[] args)

{

Counter count=new Counter();

count.init();

}

public void windowClosing(WindowEvent e){

System.exit(1);

}

public void windowOpened(WindowEvent e){}

public void windowIconified(WindowEvent e){}

public void windowDeiconified(WindowEvent e){}

public void windowClosed(WindowEvent e){}

public void windowActivated(WindowEvent e){}

public void windowDeactivated(WindowEvent e){}

}

java 計算器代碼帶括號 求注釋

//引入各種類文件

import?java.awt.Button;

import?java.awt.Color;

import?java.awt.FlowLayout;

import?java.awt.Font;

import?java.awt.Frame;

import?java.awt.GridLayout;

import?java.awt.Panel;

import?java.awt.TextField;

import?java.awt.event.ActionEvent;

import?java.awt.event.ActionListener;

//定義JsqFrame繼承Frame

class?JsqFrame?extends?Frame?{

double?d1,?d2;??//定義兩個double類型的變量

int?op?=?-1;??//定義兩個int類型的變量

static?TextField?tf;//定義靜態(tài)對象TextField

CalPanelL?p1;??//定義CalPanelL對象

//?Constructor構(gòu)造方法

JsqFrame()?{

//以下設(shè)置屬性

super("計算器");

setLayout(new?FlowLayout());

setResizable(false);

setSize(250,?250);

tf?=?new?TextField(18);

tf.setEditable(false);

tf.setBackground(Color.lightGray);

tf.setForeground(Color.red);

tf.setFont(new?Font("Arial",?Font.BOLD,?16));

add(tf);

p1?=?new?CalPanelL();

add(p1);

setVisible(true);

//?addWindowListener(new?Wclose());

}

//添加按鈕繼承Button類

class?CalButton?extends?Button?{

CalButton(String?s)?{

//設(shè)置按鈕屬性

super(s);

setBackground(Color.WHITE);?//設(shè)置顏色為白色

}

}

//定義顯示器繼承Panel類

class?CalPanelL?extends?Panel?{

CalButton?a,?c,?b0,?b1,?b2,?b3,?b4,?b5,?b6,?b7,?b8,?b9,?bPN,?bPoint,

bAdd,?bSub,?bMul,?bDiv,?bL,?bR,?bLn,?bEqual,?bCE,?bQuit;

CalPanelL()?{

//設(shè)置顯示器的屬性

setLayout(new?GridLayout(6,?4));

setFont(new?Font("TimesRoman",?Font.BOLD,?16));

a?=?new?CalButton("");

c?=?new?CalButton("");

b0?=?new?CalButton("0");

b1?=?new?CalButton("1");

b2?=?new?CalButton("2");

b3?=?new?CalButton("3");

b4?=?new?CalButton("4");

b5?=?new?CalButton("5");

b6?=?new?CalButton("6");

b7?=?new?CalButton("7");

b8?=?new?CalButton("8");

b9?=?new?CalButton("9");

bPN?=?new?CalButton("+/-");

bPoint?=?new?CalButton(".");

//?設(shè)置按鈕

bAdd?=?new?CalButton("+");

bSub?=?new?CalButton("-");

bMul?=?new?CalButton("*");

bDiv?=?new?CalButton("/");

bL?=?new?CalButton("(");

bR?=?new?CalButton(")");

bLn?=?new?CalButton("ln");

bEqual?=?new?CalButton("=");

bCE?=?new?CalButton("CE");

bQuit?=?new?CalButton("退出");

//?加入按鈕

add(a);

add(c);

add(bCE);

bCE.addActionListener(new?PressBCE());

add(bQuit);

bQuit.addActionListener(new?PressBQuit());

add(b7);

b7.addActionListener(new?PressB7());

add(b8);

b8.addActionListener(new?PressB8());

add(b9);

b9.addActionListener(new?PressB9());

add(bDiv);

bDiv.addActionListener(new?PressBDiv());

add(b4);

b4.addActionListener(new?PressB4());

add(b5);

b5.addActionListener(new?PressB5());

add(b6);

b6.addActionListener(new?PressB6());

add(bMul);

bMul.addActionListener(new?PressBMul());

add(b1);

b1.addActionListener(new?PressB1());

add(b2);

b2.addActionListener(new?PressB2());

add(b3);

b3.addActionListener(new?PressB3());

add(bSub);

bSub.addActionListener(new?PressBSub());

add(b0);

b0.addActionListener(new?PressB0());

add(bPoint);

bPoint.addActionListener(new?PressBPoint());

add(bPN);

bPN.addActionListener(new?PressBPN());

;

add(bAdd);

bAdd.addActionListener(new?PressBAdd());

add(bL);

bL.addActionListener(new?PressBL());

add(bR);

bR.addActionListener(new?PressBR());

add(bLn);

bLn.addActionListener(new?PressBLn());

add(bEqual);

bEqual.addActionListener(new?PressBEqual());

}

}

//定義PressBAdd實現(xiàn)ActionListener

//大體的意思是按計算機按鍵的時出發(fā)的時間,設(shè)置按鍵的監(jiān)聽[加號的監(jiān)聽事件]

class?PressBAdd?implements?ActionListener?{

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

try?{

String?d1?=?tf.getText();

op?=?0;

tf.setText(d1?+?"+");

}?catch?(Exception?ee)?{

}

}

}

//定義PressBSub實現(xiàn)ActionListener

//大體的意思是按計算機按鍵的時出發(fā)的時間,設(shè)置按鍵的監(jiān)聽[減號的監(jiān)聽事件]

class?PressBSub?implements?ActionListener?{

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

try?{

String?d1?=?tf.getText();

op?=?1;

tf.setText(d1?+?"-");

}?catch?(Exception?ee)?{

}

}

}

//定義PressBMul實現(xiàn)ActionListener

//大體的意思是按計算機按鍵的時出發(fā)的時間,設(shè)置按鍵的監(jiān)聽[乘號的監(jiān)聽事件]

class?PressBMul?implements?ActionListener?{

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

try?{

String?d1?=?tf.getText();

op?=?2;

tf.setText(d1?+?"*");

}?catch?(Exception?ee)?{

}

}

}

//定義PressBDiv實現(xiàn)ActionListener

//大體的意思是按計算機按鍵的時出發(fā)的時間,設(shè)置按鍵的監(jiān)聽[除號的監(jiān)聽事件]

class?PressBDiv?implements?ActionListener?{

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

try?{

String?d1?=?tf.getText();

op?=?3;

tf.setText(d1?+?"/");

}?catch?(Exception?ee)?{

}

}

}

//定義PressBL實現(xiàn)ActionListener

//大體的意思是按計算機按鍵的時出發(fā)的時間,設(shè)置按鍵的監(jiān)聽[向左鍵的監(jiān)聽事件]

class?PressBL?implements?ActionListener?{

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

try?{

String?d1?=?tf.getText();

op?=?3;

tf.setText(d1?+?"(");

}?catch?(Exception?ee)?{

}

}

}

//定義PressBR實現(xiàn)ActionListener

//大體的意思是按計算機按鍵的時出發(fā)的時間,設(shè)置按鍵的監(jiān)聽[向右鍵的監(jiān)聽事件]

class?PressBR?implements?ActionListener?{

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

try?{

String?d1?=?tf.getText();

op?=?3;

tf.setText(d1?+?")");

}?catch?(Exception?ee)?{

}

}

}

//定義PressBEqual實現(xiàn)ActionListener

//大體的意思是按計算機按鍵的時出發(fā)的時間,設(shè)置按鍵的監(jiān)聽[等號的監(jiān)聽事件]

class?PressBEqual?implements?ActionListener?{

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

try?{

Jsq?jsq?=?new?Jsq();

String?s?=?tf.getText();

System.out.println(s);

while?(s.indexOf("(")?+?1??0??s.indexOf(")")??0)?{

String?s1?=?jsq.caculateHigh(s);

System.out.println(s1);

s?=?s1;

}

String?str?=?jsq.cacluteMain(s);

System.out.println(str);

tf.setText(String.valueOf(str));

}?catch?(Exception?ee)?{

}

}

}

/*

*?批量寫吧

*?以下是按1、2、3等等的監(jiān)聽事件

*?還有清零的等等監(jiān)聽事件

*/

class?PressBLn?implements?ActionListener?{

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

try?{

double?x?=?Double.parseDouble(tf.getText());

double?y;

y?=?Math.log10(x);

tf.setText(y?+?"");

}?catch?(Exception?ee)?{

}

}

}

class?PressBCE?implements?ActionListener?{

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

tf.setText("");

}

}

class?PressBPN?implements?ActionListener?{

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

try?{

String?text?=?tf.getText();

if?(text?!=?"")?{

if?(text.charAt(0)?==?'-')

tf.setText(text.substring(1));

else?if?(text.charAt(0)?=?'0'??text.charAt(0)?=?'9')

tf.setText("-"?+?text.substring(0));

else?if?(text.charAt(0)?==?'.')

tf.setText("-0"?+?text.substring(0));

}

}?catch?(Exception?ee)?{

}

}

}

class?PressBPoint?implements?ActionListener?{

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

String?text?=?tf.getText();

if?(text.lastIndexOf(".")?==?-1)

tf.setText(text?+?".");

}

}

class?PressB0?implements?ActionListener?{

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

String?text?=?tf.getText();

tf.setText(text?+?"0");

}

}

class?PressB1?implements?ActionListener?{

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

String?text?=?tf.getText();

tf.setText(text?+?"1");

}

}

class?PressB2?implements?ActionListener?{

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

String?text?=?tf.getText();

tf.setText(text?+?"2");

}

}

class?PressB3?implements?ActionListener?{

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

String?text?=?tf.getText();

tf.setText(text?+?"3");

}

}

class?PressB4?implements?ActionListener?{

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

String?text?=?tf.getText();

tf.setText(text?+?"4");

}

}

class?PressB5?implements?ActionListener?{

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

String?text?=?tf.getText();

tf.setText(text?+?"5");

}

}

class?PressB6?implements?ActionListener?{

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

String?text?=?tf.getText();

tf.setText(text?+?"6");

}

}

class?PressB7?implements?ActionListener?{

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

String?text?=?tf.getText();

tf.setText(text?+?"7");

}

}

class?PressB8?implements?ActionListener?{

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

String?text?=?tf.getText();

tf.setText(text?+?"8");

}

}

class?PressB9?implements?ActionListener?{

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

String?text?=?tf.getText();

tf.setText(text?+?"9");

}

}

class?PressBQuit?implements?ActionListener?{

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

System.exit(0);

}

}

public?void?Js()?{

String?text?=?tf.getText();

tf.setText(text);

}

}

計算器java代碼

import java.awt.Color;

import java.awt.Font;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.WindowConstants;

import javax.swing.border.LineBorder;

class Normal{

double i,j;

public Normal(double num1,double num2){

i=num1;

j=num2;

}

public double puls(){

return i+j;

}

public double subtract(){

return i-j;

}

public double multiply(){

return i*j;

}

public double divide(){

return i/j;

}

public double surpuls(){

return i%j;

}

}

class scientific extends Normal{

public scientific(int num1, int num2) {

super(num1, num2);

}

}

public class calc extends JFrame{

public static void main(String[] args) {

viewNormal VN= new viewNormal("normal");

}

}

class viewNormal extends JFrame implements ActionListener{

JPanel jp1 = new JPanel(new GridLayout(4,3,5,5));

JPanel jp2 = new JPanel(new GridLayout(5,1,5,5));

JLabel jl;

JButton[] jb;

JButton jbs,jbo,jba,jbb,jbc,jby;

StringBuffer sb = new StringBuffer();

Normal normal;

int dot=0;

double fnum=0;

double lnum=0;

double result;

String sign=null;

public viewNormal(String title){

setTitle(title);

setLayout(null);

setVisible(true);

setBounds(200,200,305,350);

setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

jb= new JButton[12];

for(int i=0;i9;i++){

jb[i]=new JButton(""+(i+1));

jp1.add(jb[i]);

jb[i].addActionListener(this);

}

jb[9]=new JButton(".");

jb[10]=new JButton("0");

jb[11]=new JButton("=");

jb[9].addActionListener(this);

jb[10].addActionListener(this);

jb[11].addActionListener(this);

jp1.add(jb[9]);

jp1.add(jb[10]);

jp1.add(jb[11]);

jp1.setBounds(10, 100, 200, 200);

jbs= new JButton("+");jbo= new JButton("-");jba= new JButton("*");

jbb= new JButton("/");jby= new JButton("%");jbc= new JButton("C");

jbs.addActionListener(this);jbo.addActionListener(this);jba.addActionListener(this);

jbb.addActionListener(this);jby.addActionListener(this);jbc.addActionListener(this);

//jp2.add(jby);

jp2.add(jbs);jp2.add(jbo);jp2.add(jba);jp2.add(jbb);jp2.add(jbc);

jp2.setBounds(215, 100, 70, 200);

jl= new JLabel("0",JLabel.RIGHT);

jl.setFont(new Font("Batang",Font.BOLD, 20));

jl.setBorder(new LineBorder(Color.black,2));

jl.setBackground(Color.white);

jl.setBounds(10, 40, 275, 50);

jl.setOpaque(true);

add(jl);

add(jp1);

add(jp2);

}

//+

public void sum(){

lnum=Double.parseDouble(sb.toString());

normal=new Normal(fnum,lnum);

fnum=normal.puls();

result=fnum;

}

//-

private void sub() {

System.out.println(sb.toString());

lnum=Double.parseDouble(sb.toString());

normal=new Normal(fnum,lnum);

fnum=normal.subtract();

result=fnum;

}

//*

private void mul() {

lnum=Double.parseDouble(sb.toString());

normal=new Normal(fnum,lnum);

fnum=normal.multiply();

result=fnum;

}

// /

private void div() {

lnum=Double.parseDouble(sb.toString());

normal=new Normal(fnum,lnum);

fnum=normal.divide();

result=fnum;

}

//%

private void sur() {

lnum=Double.parseDouble(sb.toString());

normal=new Normal(fnum,lnum);

fnum=normal.surpuls();

result=fnum;

}

// =

private void same(){

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

sum();

}

if(sign.equals("-")){

sub();

}

if(sign.equals("*")){

mul();

}

if(sign.equals("/")){

div();

}

if(sign.equals("%")){

sur();

}

}

//result

public void Result(){

if(result%1!=0)

jl.setText(""+result);

else

{

int i=(int)result;

jl.setText(""+i);

}

}

@Override

public void actionPerformed(ActionEvent e) {

//System.out.println(sb.toString());

// 1~9

for(int i=0;i9;i++){

if(e.getSource()==jb[i]!sb.toString().equals("0")){

sb.append(jb[i].getText());

jl.setText(sb.toString());

}

else if(e.getSource()==jb[i]sb.toString().equals("0")){

int d=sb.length();

sb.delete(0, d);

sb.append(jb[i].getText());

jl.setText(sb.toString());

}

}

// 0

if(e.getSource()==jb[10]!sb.toString().equals("0")){

sb.append(jb[10].getText());

jl.setText(sb.toString());

}

// .

if(e.getSource()==jb[9]dot==0!sb.toString().equals("")){

dot++;

sb.append(jb[9].getText());

jl.setText(sb.toString());

}

// =

if(e.getSource()==jb[11]!sb.toString().equals("")){

same();

Result();

int d=sb.length();

sb.delete(0, d);

dot=0;

}

// +

if(e.getSource()==jbs!sb.toString().equals("")){

if(sign!="+"sign!=null)

same();

else

sum();

sign ="+";

Result();

int d=sb.length();

sb.delete(0, d);

dot=0;

}

//-

if(e.getSource()==jbo!sb.toString().equals("")){

if(fnum==0)

fnum=2*Double.parseDouble(sb.toString());

if(sign!="-"sign!=null)

same();

else

sub();

sign ="-";

Result();

int d=sb.length();

sb.delete(0, d);

dot=0;

}

//*

if(e.getSource()==jba!sb.toString().equals("")){

if(fnum==0)

fnum=1;

if(sign!="*"sign!=null)

same();

else

mul();

sign ="*";

Result();

int d=sb.length();

sb.delete(0, d);

dot=0;

}

// /

if(e.getSource()==jbb!sb.toString().equals("")){

if(fnum==0)

fnum=Math.pow(Double.parseDouble(sb.toString()),2);

if(sign!="/"sign!=null)

same();

else

div();

sign ="/";

Result();

int d=sb.length();

sb.delete(0, d);

dot=0;

}

//%

// if(e.getSource()==jby!sb.toString().equals("")){

// if(fnum==0){

// fnum=Double.parseDouble(sb.toString());

// result=fnum;

// }

// else {

// if(sign!="%"sign!=null)

// same();

// else{

// lnum=Double.parseDouble(sb.toString());

// normal=new Normal(fnum,lnum);

// fnum=normal.surpuls();

// result=fnum;

// }

// }

// sign ="%";

// Result();

// int d=sb.length();

// sb.delete(0, d);

// dot=0;

// }

//clear

if(e.getSource()==jbc){

int d=sb.length();

sb.delete(0, d);

jl.setText("0");

dot=0;

fnum=0;

lnum=0;

sign=null;

}

}

}

class viewScientific extends viewNormal{

public viewScientific(String title){

super(title);

setBounds(200,200,800,500);

}

}

//等號以后輸入符號用不了, String轉(zhuǎn) double 本來就有錯誤,你可以用我的擴展成科學(xué)型的。

如何用JAVA語言編寫計算器小程序?

具體代碼如下:

import javax.swing.*;

import java.awt.event.*;

import java.awt.*;

public class Calculator ?extends JFrame implements ActionListener ?{

private JFrame jf;

private JButton[] allButtons;

private JButton clearButton;

private JTextField jtf;

public Calculator() {

//對圖形組件實例化

jf=new JFrame("任靜的計算器1.0:JAVA版");

jf.addWindowListener(new WindowAdapter(){

public void windowClosing(){

System.exit(0);

}

});

allButtons=new JButton[16];

clearButton=new JButton("清除");

jtf=new JTextField(25);

jtf.setEditable(false);

String str="123+456-789*0.=/";

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

allButtons[i]=new JButton(str.substring(i,i+1));

}

}

public void init(){

//完成布局

jf.setLayout(new BorderLayout());

JPanel northPanel=new JPanel();

JPanel centerPanel=new JPanel();

JPanel southPanel=new JPanel();

northPanel.setLayout(new FlowLayout());

centerPanel.setLayout(new GridLayout(4,4));

southPanel.setLayout(new FlowLayout());

northPanel.add(jtf);

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

centerPanel.add(allButtons[i]);

}

southPanel.add(clearButton);

jf.add(northPanel,BorderLayout.NORTH);

jf.add(centerPanel,BorderLayout.CENTER);

jf.add(southPanel,BorderLayout.SOUTH);

addEventHandler();

}

//添加事件監(jiān)聽

public void addEventHandler(){

jtf.addActionListener(this);

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

allButtons[i].addActionListener(this);

}

clearButton.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

Calculator.this.jtf.setText("");

}

});

}

//事件處理

public void actionPerformed(ActionEvent e) {

//在這里完成事件處理 ?使計算器可以運行

String action=e.getActionCommand();

if(action=="+"||action=="-"||action=="*"||action=="/"){

}

}

public void setFontAndColor(){

Font f=new Font("宋體",Font.BOLD,24);

jtf.setFont(f);

jtf.setBackground(new Color(0x8f,0xa0,0xfb));

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

allButtons[i].setFont(f);

allButtons[i].setForeground(Color.RED);

}

}

public void showMe(){

init();

setFontAndColor();

jf.pack();

jf.setVisible(true);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args){

new Calculator().showMe();

}

}

本文名稱:java計算器代碼 java計算器代碼算法
網(wǎng)頁鏈接:http://muchs.cn/article36/dohcopg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、、網(wǎng)站內(nèi)鏈網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、ChatGPT

廣告

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

營銷型網(wǎng)站建設(shè)