ImageVerifierCode 换一换
格式:DOCX , 页数:23 ,大小:169.40KB ,
资源ID:19252539      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/19252539.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Java计算器实验报告材料Word文档下载推荐.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Java计算器实验报告材料Word文档下载推荐.docx

1、 import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea;import javax.swing.JTextField; public class jsq implements ActionListener /导入动作监听接口 /设计面板中的单位 JFrame frame;/窗口 JTextField text

2、Answer;/文本 JPanel panel, panel1, panel2, panel3;/面版 JMenuBar mainMenu;/菜单 JTextField textMemory; JLabel labelMemSpace; /labelMemSpace单纯做摆设,控制面板的形状 JButton buttonBk, buttonCe, buttonC; JButton button;/按钮数组 JButton buttonMC, buttonMR, buttonMS, buttonMAdd;/清除,使用,储存,添加 JButton buttonDot, buttonAddAndSu

3、b, buttonAdd, buttonSub, buttonMul, buttonDiv, buttonMod; JButton buttonSqrt, buttonDao, buttonEqual; JMenu editMenu, viewMenu, helpMenu; JMenuItem copyItem, pasteItem, tItem, sItem, numberGroup, topHelp, aboutCal; DecimalFormat df; /设置数据输出精度 boolean clickable; /控制当前能否按键 double memoryd; /使用内存中存储的数字

