| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1402 人关注过本帖
标题:求教!这样的一个计算器怎样做啊?
只看楼主 加入收藏
macy
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2005-11-2
收藏
 问题点数:0 回复次数:19 
求教!这样的一个计算器怎样做啊?

我真的不会啊!请问各位高手这样的一个计算器怎样做啊?麻烦给出源代码?小女子感激不尽!

图片附件: 游客没有浏览图片的权限,请 登录注册

搜索更多相关主题的帖子: 计算器 
2005-11-02 12:58
曾阿牛
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2005-10-14
收藏
得分:0 
我前几天刚发了个帖子 也是个计算器的 和这个差不多 你自己看看吧 如果用的着的话 不过没有小数点

你自己改一改加上吧

什么时候才能成为论坛游民啊....
2005-11-02 13:27
macy
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2005-11-2
收藏
得分:0 

请问贴名是?

2005-11-02 13:56
macy
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2005-11-2
收藏
得分:0 
求求您给个源代码我拉,我真的一点都不会啊!
2005-11-02 14:05
飘飘叶子
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:34
帖 子:597
专家分:10
注 册:2005-8-17
收藏
得分:0 
楼主说的是这个样子的吧?
这个用的是JInternalFrame做出来的

向着软件工程师的目标前进!
2005-11-02 15:43
曾阿牛
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2005-10-14
收藏
得分:0 

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class jisuanqi extends JFrame{
private JButton JButton0;
private JButton JButton1;
private JButton JButton2;
private JButton JButton3;
private JButton JButton4;
private JButton JButton5;
private JButton JButton6;
private JButton JButton7;
private JButton JButton8;
private JButton JButton9;
private JButton JButtonjia;
private JButton JButtonjian;
private JButton JButtoncheng;
private JButton JButtonchu;
private JButton JButtondeng;
private JButton JButtonqing;
private JButton JButtontui;
private JTextField JTextField1;
static int fuhao;
static long shu;


public jisuanqi(){
createUserInterface();
}

public void createUserInterface(){
Container contentPane = getContentPane();
contentPane.setLayout( null );




JButton1 =new JButton();
JButton1.setText("1");
JButton1.setBounds(0,60,60,60);
contentPane.add(JButton1);
JButton1.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButton1ActionPerformed( event );
}
}

);

JButton2 =new JButton();
JButton2.setText("2");
JButton2.setBounds(60,60,60,60);
contentPane.add(JButton2);
JButton2.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButton2ActionPerformed( event );
}
}

);

JButton3 =new JButton();
JButton3.setText("3");
JButton3.setBounds(120,60,60,60);
contentPane.add(JButton3);
JButton3.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButton3ActionPerformed( event );
}
}

);

JButton4 =new JButton();
JButton4.setText("4");
JButton4.setBounds(0,120,60,60);
contentPane.add(JButton4);
JButton4.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButton4ActionPerformed( event );
}
}

);

JButton5 =new JButton();
JButton5.setText("5");
JButton5.setBounds(60,120,60,60);
contentPane.add(JButton5);
JButton5.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButton5ActionPerformed( event );
}
}

);

JButton6 =new JButton();
JButton6.setText("6");
JButton6.setBounds(120,120,60,60);
contentPane.add(JButton6);
JButton6.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButton6ActionPerformed( event );
}
}

);

JButton7 =new JButton();
JButton7.setText("7");
JButton7.setBounds(0,180,60,60);
contentPane.add(JButton7);
JButton7.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButton7ActionPerformed( event );
}
}

);

JButton8 =new JButton();
JButton8.setText("8");
JButton8.setBounds(60,180,60,60);
contentPane.add(JButton8);
JButton8.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButton8ActionPerformed( event );
}
}

);

JButton9 =new JButton();
JButton9.setText("9");
JButton9.setBounds(120,180,60,60);
contentPane.add(JButton9);
JButton9.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButton9ActionPerformed( event );
}
}

);

JButton0 =new JButton();
JButton0.setText("0");
JButton0.setBounds(60,240,60,60);
contentPane.add(JButton0);
JButton0.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButton0ActionPerformed( event );
}
}

);

JButtonjia =new JButton();
JButtonjia.setText("+");
JButtonjia.setBounds(180,60,60,60);
contentPane.add(JButtonjia);
JButtonjia.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButtonjiaActionPerformed( event );
}
}

);

