计算器交互式Java程序设计

上传人:公**** 文档编号:463958769 上传时间:2023-12-09 格式:DOCX 页数:36 大小:37.31KB
返回 下载 相关 举报
计算器交互式Java程序设计_第1页
第1页 / 共36页
计算器交互式Java程序设计_第2页
第2页 / 共36页
计算器交互式Java程序设计_第3页
第3页 / 共36页
计算器交互式Java程序设计_第4页
第4页 / 共36页
计算器交互式Java程序设计_第5页
第5页 / 共36页
点击查看更多>>
资源描述

《计算器交互式Java程序设计》由会员分享,可在线阅读,更多相关《计算器交互式Java程序设计(36页珍藏版)》请在金锄头文库上搜索。

1、- 计算器程序:兰州大学 Java 课程设计1. 要求:利用GUI编程技术、网络编程技术、输入输出流技术,编写一个基于 C/S 的计算器软件。前台为类似于图 1 的图形界面,主要解决输入界面问题, 可以解决简单计算问题, 将复杂函数计算如 sin 、开平方根等操作交给后台服务器计算,计算后结果返回客户端显示,并将客户端的 IP 地址,发来的计算请求记录在一个日志文件calculate.log 。2. 实现:主类 :服务器类:CalculatorServer客户端类:CalculatorClient辅类 :查看日志类:lookJFrame图形面板类:mydraws & mycanvas/ 客户端

2、import .*;import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;class CalculatorClient extends JFrame implementsRunnable,ActionListenerprivate JTextField show;private Panel dispMain,dispLeft,dispRight;/主(左右面板)private JButton b;/数字privateJButtonjia

3、,jian,cheng,chu,xy,cos,sin,ln,ce,equ,bfh,point,zf,sqrt;/ 加减乘除各种运算按钮private Socket socket;private DataInputStream in=null;private DataOutputStream out=null;private Thread thread;private Double result;private Double d1,d2;private int j,action,op;private String opp;private JLabel labelconnect;private J

4、Button buttonconnect;privateJMenuItemclose,version,look,edit,word,background,caltuxing;/菜单栏 菜单项设置public CalculatorClient()super( 马康 - 计算器客户端);JMenuBar mb=new JMenuBar();/ 菜单栏JMenu filemenu=new JMenu( 计算器 );JMenu bigmenu=new JMenu(放大);JMenu calmenu=new JMenu(画板);JMenu vermenu=new JMenu(关于);JMenu edit

5、menu=new JMenu( 编辑 );look=new JMenuItem( 查看日志 );close=new JMenuItem( 退出 );version=new JMenuItem( 作者 );background=new JMenuItem( 背景 );caltuxing=new JMenuItem(word=new JMenuItem( 放大 );filemenu.add(look);filemenu.add(close);vermenu.add(version);editmenu.add(background);calmenu.add(caltuxing);bigmenu.ad

6、d(word);mb.add(filemenu);mb.add(editmenu);mb.add(calmenu);mb.add(bigmenu);mb.add(vermenu);this.setJMenuBar(mb);look.addActionListener(this);close.addActionListener(this);background.addActionListener(this);word.addActionListener(this);version.addActionListener(this);caltuxing.addActionListener(this);

7、socket=new Socket(););imageImagegetToolkit().getImage(getClass().getResource(calculator.jpg);setIconImage(image);/ 左上角图片设置setSize(360, 250);setLocation(400, 300);setBackground(Color.LIGHT_GRAY);/ 背景设置setLayout(new FlowLayout(FlowLayout.CENTER);setResizable(false);show=new JTextField(31);show.setText

8、();show.setHorizontalAlignment(SwingConstants.RIGHT);/文本框内容右对齐show.setEditable(false);add(show);dispMain=new Panel();add(dispMain);buttonconnect=new JButton( 连接服务器);labelconnect=new JLabel();add(buttonconnect);add(labelconnect);dispMain.setLayout(new GridLayout(1, 2, 10, 10);dispLeft=new Panel();dis

9、pMain.add(dispLeft);dispLeft.setLayout(new GridLayout(4, 3, 3, 3);dispRight=new Panel();dispMain.add(dispRight);dispRight.setLayout(new GridLayout(4, 3, 3, 3);b=new JButton10;int l;for(l=9;l=0;l-)/0-9数字按钮bl=new JButton(String.valueOf(l);bl.setForeground(Color.BLUE);dispLeft.add(bl);bl.addActionListe

10、ner(this); /监听设置bl.setFocusPainted(false); /去掉焦点框jia=new JButton(+);jian=new JButton(-);cheng=new JButton(*);chu=new JButton(/);xy=new JButton(xAy);cos=new JButton(cos);sin=new JButton(sin);ln=new JButton(ln);/ce=new JButton(CE);/清除equ=new JButton(=);/等号bfh=new JButton(%);/求模point=new JButton(.);/小数

11、点zf=new JButton( +/- );/ 正负号sqrt=new JButton( ,); 根号去掉焦点框去掉焦点框去掉焦点框去掉焦点框去掉焦点框去掉焦点框去掉焦点框去掉焦点框去掉焦点框去掉焦点框去掉焦点框去掉焦点框去掉焦点框jia.setFocusPainted(false); / jian.setFocusPainted(false); / cheng.setFocusPainted(false); / chu.setFocusPainted(false); / xy.setFocusPainted(false); / cos.setFocusPainted(false); / s

12、in.setFocusPainted(false); / ln.setFocusPainted(false); / ce.setFocusPainted(false); / equ.setFocusPainted(false); / bfh.setFocusPainted(false); / point.setFocusPainted(false); / zf.setFocusPainted(false); /sqrt.setFocusPainted(false); /去掉焦点框buttonconnect.setFocusPainted(false); /去掉焦点框/ 右面板 运算符按钮dis

13、pRight.add(chu);dispRight.add(sqrt);dispRight.add(ln);dispRight.add(cheng);dispRight.add(sin);dispRight.add(bfh);dispRight.add(jian);dispRight.add(cos);dispRight.add(ce);dispRight.add(jia);dispRight.add(xy);dispRight.add(equ);/ 左面板 正负号 / 小数点按钮dispLeft.add(zf);dispLeft.add(point);/ 按钮监听设置ce.addAction

14、Listener(this);jia.addActionListener(this);jian.addActionListener(this);cheng.addActionListener(this);chu.addActionListener(this);equ.addActionListener(this);point.addActionListener(this);zf.addActionListener(this);sqrt.addActionListener(this);bfh.addActionListener(this);sin.addActionListener(this);cos.addActionListener(this);xy.addActionListener(this);ln.addActionListener(this);buttonconnect.addActionListener(this);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setVisible(true);d1=0.0;d2=0.0;op=0;public void run()public void actionPerformed(ActionEvent e)if(e.getSource()=look

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

当前位置:首页 > 商业/管理/HR > 营销创新

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