aaarong
发贴: 24
积分: 0
|
于 2007-05-13 18:11
/* <applet code="Example1" width=300 height=60> </applet> */ import java.awt.*; import java.applet.*; import java.awt.event.*;
public class Example1 extends Applet implements ActionListener{ TextField tf1; TextField tf2; TextField tf3; Button bt1; Button bt2; Button bt3; Button bt4; float count,k,p; String i,j; public void init(){ tf1=new TextField("输入一个数字",10); tf2=new TextField("输入一个数字",10); tf3=new TextField(); bt1=new Button("加"); bt2=new Button("减"); bt3=new Button("乘"); bt4=new Button("除"); add(tf1); add(tf2); add(tf3); add(bt1); add(bt2); add(bt3); add(bt4); bt1.addActionListener(this); bt2.addActionListener(this); bt3.addActionListener(this); bt4.addActionListener(this); } public void actionPerformed(ActionEvent e){ if(e.getSource()==bt1) { i=tf1.getText(); j=tf2.getText(); k=Float.parseFloat; p=Float.parseFloat(j); count=k+p; } if(e.getSource()==bt2) { i=tf1.getText(); j=tf2.getText(); k=Float.parseFloat; p=Float.parseFloat(j); count=k-p; } if(e.getSource()==bt3) { i=tf1.getText(); j=tf2.getText(); k=Float.parseFloat; p=Float.parseFloat(j); count=k*p; } if(e.getSource()==bt4) { i=tf1.getText(); j=tf2.getText(); k=Float.parseFloat; p=Float.parseFloat(j); count=k/p; } tf3.setText(""+count); } }
|