JButtonjian =new JButton();
JButtonjian.setText("-");
JButtonjian.setBounds(180,120,60,60);
contentPane.add(JButtonjian);
JButtonjian.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButtonjianActionPerformed( event );
}
}

);

JButtoncheng =new JButton();
JButtoncheng.setText("*");
JButtoncheng.setBounds(180,180,60,60);
contentPane.add(JButtoncheng);
JButtoncheng.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButtonchengActionPerformed( event );
}
}

);

JButtonchu =new JButton();
JButtonchu.setText("/");
JButtonchu.setBounds(180,240,60,60);
contentPane.add(JButtonchu);
JButtonchu.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButtonchuActionPerformed( event );
}
}

);

JButtondeng =new JButton();
JButtondeng.setText("=");
JButtondeng.setBounds(120,240,60,60);
contentPane.add(JButtondeng);
JButtondeng.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButtondengActionPerformed( event );
}
}

);

JButtonqing =new JButton();
JButtonqing.setText("清0");
JButtonqing.setBounds(0,240,60,60);
contentPane.add(JButtonqing);
JButtonqing.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButtonqingActionPerformed( event );
}
}

);

JButtontui =new JButton();
JButtontui.setText("退格");
JButtontui.setBounds(180,0,60,60);
contentPane.add(JButtontui);
JButtontui.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event ){
JButtontuiActionPerformed( event );
}
}

);

JTextField1 = new JTextField();
JTextField1.setText( "0" );
JTextField1.setBounds( 20, 20, 140, 20 );
JTextField1.setHorizontalAlignment( JTextField.RIGHT );
contentPane.add( JTextField1 );
setTitle("jisuanqi");
this.setSize(240,360);
this.setVisible(true);


}
private void JButton1ActionPerformed( ActionEvent event ){
long a,b;
a=Integer.parseInt( JTextField1.getText() );
b=a*10+1;
JTextField1.setText( String.valueOf(b) );
}

private void JButton2ActionPerformed( ActionEvent event ){
long a,b;
a=Integer.parseInt( JTextField1.getText() );
b=a*10+2;
JTextField1.setText( String.valueOf(b) );
}

private void JButton3ActionPerformed( ActionEvent event ){
long a,b;
a=Integer.parseInt( JTextField1.getText() );
b=a*10+3;
JTextField1.setText( String.valueOf(b) );
}

private void JButton4ActionPerformed( ActionEvent event ){
long a,b;
a=Integer.parseInt( JTextField1.getText() );
b=a*10+4;
JTextField1.setText( String.valueOf(b) );
}

private void JButton5ActionPerformed( ActionEvent event ){
long a,b;
a=Integer.parseInt( JTextField1.getText() );
b=a*10+5;
JTextField1.setText( String.valueOf(b) );
}

private void JButton6ActionPerformed( ActionEvent event ){
long a,b;
a=Integer.parseInt( JTextField1.getText() );
b=a*10+6;
JTextField1.setText( String.valueOf(b) );
}

private void JButton7ActionPerformed( ActionEvent event ){
long a,b;
a=Integer.parseInt( JTextField1.getText() );
b=a*10+7;
JTextField1.setText( String.valueOf(b) );
}

private void JButton8ActionPerformed( ActionEvent event ){
long a,b;
a=Integer.parseInt( JTextField1.getText() );
b=a*10+8;
JTextField1.setText( String.valueOf(b) );
}

private void JButton9ActionPerformed( ActionEvent event ){
long a,b;
a=Integer.parseInt( JTextField1.getText() );
b=a*10+9;
JTextField1.setText( String.valueOf(b) );
}

private void JButton0ActionPerformed( ActionEvent event ){
long a=0,b=0;
if( JTextField1.getText()==""||Integer.parseInt( JTextField1.getText() )==0)
JTextField1.setText(String.valueOf(b));
else {a=Integer.parseInt( JTextField1.getText() );b=a*10;}
JTextField1.setText( String.valueOf(b) );
}

private void JButtonqingActionPerformed( ActionEvent event ){
JTextField1.setText( String.valueOf(0) );
}

