import java.awt.* ;
import java.awt.event.* ;
public class TQC301 implements TextListener
{
TextField input = new TextField("") ;
TextField usd = new TextField("") ; // 美金現值
public void start()
{
Frame f = new Frame("各國貨幣換算") ;
f.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
f.setSize(400,300);
//註冊事件處理函式
input.addTextListener(this) ;
//請在此撰寫程式碼
Panel p = new Panel();
p.setLayout(new GridLayout(5,2));
p.add(new Label("美金現值"));
p.add(usd);
f.add(input,"South");
f.add(p,"North");
f.setVisible(true);
//請在此撰寫程式碼
}
public void textValueChanged(TextEvent e)
{
String origin = input.getText() ;
int originvalue = 0 ;
try
{
originvalue = Integer.parseInt(origin);
usd.setText(""+originvalue*0.029);
}catch(Exception exc)
{
usd.setText("請勿輸入非數字的字元");
}
}
public static void main(String args[])
{
//請在此撰寫程式碼
TQC301 jva = new TQC301();
jva.start();
//請在此撰寫程式碼
}
} |