01:import java.awt.*; 02:import java.awt.event.*; 03: 04:public class GUIaa 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 GUIaa() { 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 GUIaa(); 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 GUI extends Frame{ 05: Button b0 = new Button(); 06: TextField t0 = new TextField(); 07: Label l0 = new Label(""); 08: TextArea ta0 = new TextArea(""); 09: Checkbox cb0 = new Checkbox(); 10: Choice ch0 = new Choice(); 11: List ls0 = new List(); 12: 13: public GUI(){ 14: setLayout(null); 15: add( b0); b0.setBounds(130, 30, 70, 30); 16: add( t0); t0.setBounds( 50, 80,150, 15); 17: add( l0); l0.setBounds( 50, 60,150, 30); 18: add(ta0); ta0.setBounds( 50, 110,150, 80); 19: add(cb0); cb0.setBounds(110, 30, 30, 30); 20: 21: ch0.add("1"); ch0.add("2"); ch0.add("3"); 22: ch0.add("4"); ch0.add("5"); ch0.add("6"); 23: add(ch0); ch0.setBounds( 50, 30, 30, 30); 24: 25: ls0.add("1"); ls0.add("2"); ls0.add("3"); 26: ls0.add("4"); ls0.add("5"); ls0.add("6"); 27: ls0.add("7"); ls0.add("8"); ls0.add("9"); 28: add(ls0); ls0.setBounds( 10, 30, 30, 160); 29: 30: b0.addActionListener(new ActionListener() { 31: public void actionPerformed(ActionEvent evt){ 32: if(cb0.getState()){ 33: t0.setText(ls0.getSelectedItem() + "年連続" + ch0.getSelectedItem() + "回目の出場"); 34: l0.setText(ls0.getSelectedItem() + "年連続" + ch0.getSelectedItem() + "回目の出場"); 35: ta0.setText(ls0.getSelectedItem() + "年連続" + ch0.getSelectedItem() + "回目の出場"); 36: } else { 37: t0.setText(ls0.getSelectedItem() + "年ぶり" + ch0.getSelectedItem() + "回目の出場"); 38: l0.setText(ls0.getSelectedItem() + "年ぶり" + ch0.getSelectedItem() + "回目の出場"); 39: ta0.setText(ls0.getSelectedItem() + "年ぶり" + ch0.getSelectedItem() + "回目の出場"); 40: } 41: } 42: }); 43: } 44: 45: public static void main(String argv[]){ 46: Frame win = new GUI(); 47: win.setSize(400, 320); 48: win.setVisible(true); 49: } 50:} |
01:import java.awt.*; 02:import java.awt.event.*; 03: 04:public class kansan extends Frame { 05: 06: Button b0 = new Button("摂氏→華氏"); 07: Button b1 = new Button("華氏→摂氏"); 08: Button b2 = new Button("Clear"); 09: Label x0 = new Label("入力"); 10: Label x1 = new Label("結果"); 11: TextField t0 = new TextField(); 12: TextField t1 = new TextField(); 13: 14: public kansan() { 15: setLayout(null); 16: add(x0); x0.setBounds(10, 25, 30, 30); 17: add(t0); t0.setBounds(10, 55, 100, 30); 18: add(x1); x1.setBounds(10, 95, 30, 30); 19: add(t1); t1.setBounds(10, 125, 100, 30); 20: add(b0); b0.setBounds(120, 30, 100, 30); 21: add(b1); b1.setBounds(120, 60, 100, 30); 22: add(b2); b2.setBounds(120, 150, 100, 30); 23: 24: b0.addActionListener(new ActionListener() { 25: public void actionPerformed(ActionEvent evt) { 26: try { 27: int i = (new Integer(t0.getText())).intValue(); 28: t1.setText("" + (i*1.8+32)); 29: } catch(NumberFormatException ee){ 30: t1.setText("Error!");} 31: } 32: }); 33: 34: b1.addActionListener(new ActionListener() { 35: public void actionPerformed(ActionEvent evt) { 36: try { 37: int i = (new Integer(t0.getText())).intValue(); 38: t1.setText("" + ((i-32)/1.8)); 39: } catch(NumberFormatException ee){ 40: t1.setText("Error!");} 41: } 42: }); 43: b2.addActionListener(new ActionListener(){ 44: public void actionPerformed(ActionEvent evt) { 45: try{ 46: t0.setText(""); t1.setText(""); 47: } catch(NumberFormatException ee){} 48: } 49: }); 50: } 51: 52: public static void main(String[] args) { 53: Frame win = new kansan(); 54: win.setSize(250, 200); win.setVisible(true); 55: win.addWindowListener(new WindowAdapter() { 56: public void windowClosing(WindowEvent evt) { 57: System.exit(0); 58: } 59: }); 60: } 61:} |
数値を入力(摂氏→華氏) 数値を入力(華氏→摂氏) |
001: import java.awt.*; 002: import java.awt.event.*; 003: 004: public class dentaku extends Frame{ 005: int a = 0; 006: Button b0 = new Button("Clear"); 007: Button b1 = new Button("+"); 008: Button b2 = new Button("-"); 009: Button b3 = new Button("*"); 010: Button b4 = new Button("/"); 011: Button b5 = new Button("%"); 012: Button b6 = new Button("="); 013: Button b7 = new Button("continue?"); 014: TextField t0 = new TextField(); 015: TextField t1 = new TextField(); 016: TextField t2 = new TextField(); 017: Label x0 = new Label(); 018: Label x1 = new Label("="); 019: 020: public dentaku(){ 021: setLayout(null); 022: add(b0); b0.setBounds(275,100, 100, 30); 023: add(b1); b1.setBounds( 10, 30, 50, 30); 024: add(b2); b2.setBounds( 60, 30, 50, 30); 025: add(b3); b3.setBounds(110, 30, 50, 30); 026: add(b4); b4.setBounds(160, 30, 50, 30); 027: add(b5); b5.setBounds(210, 30, 50, 30); 028: add(b6); b6.setBounds(275, 30, 100, 30); 029: add(b7); b7.setBounds( 20,100, 100, 30); 030: add(t0); t0.setBounds( 20, 60, 100, 30); 031: add(t1); t1.setBounds(150, 60, 100, 30); 032: add(t2); t2.setBounds(280, 60, 150, 30); 033: add(x0); x0.setBounds(128, 65, 50, 30); 034: add(x1); x1.setBounds(258, 65, 50, 30); 035: b0.addActionListener(new ActionListener(){ 036: public void actionPerformed(ActionEvent evt) { 037: try{ 038: a = 0; 039: t0.setText(""); 040: t1.setText(""); 041: t2.setText(""); 042: x0.setText(""); 043: }catch(Exception ex){} 044: } 045: }); 046: b1.addActionListener(new ActionListener(){ 047: public void actionPerformed(ActionEvent evt) { 048: x0.setText(b1.getLabel()); 049: a = 1; 050: } 051: }); 052: b2.addActionListener(new ActionListener(){ 053: public void actionPerformed(ActionEvent evt) { 054: x0.setText(b2.getLabel()); 055: a = 2; 056: } 057: }); 058: b3.addActionListener(new ActionListener(){ 059: public void actionPerformed(ActionEvent evt) { 060: x0.setText(b3.getLabel()); 061: a = 3; 062: } 063: }); 064: b4.addActionListener(new ActionListener(){ 065: public void actionPerformed(ActionEvent evt) { 066: x0.setText(b4.getLabel()); 067: a = 4; 068: } 069: }); 070: b5.addActionListener(new ActionListener(){ 071: public void actionPerformed(ActionEvent evt) { 072: x0.setText(b5.getLabel()); 073: a = 5; 074: } 075: }); 076: b6.addActionListener(new ActionListener(){ 077: public void actionPerformed(ActionEvent evt) { 078: try{ 079: int x = (new Integer(t0.getText())).intValue(); 080: int y = (new Integer(t1.getText())).intValue(); 081: if(a==1) 082: t2.setText("" + ( x + y )); 083: if(a==2) 084: t2.setText("" + ( x - y )); 085: if(a==3) 086: t2.setText("" + ( x * y )); 087: if(a==4) 088: t2.setText("" + ( x / y )); 089: if(a==5) 090: t2.setText("" + ( x % y )); 091: if(a==0) 092: t2.setText("Choose Button!!"); 093: }catch(NumberFormatException ee){ 094: t2.setText("error"); 095: } 096: } 097: }); 098: b7.addActionListener(new ActionListener(){ 099: public void actionPerformed(ActionEvent evt) { 100: try{ 101: int z = (new Integer(t2.getText())).intValue(); 102: t0.setText("" + z); 103: t1.setText(""); 104: t2.setText(""); 105: x0.setText(""); 106: }catch(NumberFormatException ee){ 107: t0.setText("Error!!"); 108: t1.setText("Push"); 109: t2.setText("Clear"); 110: } 111: } 112: }); 113: } 114: 115: 116: public static void main(String[] args) { 117: Frame win = new dentaku(); 118: win.setSize(450, 150); win.setVisible(true); 119: win.addWindowListener(new WindowAdapter() { 120: public void windowClosing(WindowEvent evt) { 121: System.exit(0); 122: } 123: }); 124: } 125: } |