private void JButtontuiActionPerformed( ActionEvent event ){
long a,b;
a=Integer.parseInt( JTextField1.getText() );
if(a<=10) JTextField1.setText( String.valueOf(0) );
else{b=a%10;a=(a-b)/10;JTextField1.setText( String.valueOf(a) );}
}

private void JButtonjiaActionPerformed( ActionEvent event ){
fuhao=1;
shu=Integer.parseInt( JTextField1.getText() );
JTextField1.setText( String.valueOf(0) );
}

private void JButtonjianActionPerformed( ActionEvent event ){
fuhao=2;
shu=Integer.parseInt( JTextField1.getText() );
JTextField1.setText( String.valueOf(0) );
}

private void JButtonchengActionPerformed( ActionEvent event ){
fuhao=3;
shu=Integer.parseInt( JTextField1.getText() );
JTextField1.setText( String.valueOf(0) );
}

private void JButtonchuActionPerformed( ActionEvent event ){
fuhao=4;
shu=Integer.parseInt( JTextField1.getText() );
JTextField1.setText( String.valueOf(0) );
}

private void JButtondengActionPerformed( ActionEvent event ){
long a;
long b=Integer.parseInt( JTextField1.getText() );
if(fuhao==1) {a=b+shu;JTextField1.setText( String.valueOf(a) );}
else if(fuhao==2) {a=shu-b;JTextField1.setText( String.valueOf(a) );}
else if(fuhao==3) {a=b*shu;JTextField1.setText( String.valueOf(a) );}
else if(fuhao==4) {a=shu/b;JTextField1.setText( String.valueOf(a) );}
}

public static void main( String[] args ){
jisuanqi application = new jisuanqi();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}


什么时候才能成为论坛游民啊....
2005-11-02 22:08
a548475
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2005-10-25
收藏
得分:0 

兄弟a*10 是什么意思啊.

2005-11-03 11:57
a548475
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2005-10-25
收藏
得分:0 

真是厉害啊.
2005-11-03 12:26
anromee
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2004-11-22
收藏
得分:0 

用个循环可以让代码更精练


2005-11-05 13:02
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 

to 曾啊牛

首先,我必须敬佩你的毅力~~你让我想起以前的我,也是那么的热情,那么的有精力

但是,我必须还是得说:这样写这个软件!
you make a mistake!

我们先说实现的细节错误
1.对于一个计算器,我们一接手马上就应该意识到,要检查除数不能为0!!!这也是我测试的第一个计算! 很遗憾,你没通过...
2.输出的“液晶”显示屏你是用个JTextarea代替的,这很对,但是你也要设置一下不能编辑吧,如果我往里面输入的字母,你知道会发生什么情况吗?

再说说实现的设计错误
1.难道你打了那么多的JButton就没意识到,其实这是可以作为一个类的么!这样连楼9的意思都不用~
2.写swing的时候,极力不推荐采用坐标方式安插对象,比如JButton2.setBounds(60, 60, 60, 60);因为只要用户一旦改变了分辨率,你这个坐标就全乱了,当然这个对这个计算器那么小的项目来说根本就没有用Layout Managers的必要,但是为了你的以后的大设计中不出现这样的代码,我还是忍不住和你说说。

最后我还要说说整个程序的设计错误~
界面设计应该要与逻辑设计相分离,对于这个错误嘛~~你同样也可以不理会,这个要求是有点苛刻了的,起码对于这个小小的计算器来说,但是我记得我也是从计算器学起的。

我说那么多,其实不是针对这个计算器的,这个计算器除了我前面说的那些实现的错误以外,其他还算是勉强的,特别是这个程序的ActionListener的实现让我又学会了一个实现的方法~谢谢
我看了你最近的帖子,知道你要做一个药店管理的软件~~根据你现在的知识,我想你应该是打算往C/S方向发展的。祝你顺利~

我早在几个月前(呵呵,现在的电脑知识都是按月计的)就放弃了java的桌面应用程序设计~因为java在桌面应用上是不可能和已经完全绑定、整合到windows操作系统的vc++、c#相比的。Linux/unix下java就更加慢了~要知道玩Linux/Unix的人不是网管就是C语言N牛的程序设计员...


淘宝杜琨
2005-11-05 17:03
快速回复:求教!这样的一个计算器怎样做啊?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017768 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved