- import java.awt.* ;
- import java.awt.event.* ;
- public class Java implements TextListener
- {
- TextField input = new TextField("") ;
- TextField usd = new TextField("") ;
- TextField jpy = new TextField("") ;
- TextField hkd = new TextField("") ;
- TextField gbp = new TextField("") ;
- TextField eur = new TextField("") ;
- public static void main(String args[])
- {
- Java java = new Java();
- java.start();
- }
- 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);
- p.add(new Label("日幣現值"));
- p.add(jpy);
- p.add(new Label("港幣現值"));
- p.add(hkd);
- p.add(new Label("英鎊現值"));
- p.add(gbp);
- p.add(new Label("日幣現值"));
- p.add(eur);
- 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);
- jpy.setText(""+originvalue*33.53);
- hkd.setText(""+originvalue*0.22);
- gbp.setText(""+originvalue*0.018);
- eur.setText(""+originvalue*0.03);
- }catch(Exception exc)
- {
- usd.setText("Unknown words");
- jpy.setText("Unknown words");
- hkd.setText("Unknown words");
- gbp.setText("Unknown words");
- eur.setText("Unknown words");
- }
-
- }
- }
複製代碼 不知此方法....可否? |