计算机组织原理与体系结构课程设计用Java Swing实现简单的计算器功能.doc
《计算机组织原理与体系结构课程设计用Java Swing实现简单的计算器功能.doc》由会员分享,可在线阅读,更多相关《计算机组织原理与体系结构课程设计用Java Swing实现简单的计算器功能.doc(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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机组织原理与体系结构课程设计用Java Swing实现简单的计算器功能 计算机 组织 原理 体系结构 课程设计 Java Swing 实现 简单 计算器 功能
链接地址:https://www.31ppt.com/p-2387651.html