求用java編寫的計算器程式1實現簡單加減

2021-03-03 22:07:34 字數 3279 閱讀 9079

1樓:水星

public mycalculator() { f = new jframe("計算器bymdou"); container contentpane = f.getcontentpane(); /****************選單的建立開始**************************************/ jmenubar mbar = new jmenubar(); mbar.setopaque(true); medit = new jmenu("編輯(e)"); medit.

setmnemonic(keyevent.vk_e); mcopy = new jmenuitem("複製(c)"); medit.add(mcopy); mpaste = new jmenuitem("貼上(p)"); medit.

add(mpaste); mview = new jmenu("檢視(v)"); mview.setmnemonic(keyevent.vk_v); mview.

add(new jmenuitem("標準型")); mview.add(new jmenuitem("科學型")); mview.addseparator(); mview.

add(new jmenuitem("檢視分組")); mhelp = new jmenu("幫助(h)"); mhelp.setmnemonic(keyevent.vk_h); mhelp.

add(new jmenuitem("幫助主題")); mhelp.addseparator(); mhelp.add(new jmenuitem("關於計算器")); mbar.

add(medit); mbar.add(mview); mbar.add(mhelp); f.

setjmenubar(mbar); contentpane.setlayout(new borderlayout()); jpanel ptop = new jpanel(); tresult = new jtextfield("0.",26); tresult.

sethorizontalalignment(jtextfield.right ); tresult.seteditable(false); ptop.

add(tresult); contentpane.add(ptop,borderlayout.north); jpanel pbottom = new jpanel(); pbottom.

setlayout(new borderlayout()); jpanel pleft = new jpanel(); pleft.setlayout(new gridlayout(5,1,3,3)); bm = new jbutton(" "); bm.setenabled(false); pleft.

add(bm); bother = new jbutton("mc"); bother.addactionlistener(this); bother.setforeground(color.

red); bother.setmargin(new insets(3,2,3,2)); pleft.add(bother); bother = new jbutton("mr"); bother.

addactionlistener(this); bother.setforeground(color.red); bother.

setmargin(new insets(3,2,3,2)); pleft.add(bother); bother = new jbutton("ms"); bother.addactionlistener(this); bother.

setforeground(color.red); bother.setmargin(new insets(3,2,3,2)); pleft.

add(bother); bother = new jbutton("m+"); bother.addactionlistener(this); bother.setforeground(color.

red); bother.setmargin(new insets(3,2,3,2)); pleft.add(bother);

java程式編寫一個計算器類,要求實現加、減、乘、除運算,注意在進行除法運算時,如果除數為0,

2樓:小童鞋_成

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class caculator extends jframe implements keylistener{ //構造caculator類

private container content;//構造容器private jbutton bcancel; //清除按鈕private jbutton b=new jbutton[16]; //構造按鈕陣列

private char lastop; //操作符號private boolean countable; //用於判斷是否可計算

3樓:匿名使用者

用java定義一個類,實現加減乘除計算功能,把結果輸出?

java裡使用物件導向的思想編寫一個計算器類,可以實現兩個數的加、減、乘、除運算

4樓:匿名使用者

import java.util.scanner;

public class class else if(token.equals("-"))else if(token.equals("*"))else if(token.

equals("/"))else

system.out.println("計算結果為:"+num1+token+num2+"="+result+";");

system.out.println("是否繼續運算?y/n");

string s=sc.next();

if(s.equals("y"))else if(s.equals("n"))else}}}}

5樓:匿名使用者

public class calculatorpublic double minus(double num1, double num2)

public double multiple(double num1, double num2)

public double divide(double num1, double num2)

return -1;//除數為0,錯誤}}

用C製作科學計算器,如何用C 編寫簡易計算器

用指令碼引擎實現吧,把你要計算的內容轉化為指令碼 你 或者 我 都做出來了,還要微軟幹嘛。去51aspx找原始碼唄 如何用c 編寫簡易計算器 你要做什麼樣的計算器?如何用c 製作計算器啊?兄弟 感覺和你有種似曾相識的感覺 你成都的?建議你去找本參考書慢慢看!用c 做一個計算器怎麼做?你學過別的程式語...

ENKO計算器中如何求,計算器的X怎麼用啊?謝謝幫忙

對於一般的雙行顯示的科學計算器,按 rcl 變數 後,上行會顯示a 統計模式中是 x的平方 下行直接顯示結果。對於單行的計算器,輸入 rcl 變數 後會直接顯示結果。統計模式中,x的平方 的值會代入變數a,所以按 rcl 變數a所在的按鍵 會直接顯示平方和。是不需要單獨輸入 a 的。計算器的 x 怎...

用VF怎麼做簡易計算器啊,VF編寫簡易計算器

你在計算按鈕上雙擊,在其click事件中輸入 a thisform.text1.valueb thisform.text2.valuen thisform.optiongroup1.valuedo case case n 1 thisform.text3.value a bcase n 2 this...