Presentation is loading. Please wait.

Presentation is loading. Please wait.

Button 元件. public class ko12_1 extends Applet implements ActionListener { Label lb=new Label(" 輸入密碼 :"); TextField tf1=new TextField(25); Button bn=new.

Similar presentations


Presentation on theme: "Button 元件. public class ko12_1 extends Applet implements ActionListener { Label lb=new Label(" 輸入密碼 :"); TextField tf1=new TextField(25); Button bn=new."— Presentation transcript:

1 Button 元件

2

3

4 public class ko12_1 extends Applet implements ActionListener { Label lb=new Label(" 輸入密碼 :"); TextField tf1=new TextField(25); Button bn=new Button(" 結果 "); TextField tf2=new TextField(25); public void init() { add(lb); add(tf1); tf1.setEchoChar('*'); add(bn); add(tf2); bn.addActionListener(this); }

5 Button 元件 public void actionPerformed(ActionEvent e) { if (e.getSource()==bn) { if (Integer.parseInt(tf1.getText())==123456) tf2.setText(" 正確 !!"); else tf2.setText(" 錯誤 !!"); }

6 Button 元件

7

8 import java.applet.*; import java.awt.*; import java.awt.event.*; public class ko12_4 extends Applet implements ActionListener { TextField tf1=new TextField(10), tf2=new TextField(10); Label lb1=new Label("**** 徑度與角度的轉換 ****"), lb2=new Label(" 輸入徑度 :"), lb3=new Label(" 輸出角度 :"); Button bn=new Button(" 轉換結果 ");

9 Button 元件 public void init() { add(lb1); add(lb2); add(tf1); add(lb3); add(tf2); add(bn); bn.addActionListener(this); }

10 Button 元件 public void actionPerformed(ActionEvent e) { String s; if (e.getSource()==bn) { s=String.valueOf(Math.toDegrees(Double.parseDouble(tf1.getText()))); tf2.setText(s); }

11 Button 元件

12

13

14 import java.applet.*; import java.awt.*; import java.awt.event.*; public class ko12_5 extends Applet implements ActionListener { TextField tf1=new TextField(6), tf2=new TextField(6), tf3=new TextField(6), tf4=new TextField(6); Label lb1=new Label("* 求最大公因數及最小公倍數 *"), lb2=new Label(" 輸入第一個數值 :"), lb3=new Label(" 輸入第二個數值 :"),

15 Button 元件 lb4=new Label(" 輸出最大公因數 :"), lb5=new Label(" 輸出最小公倍數 :"); Button bn=new Button(" 輸出結果 "); public void init() { add(lb1); add(lb2); add(tf1); add(lb3); add(tf2); add(lb4); add(tf3); add(lb5); add(tf4); add(bn); bn.addActionListener(this); }

16 Button 元件 public void actionPerformed(ActionEvent e) { int x,y,z,a,b,gcd,lcm; String s,t; x=Integer.parseInt(tf1.getText()); y=Integer.parseInt(tf2.getText()); a=x; b=y; while(y!=0) { z=x%y; x=y; y=z; }

17 Button 元件 gcd=x; lcm=a*b/gcd; if (e.getSource()==bn) { s=String.valueOf(gcd); t=String.valueOf(lcm); tf3.setText(s); tf4.setText(t); }


Download ppt "Button 元件. public class ko12_1 extends Applet implements ActionListener { Label lb=new Label(" 輸入密碼 :"); TextField tf1=new TextField(25); Button bn=new."

Similar presentations


Ads by Google