




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、import java.awt.BorderLayout;import java.awt.Color;import java.awt.FlowLayout;import java.awt.F ont;import java.awt.GridLayout;import java.awt.eve nt.Act ion Eve nt;import java.awt.eve nt.Act ion Liste ner;import javax.swi ng.JButt on;import javax.swi ng.JFrame;import javax.swi ng.JPa nel;import jav
2、ax.swi ng.JTextField;public class CalculatorB impleme nts Acti on Liste ner private JFrame frame;private JTextField field;private JButton allButtons;private JButton clearButton;/构造初始化成员变量public CalculatorB() frame = new JFrame(Calculator v1.1);field = new JTextField(25);allButto ns = new JButto n16;
3、Stri ng str = 123+456-789*0.=/;for (int i = 0; i 16; i+) allButt on si = new JButt on( str.substri ng(i, i + 1);clearButton = new JButto n( CLEAR);/调用界面的初始化方法ini t();/调用设置文本框的字体和颜色方法setFo ntAn dColor();addEve ntHa ndler();public void addEve ntHa ndler() for (int i = 0; i allButt ons.len gth; i+) all
4、Butt on si.addAct ion Liste ner(this);clearButt on .addAct ion Liste ner(this);private String op = null;private String m = null;private String n = nuII;private boolea n cls = false;private void setResult() if (field.getText().equals() cis = true;m = n ull;n = n ull; else if (m != n ull) n = field.ge
5、tText();if (op.equals(+) field.setText(Double.parseDouble(m) + Double.parseDouble( n)+ ); else if (op.equals(-) field.setText(Double.parseDouble(m) - Double.parseDouble( n)+ ); else if (op.equals(*) field.setText(Double.parseDouble(m) * Double.parseDouble( n)+ ); else if (op.equals(/) field.setText(
6、Double.parseDouble(m) / Double.parseDouble( n)+ );cls = true;m = n ull;n = n ull;public void actio nPerformed(Actio nEvent e) Stri ng str = e.getActio nComma nd();得到被点的按钮名称if (0123456789.indexOf(str) != -1) if (cis) field.setText(”);cis = false;field.setText(field.getText() + str); else if (+-*/.ind
7、exOf(str) != -1) if (field.getText().equals() op = str; else if (m = n ull) m = field.getText(); op = str;field.setText(”); else if (m != n ull) setResult();m = field.getText(); op = str; else if (str.equals(=) setResult(); else if (str.equals(CLEAR) field.setText(”);m = n ull;n = n ull;public void
8、in it() frame.setLayout (new BorderLayout();JPa nel n orthPa nnel = new JPa nel();JPa nel cen terPa nnel = new JPa nel();JPa nel southPa nnel = new JPa nel();no rthPa nn el.setLayout (new FlowLayout();cen terPa nn el.setLayout (new GridLayout(4, 4);southPa nn el.setLayout (new FlowLayout();n orthPa
9、nn el.add(field);southPa nn el.add(clearButt on);for (int i = 0; i allButt ons.len gth; i+) cen terPa nn el.add(allButt on si);frame.add( no rthPa nn el, BorderLayout.NORTH);frame.add(southPa nn el, BorderLayout.SOUTH); frame.add(ce nterPa nn el, BorderLayout.CENTER);public void setFo ntAn dColor()
10、field.setFont(new Font( 宋体,Font.BOLD, 20);field.setForegrou nd(Color.PINK);field.setBackgrou nd( new Color(0x2a, 0x3b, 0x4f);public void showMe() frame.pack(); /系统调整大小-很重要/ frame.setSize(600, 400);/自定义窗体大小frame.setLocatio n(500, 400);/设置窗体的启动位置frame.setVisible(true);frame.setDefaultCloseOperati on(
11、3);public static void main( Stri ng args) new CalculatorB().showMe();When you are old and grey and full of sleep,And no ddi ng by the fire, take down this book,And slowly read, and dream of the soft lookYour eyes had once, and of their shadows deep;How many loved your mome nts of glad grace,And love
12、d your beauty with love false or true,But one man loved the pilgrim soul in you,And loved the sorrows of your cha nging face;And bending dow n beside the glow ing bars,Murmur, a little sadly, how love fledAnd paced upon the mountains overheadAnd hid his face amid a crowd of stars.The furthest dista
13、nee in the worldIs not betwee n life and deathBut whe n I sta nd in front of youYet you dont know thatI love you.The furthest dista nee in the worldIs not whe n I sta nd in front of youYet you cant see my loveBut whe n un doubtedly knowing the love from bothYet cannot be together.The furthest dista
14、nee in the worldIs not being apart while being in loveBut whe n I pla inly cannot resist the year ningYet prete nding you have n ever bee n in my heart.The furthest dista nee in the worldIs not struggli ng aga inst the tidesBut using on es in differe nt heartTo dig an un crossable riverFor the one who loves you.倚窗远眺,目光目光尽处必有一座山,那影影绰绰的黛绿色的影,是春天的 颜色。周遭流岚升腾,没露出那真实的面孔。面对那流转的薄雾,我会幻想,那 里有一个世外桃源。在天阶夜色凉如水的夏夜,我会静静地,静静地,等待一场 流星
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025湖南永州市教育局直属学校(单位)公开招聘教师46人模拟试卷附答案详解
- 2025年甘肃省兰州大学数学与统计学院人才招聘考前自测高频考点模拟试题及参考答案详解一套
- 2025广西桂林市资源县中峰镇中心卫生院公开招聘编外专业技术人员2人考前自测高频考点模拟试题及答案详解(必刷)
- 2025内蒙古能源集团所属单位招聘30人模拟试卷及参考答案详解一套
- 2025湖北随州市招募选派三支一扶高校毕业生80人考前自测高频考点模拟试题附答案详解(典型题)
- 2025海南澄迈县就业局招聘见习生1人模拟试卷附答案详解(模拟题)
- 2025北京华商电力产业发展有限公司2025年搞笑毕业生招聘29人(第三批)模拟试卷及答案详解(网校专用)
- 2025年4月广东深圳小学光明学校曙光校区、狮山校区赴济南定点面向2025年应届毕业生招聘教师11人模拟试卷及1套参考答案详解
- 2025年咸阳经济技术开发区管委会招聘?(24人)模拟试卷及1套完整答案详解
- 2025北京首都医科大学附属北京世纪坛医院招聘13人(第三批)考前自测高频考点模拟试题完整参考答案详解
- 【初中语文】第1课《消息二则》课件++2025-2026学年统编版语文八年级上册
- 电力消防安全知识考试题库含答案2025
- 2025年国学与传统文化考试试题及答案
- 仪表参数调校规程
- 2024年10月自考00144企业管理概论真题及答案
- 子宫颈炎症护理课件
- 石油化工课件
- 非小细胞肺癌课件
- 6.1正视发展挑战 课件 2025-2026学年度道德与法治九年级上册 统编版
- 涉密人员岗前知识培训课件
- VOCs治理设备培训
评论
0/150
提交评论