4、int memoryi; double vard, answerd; /用来保存double型数据的中间值(vard)和最后结果(answerd) short key = -1, prekey = -1; /key用来保存当前进行何种运算,prekey用来保存前次进行何种运算 String copy; /做复制用 JTextArea help; /帮助 JScrollPane scrollHelp; /构造函数 public jsq() clickable = true; answerd = 0; frame = new JFrame(计算器); df = new DecimalFormat(

5、0.# /设置数据输出精度(对于double型值) textAnswer = new JTextField(15); textAnswer.setText( textAnswer.setEditable(false); textAnswer.setBackground(new Color(255, 255, 255); panel = new JPanel(); frame.getContentPane().add(panel); panel1 = new JPanel(); panel2 = new JPanel(); panel.setLayout(new BorderLayout();

6、/设计整个面板 mainMenu = new JMenuBar(); editMenu =new JMenu(编辑(E) editMenu .setMnemonic(KeyEvent.VK_E); viewMenu =new JMenu(查看(V) viewMenu .setMnemonic(KeyEvent.VK_V); helpMenu =new JMenu(帮助(H) helpMenu .setMnemonic(KeyEvent.VK_H); mainMenu .add(editMenu ); mainMenu .add(viewMenu ); mainMenu .add(helpMen

7、u ); panel.add(mainMenu, BorderLayout.NORTH); panel.add(textAnswer, BorderLayout.CENTER); panel.add(panel1, BorderLayout.SOUTH); panel1.setLayout(new BorderLayout(); textMemory = new JTextField(3); textMemory.setEditable(false); textMemory.setBackground(new Color(217, 217, 217); labelMemSpace = new

8、JLabel( buttonBk = new JButton(Backspace buttonBk.setForeground(new Color(255, 0, 0); buttonCe = new JButton(CE buttonCe.setForeground(new Color(255, 0, 0); buttonC = new JButton(C buttonC.setForeground(new Color(255, 0, 0); buttonBk.addActionListener(this); buttonCe.addActionListener(this); buttonC

9、.addActionListener(this); panel1.add(panel2, BorderLayout.NORTH); panel2.setLayout(new FlowLayout(FlowLayout.RIGHT); panel2.add(textMemory); panel2.add(labelMemSpace); panel2.add(buttonBk); panel2.add(buttonCe); panel2.add(buttonC); panel3 = new JPanel(); panel1.add(panel3, BorderLayout.CENTER); but

10、ton = new JButton10; for (int i = 0; i button.length; i+) buttoni = new JButton(Integer.toString(i); buttoni.setForeground(new Color(0, 0, 255); /构造按钮 buttonMC = new JButton(MC buttonMC.setForeground(new Color(255, 0, 0); buttonMR = new JButton(MR buttonMR.setForeground(new Color(255, 0, 0); buttonM

11、S = new JButton(MS buttonMS.setForeground(new Color(255, 0, 0); buttonMAdd = new JButton(M+ buttonMAdd.setForeground(new Color(255, 0, 0); buttonDot = new JButton(. buttonDot.setForeground(new Color(0, 0, 255); buttonAddAndSub = new JButton(+/- buttonAddAndSub.setForeground(new Color(0, 0, 255); but

12、tonAdd = new JButton(+ buttonAdd.setForeground(new Color(255, 0, 0); buttonSub = new JButton(- buttonSub.setForeground(new Color(255, 0, 0); buttonMul = new JButton(* buttonMul.setForeground(new Color(255, 0, 0); buttonDiv = new JButton(/ buttonDiv.setForeground(new Color(255, 0, 0); buttonMod = new

13、 JButton(% buttonMod.setForeground(new Color(0, 0, 255); buttonSqrt = new JButton(sqrt buttonSqrt.setForeground(new Color(0, 0, 255); buttonDao = new JButton(1/x buttonDao.setForeground(new Color(0, 0, 255); buttonEqual = new JButton(= buttonEqual.setForeground(new Color(255, 0, 0); /将所有行为与监听绑定 pane

14、l3.setLayout(new GridLayout(4, 6); panel3.add(buttonMC); buttonMC.addActionListener(this); panel3.add(button7); button7.addActionListener(this); panel3.add(button8); button8.addActionListener(this); panel3.add(button9); button9.addActionListener(this); panel3.add(buttonDiv); buttonDiv.addActionListe

15、ner(this); panel3.add(buttonSqrt); buttonSqrt.addActionListener(this); panel3.add(buttonMR); buttonMR.addActionListener(this); panel3.add(button4); button4.addActionListener(this); panel3.add(button5); button5.addActionListener(this); panel3.add(button6); button6.addActionListener(this); panel3.add(

16、buttonMul); buttonMul.addActionListener(this); panel3.add(buttonMod); buttonMod.addActionListener(this); panel3.add(buttonMS); buttonMS.addActionListener(this); panel3.add(button1); button1.addActionListener(this); panel3.add(button2); button2.addActionListener(this); panel3.add(button3); button3.ad

17、dActionListener(this); panel3.add(buttonSub); buttonSub.addActionListener(this); panel3.add(buttonDao); buttonDao.addActionListener(this); panel3.add(buttonMAdd); buttonMAdd.addActionListener(this); panel3.add(button0); button0.addActionListener(this); panel3.add(buttonAddAndSub); buttonAddAndSub.ad

18、dActionListener(this); panel3.add(buttonDot); buttonDot.addActionListener(this); panel3.add(buttonAdd); buttonAdd.addActionListener(this); panel3.add(buttonEqual); buttonEqual.addActionListener(this); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.show(); /设置各个按钮行为 public

19、void actionPerformed(ActionEvent event) boolean sign = false; /判断是否是double型数参与运算,是为true,不是为false Object temp = event.getSource(); try /如果按下数据按钮,将按下的按钮代表的数据插入的当前文本框字符串之后= 9; i+) if (temp = buttoni & clickable = true) textAnswer.setText(textAnswer.getText() + Integer.toString(i); /按下按钮时,判断当前文本框内字符串中含不

20、含,如果已含,则不允许再插入 if (temp = buttonDot & clickable = true) boolean isDot = false; if (textAnswer.getText().length() = 0) isDot = true; textAnswer.getText().length(); if (. = textAnswer.getText().charAt(i) break; if (isDot = false) textAnswer.setText(textAnswer.getText() + if (temp = buttonAdd | temp =

21、buttonSub | temp = buttonMul | temp = buttonDiv) & /操作 if (temp = buttonAdd) switch (prekey) case 0: answerd += Double.parseDouble(textAnswer.getText(); case 1: answerd -= Double.parseDouble(textAnswer.getText(); case 2: answerd *= Double.parseDouble(textAnswer.getText(); case 3: if (Double.parseDou

22、ble(textAnswer.getText() = 0) /textAnswer=aa;除数不能为零 clickable = false; else answerd /= Double.parseDouble(textAnswer.getText(); default: answerd = Double.parseDouble(textAnswer.getText(); prekey = key = 0; if (temp = buttonSub) prekey = key = 1; if (temp = buttonMul) /textAnser = prekey = key = 2; if (temp = buttonDiv) prekey = key = 3;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1