import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestInOut
{
public static void main(String args[])
{
new FrameInOut();
}
}
class FrameInOut extends Frame implements ActionListener
{
Label prompt;
TextField output,output1,output2;
Button btn,input;
FrameInOut()
{
super("图形界面的Java Application程序员");
prompt =new Label("请输入一个浮点数:");
input=new Button("计算");
output=new TextField(20);
output1=new TextField(20);
output2=new TextField(20);
btn=new Button("关闭");
setLayout(new FlowLayout());
add(prompt);
add(input);
add(output);
add(output1);
add(output2);
add(btn);
input.addActionListener(this);
btn.addActionListener(this);
setSize(300,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==input){
String a=null;
a=output.getText();
String[] resultValue=a.split("\\.");//注意split方法的转意方式,默认的事逗号
output1.setText(resultValue[0]);
output2.setText(resultValue[1]);
}
else{
dispose();
System.exit(0);
}
}
}