计算机组织原理与体系结构课程设计用Java Swing实现简单的计算器功能

上传人:夏** 文档编号:508143434 上传时间:2023-03-19 格式:DOC 页数:27 大小:271.02KB
返回 下载 相关 举报
计算机组织原理与体系结构课程设计用Java Swing实现简单的计算器功能_第1页
第1页 / 共27页
计算机组织原理与体系结构课程设计用Java Swing实现简单的计算器功能_第2页
第2页 / 共27页
计算机组织原理与体系结构课程设计用Java Swing实现简单的计算器功能_第3页
第3页 / 共27页
计算机组织原理与体系结构课程设计用Java Swing实现简单的计算器功能_第4页
第4页 / 共27页
计算机组织原理与体系结构课程设计用Java Swing实现简单的计算器功能_第5页
第5页 / 共27页
点击查看更多>>
资源描述

《计算机组织原理与体系结构课程设计用Java Swing实现简单的计算器功能》由会员分享,可在线阅读,更多相关《计算机组织原理与体系结构课程设计用Java Swing实现简单的计算器功能(27页珍藏版)》请在金锄头文库上搜索。

1、用Java Swing实现简单的计算器功能 班级: 姓名: 学号: 计算机科学与工程学院 网络工程系一:源代码如下:package com.xinzhan.demoFrame;import java.awt.Font;import java.awt.Image;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JO

2、ptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class CalculatorFrame extends JFrame implements ActionListenerpublic JTextField textField = new JTextField();private final JPanel panel = new JPanel();private final JButton b12 = new JButton();private final JButton b13 = new JB

3、utton();private final JButton s5 = new JButton();private final JButton s1 = new JButton();private final JButton b7 = new JButton();private final JButton b8 = new JButton();private final JButton b9 = new JButton();private final JButton s2 = new JButton();private final JButton b4 = new JButton();priva

4、te final JButton b5 = new JButton();private final JButton b6 = new JButton();private final JButton s3 = new JButton();private final JButton b1 = new JButton();private final JButton b2 = new JButton();private final JButton b3 = new JButton();private final JButton s4 = new JButton();private final JBut

5、ton b0 = new JButton();private final JButton b11 = new JButton();private final JButton bn = new JButton();private final Image icon1 = Toolkit.getDefaultToolkit().getImage(image/cal.png);private boolean add,sub,mul,div;private boolean end = true;private double num1;/第一个操作数private double num2;/第二个操作数p

6、rivate double result;/存放结果/* * Launch the application * param args */public static void main(String args) try CalculatorFrame frame = new CalculatorFrame();frame.setVisible(true); catch (Exception e) e.printStackTrace();/* * Create the frame * return */public CalculatorFrame() super();this.setBounds

7、(Toolkit.getDefaultToolkit().getScreenSize().width/2-553/2,Toolkit.getDefaultToolkit().getScreenSize().height/2-487/2, 553, 487);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);try jbInit(); catch (Throwable e) e.printStackTrace();private void jbInit() throws Exception getContentPane().setLayout(null

8、);setFont(new Font(黑体, Font.PLAIN, 20);setTitle(计算机Jhon2.0版);this.setIconImage(icon1);getContentPane().add(textField);textField.setFont(new Font(楷体, Font.PLAIN, 20);textField.setBounds(47, 29, 448, 83);textField.setHorizontalAlignment(JTextField.RIGHT);textField.setEditable(false);textField.setText(

9、0);getContentPane().add(panel);panel.setLayout(null);panel.setBounds(10, 141, 517, 308);panel.add(b12);b12.setFont(new Font(楷体, Font.PLAIN, 20);b12.setBounds(10, 10, 106, 40);b12.setText(Cancel);b12.addActionListener(this);panel.add(b13);b13.setFont(new Font(楷体, Font.PLAIN, 30);b13.setText(CE);b13.s

10、etBounds(143, 10, 106, 40);b13.addActionListener(this);panel.add(s5);s5.setText(EXIT);s5.setFont(new Font(楷体, Font.PLAIN, 30);s5.setBounds(270, 10, 106, 40);s5.addActionListener(this);panel.add(s1);s1.setFont(new Font(楷体, Font.PLAIN, 30);s1.setText(+);s1.setBounds(401, 10, 106, 40);s1.addActionListe

11、ner(this);panel.add(b7);b7.setFont(new Font(楷体, Font.PLAIN, 30);b7.setText(7);b7.setBounds(10, 70, 106, 40);b7.addActionListener(this);panel.add(b8);b8.setFont(new Font(楷体, Font.PLAIN, 30);b8.setText(8);b8.setBounds(143, 70, 106, 40);b8.addActionListener(this);panel.add(b9);b9.setFont(new Font(楷体, F

12、ont.PLAIN, 30);b9.setText(9);b9.setBounds(270, 70, 106, 40);b9.addActionListener(this);panel.add(s2);s2.setFont(new Font(, Font.PLAIN, 30);s2.setText(-);s2.setBounds(401, 70, 106, 40);s2.addActionListener(this);panel.add(b4);b4.setFont(new Font(楷体, Font.PLAIN, 30);b4.setText(4);b4.setBounds(10, 133,

13、 106, 40);b4.addActionListener(this);panel.add(b5);b5.setFont(new Font(楷体, Font.PLAIN, 30);b5.setText(5);b5.setBounds(143, 133, 106, 40);b5.addActionListener(this);panel.add(b6);b6.setFont(new Font(楷体, Font.PLAIN, 30);b6.setText(6);b6.setBounds(270, 133, 106, 40);b6.addActionListener(this);panel.add(s3);s3.setFont(new Font(楷体, Font.PLAIN, 30);s3.setText(*);s3.setBounds(401, 133, 106, 40);s3.addActionListener(this);panel.add(b1);b1.setFont(new Font(楷体, Font.PLAIN, 30);b1.setText(1);b1.setBounds(10, 195, 106, 40);b1.addActionListener(this);panel.add(b2);b2.setFont(new Font(楷体, Font.PLAIN, 30);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 工作计划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号