首页 > 其他 > 详细

计算器

时间:2015-10-06 10:19:35      阅读:224      评论:0      收藏:0      [点我收藏+]

public class Tes

{

   static TestField tf1;static TestField tf2;static Choice choice;static TestField tf3;

  public static void main(String[]args)

{

  Frame frame=new Frame("计算器");

frame.setSize(300,200);

frame.setLocation(300,200);

frame.addWindowListener(new Listener());

final TestField tf1=new TestField(8);

final Choice choice=new Choice();

choice.addItem("+");

choice.addItem("-");

choice.addItem("*");

choice.addItem("/");

final TestField tf2=new TestField(8);

Lable lable =new Lable("=");

final TestField tf3=new TestField(8);

Button button=new Button("计算器");

frame.add(tf1);

frame.add(choice);

frame.add(tf2);

frame.add(Lable);

frame.add(tf3);

frame.add(button);

frame.setLayout(new flowLayout());

{

@override

public void actionperformed(ActionEvent argo)

{

String s1=tf1.get Test();

String s2=tf2.getTest();

String ch=Choice.getSelectedItem();

double d1=Double.parseDouble(s1);

double d2=Double.parseDouble(s2);

double d=0;

if(ch.equals("+"))

{

d=d1+d2;

}

else if(ch.equals("-"))

{

d=d1*d2;

}

else

{

d=d1/d2;

}

tf3.setTest(d+"");

}

})

frame.setVisible(true);

}

}

计算器

原文:http://www.cnblogs.com/zql0514/p/4856710.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!