j**a编一个计算器的代码

果儿姐姐 2024-05-17 06:08:25
最佳回答
漂亮堪比系统自带计算器,功能完美乘除开平方等等全部具备,还有清零按钮,小数点的,连加连乘功能完全参考系统官方计算器经过长期调试改进而成,马上拷贝代码拿去试试看吧,绝不后悔! 代码如下: import j**a.awt.*; import j**a.awt.event.*; import j**ax.swing.*; import j**a.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.addactionl**tener ( new actionl**tener() { public void actionperformed(actionevent e) { counterframe.th**.windowclosed(); } } ); menufile.add(menufileexit); menubar.add(menufile); menubar.add(menufile1); menubar.add(menufile2); menubar.add(menufile3); settitle("计算器"); setjmenubar(menubar); setsize(new dimension(400, 280)); th**.getcontentpane().add(new allpanel()); th**.addwindowl**tener ( new windowadapter() { public void windowclosing(windowevent e) { counterframe.th**.windowclosed(); } } ); } protected void windowclosed() { system.exit(0); } } class tool { public static tool instance; private jtextfield field; private tool() { th**.field=new jtextfield(30); th**.field.sethorizontalalignment(jtextfield.right); } public static tool getinstance() { if(instance==**) { instance=new tool(); } return instance; } public jtextfield getfield() { return (th**.field); } } class allpanel extends jpanel { public allpanel() { th**.setlayout(new borderlayout(0,7)); northpanel np=new northpanel(); centerpanel cp=new centerpanel(); th**.add(np,borderlayout.north); th**.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(); th**.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;i<20;i++) { final **utton b=new **utton(arg[i]); //th**.add(new **utton(arg[i])); th**.add(b); if(i==0||i==1||i==2||i==5||i==6||i==7||i==10||i==11||i==12||i==15) { b.addactionl**tener(new actionl**tener() { 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.addactionl**tener(new actionl**tener() { 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.addactionl**tener(new actionl**tener() { public void actionperformed(actionevent e) { string ma=text.gettext(); add=double.parsedouble(ma); if(what==**) { tool=add; what="add"; } else { tool=tool+add; text.settext(string.valueof((tool))); } vc.add("a"); vc1.add("v1"); to="+"; } }); } if(i==13) { b.addactionl**tener(new actionl**tener() { public void actionperformed(actionevent e) { string ma=text.gettext(); jq=double.parsedouble(ma); if(what==**) { tool=jq; what="jq"; } else { tool=tool-jq; text.settext(string.valueof((tool))); } vc.add("a"); vc1.add("v1"); to="-"; } }); } if(i==3) { b.addactionl**tener(new actionl**tener() { public void actionperformed(actionevent e) { string ma=text.gettext(); cq=double.parsedouble(ma); if(what==**) { tool=cq; what="cq"; } else { tool=tool/cq; text.settext(string.valueof((tool))); } vc.add("a"); vc1.add("v1"); to="/"; } }); } if(i==4) { b.addactionl**tener(new actionl**tener() { public void actionperformed(actionevent e) { string ma=text.gettext(); cq=double.parsedouble(ma); text.settext(string.valueof(math.sqrt(cq))); } }); } if(i==8) { b.addactionl**tener(new actionl**tener() { public void actionperformed(actionevent e) { string ma=text.gettext(); cs=double.parsedouble(ma); if(what==**) { tool=cs; what="cs"; } else { tool=tool*cs; text.settext(string.valueof((tool))); } vc.add("a"); vc1.add("v1"); to="*"; } }); } if(i==19) { b.addactionl**tener(new actionl**tener() { 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==**) { 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=**; tool=0; } }); } } } } class centernorth extends jpanel { public centernorth() { final jtextfield text=tool.getinstance().getfield(); **utton **1=new **utton("backspace"); **utton **2=new **utton(" ce "); **utton **3=new **utton(" c "); th**.add(**1); th**.add(**2); th**.add(**3); **1.addactionl**tener(new actionl**tener(){ public void actionperformed(actionevent e) { string back=tool.getinstance().getfield().gettext(); text.settext(backmethod(back)); centercenter.vec.remove(centercenter.vec.size()-1); } }); **3.addactionl**tener(new actionl**tener(){ 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=**; centercenter.tool=0; } }); } public string backmethod(string str) { return str.substring(0,str.length()-1); } } class centerpanel extends jpanel { public centerpanel() { th**.setlayout(new borderlayout(8,7)); centernorth cn=new centernorth(); centercenter cc=new centercenter(); centerwest cw=new centerwest(); th**.add(cn,borderlayout.north); th**.add(cc,borderlayout.center); th**.add(cw,borderlayout.west); } } class centerwest extends jpanel { public centerwest() { th**.setlayout(new gridlayout(4,1,3,3)); th**.add(new **utton("mc")); th**.add(new **utton("mr")); th**.add(new **utton("ms")); th**.add(new **utton("m+")); } } class northpanel extends jpanel { private jtextfield tf; public northpanel() { tf=tool.getinstance().getfield(); th**.add(tf); } } ---------------------------------------------------------------------------=============《按你要求特意后改过的最简单功能的代码如下》========================import j**a.awt.*;import j**a.awt.event.*;import j**ax.swing.*;import j**a.util.*;public class counter2 { public static void main(string[] args) { counterframe frame = new counterframe(); frame.show(); }}class counterframe extends jframe { public counterframe() { settitle("计算器"); setsize(new dimension(400, 280)); th**.getcontentpane().add(new allpanel()); th**.addwindowl**tener ( new windowadapter() { public void windowclosing(windowevent e) { counterframe.th**.windowclosed(); } } ); } protected void windowclosed() { system.exit(0); }}class tool {public static tool instance; private jtextfield field; private tool() { th**.field=new jtextfield(30); th**.field.sethorizontalalignment(jtextfield.right); }public static tool getinstance() { if(instance==**) { instance=new tool(); } return instance; } public jtextfield getfield() { return (th**.field); }}class allpanel extends jpanel { public allpanel() { th**.setlayout(new borderlayout(0,7)); northpanel np=new northpanel(); centerpanel cp=new centerpanel(); th**.add(np,borderlayout.north); th**.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(); th**.setlayout(new gridlayout(4,5,3,3)); string arg[] ={"7","8","9","/","4","5","6","*","1","2","3","-","0","=",".","+"}; for(int i=0;i<16;i++) { final **utton b=new **utton(arg[i]); //th**.add(new **utton(arg[i])); th**.add(b); if(i==0||i==1||i==2||i==4||i==5||i==6||i==8||i==9||i==10||i==12) { b.addactionl**tener(new actionl**tener() { 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.addactionl**tener(new actionl**tener() { 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.addactionl**tener(new actionl**tener() { public void actionperformed(actionevent e) { string ma=text.gettext(); add=double.parsedouble(ma); if(what==**) { tool=add; what="add"; } else { tool=tool+add; text.settext(string.valueof((tool))); } vc.add("a"); vc1.add("v1"); to="+"; } }); } if(i==11) { b.addactionl**tener(new actionl**tener() { public void actionperformed(actionevent e) { string ma=text.gettext(); jq=double.parsedouble(ma); if(what==**) { tool=jq; what="jq"; } else { tool=tool-jq; text.settext(string.valueof((tool))); } vc.add("a"); vc1.add("v1"); to="-"; } }); } if(i==3) { b.addactionl**tener(new actionl**tener() { public void actionperformed(actionevent e) { string ma=text.gettext(); cq=double.parsedouble(ma); if(what==**) { tool=cq; what="cq"; } else { tool=tool/cq; text.settext(string.valueof((tool))); } vc.add("a"); vc1.add("v1"); to="/"; } }); }if(i==7) { b.addactionl**tener(new actionl**tener() { public void actionperformed(actionevent e) { string ma=text.gettext(); cs=double.parsedouble(ma); if(what==**) { tool=cs; what="cs"; } else { tool=tool*cs; text.settext(string.valueof((tool))); } vc.add("a"); vc1.add("v1"); to="*"; } }); } if(i==13) { b.addactionl**tener(new actionl**tener() { 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==**) { 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=**; tool=0; } }); } }}}class centernorth extends jpanel { public centernorth() { final jtextfield text=tool.getinstance().getfield(); }}class centerpanel extends jpanel { public centerpanel() { th**.setlayout(new borderlayout(8,7)); centernorth cn=new centernorth(); centercenter cc=new centercenter(); centerwest cw=new centerwest(); th**.add(cn,borderlayout.north); th**.add(cc,borderlayout.center); th**.add(cw,borderlayout.west); } }class centerwest extends jpanel { public centerwest() { }}class northpanel extends jpanel { private jtextfield tf; public northpanel() { tf=tool.getinstance().getfield(); th**.add(tf); } }------------------------------------------------------------才子_辉祝您愉快! 20210311
汇率兑换计算器

类似问答
  • 求大神帮我详解一下这一段j**a代码
    • 2024-05-17 02:38:19
    • 提问者: 未知
    这段代码的含义就是:编写j**a应用程序实现下面数据的排序,从小到大排序。publicclass a {//这是类名,每个j**a类都得有一个 publicstaticvoid main(string[] args) { //声明main函数,这是程序的入口 application1();//调用application1()这个方法。 } privatestatic void a...
  • 有没有可以自动探测一个文本的编码的dll文件,就像一些文本编辑器能自动地用合适的编码打开一个文本
    • 2024-05-17 23:25:14
    • 提问者: 未知
    我刚刚学习了这个,来一段vb.net的代码,这是我从网上搜索到的。转化成了vb。使用方法是把这些代码保存成一个类。然后在另一个类中调用 : dim ed as encoding ed = encodingtype.getcodetype(fname)简单吧。具体代码如下:imports systemimports system.ioimports system.text'...
  • 海关编码-计量单位代码表
    • 2024-05-17 05:08:58
    • 提问者: 未知
    代码名称001台002座003辆004艘005架006套007008只009010张011件012支013枝014根015条016把017块018卷019副020片021组022份023幅025双026对027棵028株029井030031盘032平方米033立方木034筒035千克036克037盆038万个039具040百副041百支042百把043百个044百片045刀046疋047公担048...
  • 增量式编码器和绝对式编码器哪个好
    • 2024-05-17 11:26:03
    • 提问者: 未知
    肯定是绝对值编码器好,绝对值编码器掉电记忆功能,绝对值编码器输出可选:ssi、4-20ma、0-10v,profibus-dp、devicenet、并行、二进制码、b**s、canopen、endat及hiperface等ben编码器常用规格:besm58,be1322sm58-n011,besm58-011、be122sm58、be1822sm58、be420sm58,be1622sm58-n0...
  • 求一房贷计算器j**a源程序
    • 2024-05-17 20:34:01
    • 提问者: 未知
    打了个电话给农行的客服(收费的),终于知道公式了。.好麻烦的公式...浪费了我15分钟的电话费。 还有在写公式的过程中遇到了计算x的y次方..谁知道j**a里怎么计算啊???我是自己写了个方法。.感觉有点麻烦...注意的是利率.由于开始写的时候没考虑到小数点.所以这里都是按整数算..比如利率是7.5%就写成750..呵呵。.不直到她公式给错了还是我没听清楚.好象公式有些不准。.明天我去银行问下。...
  • 求一个关于个人贷款计算器的代码
    • 2024-05-17 09:09:36
    • 提问者: 未知
    这么简单的页面,给你个公式,自己算吧每期应还款额=【借款本金×月利率×(1+月利率)^还款期数】/【(1+月利率)^还款期数-1】
  • 有什么好用的手机(android)上的代码编辑器吗?
    • 2024-05-17 07:20:46
    • 提问者: 未知
    安卓上很多文本编辑器只能编辑几百k的文件,稍大就卡的要死。...推荐三个国外开发者写的 android 代码编辑器,在 google play 上都收获超过 5k+好评的,同时国内应用商店也...
  • j**a编程怎么编一个银行账户类
    • 2024-05-17 23:05:06
    • 提问者: 未知
    可选中1个或多个下面的关键词,搜索相关资料。也可直接点“搜索资料”搜索整个问题。j**a编程银行账户
  • 国产计算器密码是什么?
    • 2024-05-17 11:33:47
    • 提问者: 未知
    国产计算器是不码的计算器是现代明的可以进字运算的电子机器现代的电子计算器能进行数学运算的手持电子机器,拥有集成电路芯片,但结构比电脑简单得多,可以说是第一代的电子计算机(电脑),且功能也较弱,但较为方便与廉价,可广泛运用于商业交易中,是必备的办公用品之一。除显示计算结果外,还常有溢出指示、错误指示等。计算器电源采用交流转换器或电池,电池可用交流转换器或太阳能转换器再充电。为节省电能,计算器都采用c...
  • 谁有flex制作计算器的源代码
    • 2024-05-17 14:53:54
    • 提问者: 未知
    我做了一个flex 简单的计算器,在我的个人网站()上有的下载,有兴趣的话,可以去看看o(∩_∩)o参考链接:
汇率兑换计算器

热门推荐
热门问答
最新问答
推荐问答
新手帮助
常见问题
房贷计算器-九子财经 | 备案号: 桂ICP备19010581号-1 商务联系 企鹅:2790-680461

特别声明:本网为公益网站,人人都可发布,所有内容为会员自行上传发布",本站不承担任何法律责任,如内容有该作者著作权或违规内容,请联系我们清空删除。