




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
import java.awt.*; import java.awt.event.*;public class Cal public static void main(String args) CalFrame f = new CalFrame();class CalFrame extends Frame double d1, d2;int op = -1;TextField tf;CalPanelL p1;CalPanelR p2;/ ConstructorCalFrame() super(“Small Calculator“);setLayout(new FlowLayout(FlowLayout.CENTER,8,10);setBackground(new Color(100,150,150);setForeground(Color.white);setResizable(false);setSize(300,200);tf = new TextField(22);tf.setEditable(false);tf.setBackground(new Color(108,118,103);tf.setForeground(Color.white);tf.setFont(new Font(“Arial“,Font.BOLD,16);add(tf);p1 = new CalPanelL();p2 = new CalPanelR();add(p1);add(p2);setVisible(true);addWindowListener(new Wclose();/ inner class:CalButtonclass CalButton extends Button CalButton(String s)super(s);setBackground(Color.gray);/ inner class: CalPanelLclass CalPanelL extends Panel CalButton b0, b1, b2, b3,b4, b5, b6, b7,b8, b9, bPN, bPoint;CalPanelL() setLayout(new GridLayout(4,3);setFont(new Font(“TimesRoman“,Font.BOLD,16);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(“.“); / 加入按钮add(b7); b7.addActionListener(new PressB7(); add(b8); b8.addActionListener(new PressB8(); add(b9); b9.addActionListener(new PressB9(); add(b4); b4.addActionListener(new PressB4(); add(b5); b5.addActionListener(new PressB5(); add(b6); b6.addActionListener(new PressB6(); add(b1); b1.addActionListener(new PressB1(); add(b2); b2.addActionListener(new PressB2(); add(b3); b3.addActionListener(new PressB3(); add(b0); b0.addActionListener(new PressB0(); add(bPN); bPN.addActionListener(new PressBPN(); ;add(bPoint); bPoint.addActionListener(new PressBPoint(); class CalPanelR extends Panel CalButton bAdd, bSub, bMul, bDiv,bSqrt, bSin, bCos, bYx,bLn, bEqual, bCE, bBack;CalPanelR() setLayout(new GridLayout(4,3);setFont(new Font(“TimesRoman“,Font.BOLD,16);bAdd = new CalButton(“+“); bSub = new CalButton(“-“); bMul = new CalButton(“*“); bDiv = new CalButton(“/“); bSqrt = new CalButton(“sqrt“); bSin = new CalButton(“sin“); bCos = new CalButton(“cos“); bYx = new CalButton(“yx“); bLn = new CalButton(“ln“); bEqual = new CalButton(“=“); bCE = new CalButton(“CE“); bBack = new CalButton(“= 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 ActionList
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年机器人技术与应用专业试题及答案
- 桌面演练知识培训课件
- 2025年B级注册验船师资格考试复习资料模拟试题及答案一
- 2025注册验船师资格考试(A级船舶检验专业能力)测试题及答案一
- 2025年健康素养知识考试题库及答案(含各题型)
- 国有银行考试题库及答案
- 北京市门头沟区2023-2024学年七年级下学期第一次月考道德与法制试题及答案
- 2025年企业人力资源管理师法规实施能力考试预测题
- 2025年项目经理中级考试模拟题集与备考策略
- 2025年本科院校教学管理岗位面试题及解析
- Z20+名校联盟(浙江省名校新高考研究联盟)2026届高三第一次联考英语及答案
- 2025-2030年中国黑色像素定义层材料(BPDL)市场调研分析及投资前景研究预测报告
- 2025至2030中国开环霍尔效应电流传感器行业发展趋势分析与未来投资战略咨询研究报告
- 民族宗教法规课件
- 2025年吉林省事业单位招聘考试公共基础知识考试试题库及答案详解
- 2025年农业科技学(农业技术推广)知识考试题库与答案
- 2025年陕西西安工程大学专职辅导员招聘考试笔试试题(含答案)
- 共享员工模式创新创业项目商业计划书
- 2025年26道医院财务科岗位面试真题及答案
- 研发样品管理办法
- 2025年四川乐山市中区物理高一下期末调研试题含解析
评论
0/150
提交评论