1 26 27 28 package org.objectweb.mobilitools.util.gui; 29 30 31 import java.awt.*; 32 import java.awt.event.*; 33 34 35 public class FormFrame extends Frame implements ActionListener 36 { 37 Button[] boutonsBtn; 38 TextField[] fields; 39 FormListener listener; 41 42 public FormFrame(String titre, String comment, String [] champs, String [] boutons) 43 { 44 this(titre, comment, champs, null, null, boutons); 45 } 46 47 48 public FormFrame(String titre, String comment, String [] champs, String [] valeurs, String [] boutons) 49 { 50 this(titre, comment, champs, valeurs, null, boutons); 51 } 52 53 54 public FormFrame(String titre, String comment, String [] champs, boolean[] secret, String [] boutons) 55 { 56 this(titre, comment, champs, null, secret, boutons); 57 } 58 59 60 public FormFrame(String titre, String comment, String [] champs, String [] valeurs, boolean[] secret, String [] boutons) 61 { 62 super(titre); 63 setLayout(new BorderLayout()); 64 65 Label texte = new Label(comment); 67 add("North", texte); 68 69 Panel labelPanel = new Panel(), fieldPanel = new Panel(); 71 labelPanel.setLayout(new GridLayout(champs.length, 1)); 72 fieldPanel.setLayout(new GridLayout(champs.length, 1)); 73 fields = new TextField[champs.length]; 74 for (int i=0 ; i<champs.length ; ++i) 75 { 76 labelPanel.add(new Label(champs[i])); 77 fieldPanel.add(fields[i] = new TextField()); 78 if (valeurs != null && valeurs[i] != null && valeurs[i].length() > 0) 79 { 80 fields[i].setText(valeurs[i]); 81 } 82 if (secret != null && secret[i]) 83 { 84 fields[i].setEchoChar('*'); 85 } 86 } 87 add("West", labelPanel); 88 add("Center", fieldPanel); 89 90 Panel boutonsPnl = new Panel(); 92 boutonsPnl.setLayout(new FlowLayout()); 93 boutonsBtn = new Button[boutons.length]; 94 for (int i=0 ; i<boutons.length ; ++i) 95 { 96 boutonsPnl.add(boutonsBtn[i] = new Button(boutons[i])); 97 boutonsBtn[i].addActionListener(this); 98 } 99 add("South", boutonsPnl); 100 addWindowListener(new OnWindowClosing()); 101 pack(); 102 } 103 104 105 public void run(FormListener the_listener) 106 { 107 listener = the_listener; 108 show(); 109 } 110 111 112 116 117 public void actionPerformed(ActionEvent evt) 118 { 119 int i; 120 String [] values = new String [1+fields.length]; 121 for (i=0 ; i<fields.length ; ++i) 122 { 123 values[i] = fields[i].getText(); 124 } 125 values[i] = ((Button)evt.getSource()).getLabel(); 126 listener.formResult(values); 127 dispose(); 128 } 129 130 131 135 136 class OnWindowClosing extends WindowAdapter 137 { 138 public void windowClosing(WindowEvent e) 139 { 140 if (listener != null) 141 { 142 FormFrame.this.listener.formResult(null); 143 } 144 FormFrame.this.dispose(); 145 } 146 } 147 } 148 | Popular Tags |