Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:关于计算器显示的问题(菜菜的问题) [Re:xuxiang84]
xuxiang84





发贴: 23
积分: 0
于 2004-10-03 18:54 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.lang.String;
import java.lang.Integer;
public class jisuanqi extends Applet implements ActionListener
{
static String xianshi;
static float caozuoshu,jieguo;
int biaoji,yunsuanfu,zhengfuhao;

TextField text;
Button n1,n2,n3,n4,n5,n6,n7,n8,n9,n0,point,minus,plus,subtract,multiply,divild,equal,back,ce;

public void init()
{
xianshi=new String("");
caozuoshu=0;
jieguo=0;
biaoji=-1;
yunsuanfu=0;
zhengfuhao=0;


text=new TextField(11);
text.setEditable(false);
text.setText("");

n1=new Button("1");
n2=new Button("2");
n3=new Button("3");
n4=new Button("4");
n5=new Button("5");
n6=new Button("6");
n7=new Button("7");
n8=new Button("8");
n9=new Button("9");
n0=new Button("0");
point=new Button(".");
minus=new Button("-/+");
plus=new Button("+");
subtract=new Button("-");
multiply=new Button("*");
divild=new Button("/");
equal=new Button("=");
back=new Button("back");
ce=new Button("ce");

add(text);
add(n1);
add(n2);
add(n3);
add(n4);
add(n5);
add(n6);
add(n7);
add(n8);
add(n9);
add(n0);
add(point);
add(minus);
add(plus);
add(subtract);
add(multiply);
add(divild);
add(equal);
add(back);
add(ce);

n1.addActionListener(this);
n2.addActionListener(this);
n3.addActionListener(this);
n4.addActionListener(this);
n5.addActionListener(this);
n6.addActionListener(this);
n7.addActionListener(this);
n8.addActionListener(this);
n9.addActionListener(this);
n0.addActionListener(this);
point.addActionListener(this);
minus.addActionListener(this);
plus.addActionListener(this);
subtract.addActionListener(this);
multiply.addActionListener(this);
divild.addActionListener(this);
equal.addActionListener(this);
back.addActionListener(this);
ce.addActionListener(this);

}


public void actionPerformed(ActionEvent e)
{
if(e.getSource()==n1)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"1";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n2)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"2";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n3)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"3";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n4)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"4";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n5)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"5";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n6)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"6";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n7)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"7";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n8)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"8";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n9)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"9";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n0)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"0";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==point)
{if(biaoji==1){xianshi="";biaoji=0;}
if(xianshi.indexOf('.')==-1)
{xianshi=xianshi+".";}
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==minus)
{if(biaoji==1){xianshi="";biaoji=0;}
if(xianshi.indexOf('-')==-1)
{xianshi="-"+xianshi;}
else
{xianshi=xianshi.substring(1,xianshi.length());}
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}

else if(e.getSource()==plus)
{caozuoshu=0;biaoji=1;yunsuanfu=1;
}
else if(e.getSource()==subtract)
{caozuoshu=0;biaoji=1;yunsuanfu=2;

}
else if(e.getSource()==multiply)
{
caozuoshu=0;biaoji=1;yunsuanfu=3;
}
else if(e.getSource()==divild)
{
caozuoshu=0;biaoji=1;yunsuanfu=4;
}
else if(e.getSource()==equal)
{if(yunsuanfu==1){jieguo=jieguo+caozuoshu;biaoji=1;text.setText(xianshi=String.valueOf(jieguo));}
if(yunsuanfu==2){jieguo=jieguo-caozuoshu;biaoji=1;text.setText(xianshi=String.valueOf(jieguo));}
if(yunsuanfu==3){jieguo=jieguo*caozuoshu;biaoji=1;text.setText(xianshi=String.valueOf(jieguo));}
if(yunsuanfu==4){jieguo=jieguo/caozuoshu;biaoji=1;text.setText(xianshi=String.valueOf(jieguo));}
}

else if(e.getSource()==back)
{
xianshi=xianshi.substring(0,xianshi.length()-1);
caozuoshu=Integer.parseFlaot(xianshi);

text.setText(xianshi);}
else if(e.getSource()==ce)
{
xianshi=new String("");
caozuoshu=0;
jieguo=0;
biaoji=-1;
yunsuanfu=0;
text.setText(xianshi);}


why edited on 2004-10-03 21:35


Hibernate的优点

话题树型展开
人气 标题 作者 字数 发贴时间
6748 关于计算器显示的问题(菜菜的问题) xuxiang84 62 2004-09-28 21:12
5933 Re:关于计算器显示的问题(菜菜的问题) 三角梅 7 2004-09-29 15:13
6053 Re:关于计算器显示的问题(菜菜的问题) eric_dasini 25 2004-09-29 16:14
5941 Re:关于计算器显示的问题(菜菜的问题) xuxiang84 63 2004-10-03 18:53
6427 Re:关于计算器显示的问题(菜菜的问题) xuxiang84 6975 2004-10-03 18:54
5744 Re:关于计算器显示的问题(菜菜的问题) Jason_zhu85 20 2004-10-03 22:41
5703 Re:关于计算器显示的问题(菜菜的问题) hvbird 18 2004-10-05 00:04
5888 Re:关于计算器显示的问题(菜菜的问题) xuxiang84 44 2004-10-05 03:38
6001 Re:关于计算器显示的问题(菜菜的问题) xuxiang84 60 2004-10-09 16:49

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923