各位好心人啊,誰能幫我用JAVA語言編個計算器??這周要交的!要簡單易懂!最好加點說明!要分3個panel,第一個包括textfiled ,用flowlayout布局,第二個就是0-9數字,包括小數點,和=號,用gridlayout布局,第三個是 + - * /號,要用gridlayout布局!!謝謝!!幫忙啊!!

熱心網友

哈哈!我們也要交作業阿,老大把分給我吧,我沒分啦!拷貝編譯就行了我上禮拜寫的import t。*;import t。event。*;public class Calculator extends WindowAdapter implements ActionListener{private double result=0,data1=0,radixPointDepth=1;private boolean radixPointIndicate=false,resultIndicate=false;private char prec='+';private Frame f;private TextField tf;private Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16;private Panel p;static public void main(String args[]){Calculator de=new Calculator();de。go();}public void go(){f=new Frame();p=new Panel(); tLayout(new GridLayout(4,4));tf=new TextField(30);b1=new Button("7");b2=new Button("8");b3=new Button("9");b4=new Button("+");b5=new Button("4");b6=new Button("5");b7=new Button("6");b8=new Button("-");b9=new Button("1");b10=new Button("2");b11=new Button("3");b12=new Button("*");b13=new Button("0");b14=new Button("。");b15=new Button("=");b16=new Button("/"); d(tf,"North"); d(p,"Center"); d(b1); d(b2); d(b3); d(b4); d(b5); d(b6); d(b7); d(b8); d(b9); d(b10); d(b11); d(b12); d(b13); d(b14); d(b15); d(b16); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dActionListener(this); dWindowListener(this); tSize(300,200); tVisible(true);}public void actionPerformed(ActionEvent e){String s;s= tActionCommand();switch( arAt(0)){case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':if(resultIndicate){result=0;data1=0;}Integer Int1=new Integer(s);if(radixPointIndicate){radixPointDepth=radixPointDepth/10;data1=data1+( Value())*radixPointDepth;}else{data1=data1*10+( Value());}Double displayNumber=new Double(data1); tText( String());resultIndicate=false;break;case '+': case '-':case '*':case '/':case '=':if( arAt(0)!='='&&resultIndicate){prec= arAt(0);resultIndicate=false;}else{switch(prec){case '+':result=result+data1;break;case '-':result=result-data1;break;case '*':result=result*data1;break;case '/':result=result/data1;break;}}radixPointIndicate=false;radixPointDepth=1;displayNumber=new Double(result); tText( String());if( arAt(0)!='='){data1=0;prec= arAt(0);}else{resultIndicate=true;}break;case '。':radixPointIndicate=true;break;}}public void windowClosing(WindowEvent e){System。exit(0);}}。

熱心網友

發到你郵箱里了,去看一下