java计算器的图形用户界面代码_java图形用户界面-计算器.

import java.awt.*; import java.awt.event.*; public class jisuanqi extends Frame implements WindowListener, ActionListener { Button but1,but2,but3,but4,but5; Label lab; TextField text1,text2,text3; jisuanqi( { super("计算器"; setSize(400,150; setLayout(new GridLayout(3,4,10,2; Font f=new Font("楷体

",Font.ITALIC+Font.BOLD,20; setFont(f; but1=new Button("+"; but2=new Button("-"; but3=new Button("*"; but4=new Button("/"; but5=new Button("清除"; lab=new

Label("="; text1=new TextField(; text2=new TextField(; text3=new TextField(;

add(text1;add(text2;add(lab;add(text3;add(but1;add(but2;add(but3; add(but4;add(new Label(;add(new Label(;add(new Label(;add(but5; but1.addActionListener(this;

but2.addActionListener(this; but3.addActionListener(this; but4.addActionListener(this; but5.addActionListener(this; addWindowListener(this; setVisible(true; } public void actionPerformed(ActionEvent e { double a=Double.parseDouble(text1.getText(; Double b=Double.parseDouble(text2.getText(; if(e.getSource(==but1 { //Float

m=Float.valueOf(text1.getText(+Float.valueOf(text2.getText(; double m=a+b;

text3.setText(""+m; } if(e.getSource(==but2 { //Float m=Float.valueOf(text1.getText(-Float.valueOf(text2.getText(; double m=a-b; text3.setText(""+m; } if(e.getSource(==but3 { //Float m=Float.valueOf(text1.getText(*Float.valueOf(text2.getText(; double m=a*b; text3.setText(""+m; } if(e.getSource(==but4 { if(b==0 { text1.setText("";

text2.setText(""; text3.setText(""; } else { //Float

m=Float.valueOf(text1.getText(/Float.valueOf(text2.getText(; double m=a/b;

text3.setText(""+m; } } if(e.getSource(==but5 { text1.setText(""; text2.setText("";

text3.setText(""; } } public void windowClosing(WindowEvent e { Window

ww=(Windowe.getSource(; ww.setVisible(false; ww.dispose(; } public void windowActivated(WindowEvent e{} public void windowClosed(WindowEvent e {} public void windowDeactivated(WindowEvent e{} public void

windowDeiconified(WindowEvent e{} public void windowIconified(WindowEvent e {} public void windowOpened(WindowEvent e {} public static void main(String[] args { new jisuanqi(; } }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值