01 import java.awt.*; 02 import java.awt.event.*; 03 04 public class rep7_1 extends Frame { 05 Button b0 = new Button("Even/Odd?"); 06 Label x0 = new Label("Type a number and press..."); 07 TextField t0 = new TextField(); 08 09 public rep7_1() { 10 setLayout(null); 11 add(t0); t0.setBounds(10, 40, 90, 30); 12 add(b0); b0.setBounds(110, 40, 80, 30); 13 add(x0); x0.setBounds(10, 80, 180, 30); 14 b0.addActionListener(new ActionListener() { 15 public void actionPerformed(ActionEvent evt) { 16 int i = (new Integer(t0.getText())).intValue(); 17 t0.setText(""); 18 if(i % 2 == 0) { 19 x0.setText(i + " is Even"); 20 } else { 21 x0.setText(i + " is Odd"); 22 } 23 } 24 }); 25 } 26 public static void main(String[] args) { 27 Frame win = new rep7_1(); 28 win.setSize(200, 150); win.setVisible(true); 29 win.addWindowListener(new WindowAdapter() { 30 public void windowClosing(WindowEvent evt) { 31 System.exit(0); 32 } 33 }); 34 } 35 }
01 import java.awt.*; 02 import java.awt.event.*; 03 04 public class rep7_1 extends Frame { 05 Button b0 = new Button("Even/Odd?"); 06 Label x0 = new Label("Type a number and press..."); 07 TextField t0 = new TextField(); 08 09 public rep7_1() { 10 setLayout(null); 11 add(t0); t0.setBounds(10, 40, 90, 30); 12 add(b0); b0.setBounds(110, 40, 80, 30); 13 add(x0); x0.setBounds(10, 80, 180, 30); 14 b0.addActionListener(new ActionListener() { 15 public void actionPerformed(ActionEvent evt) { 16 try{ 17 int i = (new Integer(t0.getText())).intValue(); 18 t0.setText(""); 19 if(i % 2 == 0) { 20 x0.setText(i + " is Even"); 21 } else { 22 x0.setText(i + " is Odd"); 23 } 24 } 25 catch(NumberFormatException ee) 26 {x0.setText("error");} 27 28 } 29 }); 30 } 31 public static void main(String[] args) { 32 Frame win = new rep7_1(); 33 win.setSize(200, 150); win.setVisible(true); 34 win.addWindowListener(new WindowAdapter() { 35 public void windowClosing(WindowEvent evt) { 36 System.exit(0); 37 } 38 }); 39 } 40 }
import java.awt.*; import java.awt.event.*; public class rep7_2 extends Frame { Button b0 = new Button(" 送信 "); Label x0 = new Label(" 名前 "); Label x1 = new Label(" 年齢 "); Label x2 = new Label(" 家族構成 "); Label x3 = new Label(" 性別 "); Label x4 = new Label(); TextField t0 = new TextField(); Checkbox o0 = new Checkbox(" 父 "); Checkbox o1 = new Checkbox(" 母 "); Checkbox o2 = new Checkbox(" 兄 "); Checkbox o3 = new Checkbox(" 姉 "); Checkbox o4 = new Checkbox(" 弟 "); Checkbox o5 = new Checkbox(" 妹 "); Checkbox o6 = new Checkbox(" 祖父"); Checkbox o7 = new Checkbox(" 祖母"); Choice c1 = new Choice(); List l1 = new List(); public rep7_2() { setLayout(null); add(b0); b0.setBounds(150, 250, 60, 20); add(x0); x0.setBounds(25, 20, 80, 20); add(x1); x1.setBounds(150, 20, 80, 20); add(x2); x2.setBounds(25, 80, 80, 20); add(x3); x3.setBounds(290, 20, 80, 20); add(x4); x4.setBounds(150, 270, 120, 20); add(t0); t0.setBounds(10, 40, 100, 20); add(o0); o0.setBounds(25, 110, 80, 20); add(o1); o1.setBounds(150, 110, 80, 20); add(o2); o2.setBounds(275, 110, 80, 20); add(o3); o3.setBounds(25, 150, 80, 20); add(o4); o4.setBounds(150, 150, 80, 20); add(o5); o5.setBounds(275, 150, 80, 20); add(o6); o6.setBounds(25, 190, 80, 20); add(o7); o7.setBounds(150, 190, 80, 20); add(c1); c1.setBounds(180, 40, 80, 20); c1.add("15 Old"); c1.add("16 Old"); c1.add("17 Old"); c1.add("18 Old"); c1.add("19 Old"); c1.add("20 Old"); c1.add("21 Old"); c1.add("22 Old"); c1.add("23 Old"); add(l1); l1.setBounds(350, 40, 80, 40); l1.add(" 男 "); l1.add(" 女 "); b0.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { x4.setText(" 登録しました。"); } }); } public static void main(String[] args) { Frame win = new rep7_2(); win.setSize(500, 300); win.setVisible(true); win.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); } }
import java.awt.*; import java.awt.event.*; public class rep7_3 extends Frame{ Button b0 = new Button("摂氏から華氏へ"); Button b1 = new Button("華氏から摂氏へ"); Label x0 = new Label("変換ボタンを押してください。"); Label x1 = new Label("変換後"); TextField t0 = new TextField(); TextField t1 = new TextField(); public rep7_3(){ setLayout(null); add(x0); x0.setBounds(50, 40, 150, 20); add(x1); x1.setBounds(165, 60, 60, 20); add(t0); t0.setBounds(50, 80, 60, 20); add(t1); t1.setBounds(150, 80, 60, 20); add(b0); b0.setBounds(70, 120, 100, 20); add(b1); b1.setBounds(70, 150, 100, 20); b0.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try{ int i = (new Integer(t0.getText())).intValue(); t1.setText("" + i*1.8+32); }catch(Exception ex) { t1.setText("error"); } } }); b1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try{ int i = (new Integer(t0.getText())).intValue(); t1.setText("" + (i-32)/1.8); }catch(Exception ex) { t1.setText("error"); } } }); } public static void main(String[] args) { Frame win = new rep7_3(); win.setSize(300, 200); win.setVisible(true); win.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); } }
import java.awt.*; import java.awt.event.*; public class rep7_4 extends Frame { Button b0 = new Button("+"); Button b1 = new Button("-"); Button b2 = new Button("*"); Button b3 = new Button("/"); Label x0 = new Label("Type a number and press..."); TextField t0 = new TextField(); TextField t1 = new TextField(); public rep7_4() { setLayout(null); add(t0); t0.setBounds(10, 40, 90, 30); add(t1); t1.setBounds(110, 40, 90, 30); add(b0); b0.setBounds(10, 80, 80, 30); add(b1); b1.setBounds(110, 80, 80,30); add(b2); b2.setBounds(10,110, 80, 30); add(b3); b3.setBounds(110,110, 80, 30); add(x0); x0.setBounds(10, 140, 180, 30); b0.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int i = (new Integer(t0.getText())).intValue(); int y =(new Integer(t1.getText())).intValue(); { x0.setText(i+y+""); } } }); b1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int i = (new Integer(t0.getText())).intValue(); int y =(new Integer(t1.getText())).intValue(); { x0.setText(i-y+""); } } }); b2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int i = (new Integer(t0.getText())).intValue(); int y =(new Integer(t1.getText())).intValue(); { x0.setText(i*y+""); } } }); b3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { float i = (new Integer(t0.getText())).floatValue(); float y =(new Integer(t1.getText())).floatValue(); { x0.setText(i/y+""); } } }); } public static void main(String[] args) { Frame win = new rep7_4(); win.setSize(210, 200); win.setVisible(true); win.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); } }