JTextFieldの簡単な例 のバックアップ(No.1) - アールメカブ

アールメカブ


JTextFieldの簡単な例 のバックアップ(No.1)


Eclipse

import java.awt.HeadlessException;
public class TestTextField extends JFrame implements ActionListener {

JTextField tf1;
JTextField tf2;

public TestTextField() throws HeadlessException {
  super();
  // TODO Auto-generated constructor stub
  setSize(300,200);
  setTitle("Swing  サンプル");
  setLocation(210,415);

  JPanel p = new JPanel();
  p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
  tf1 = new JTextField("");
  tf2 = new JTextField("");
  tf1.addActionListener(this);
  tf2.addActionListener(this);
  p.add(tf1);
  p.add(tf2);
  getContentPane().add(p);
  setVisible(true);
}
public void actionPerformed(ActionEvent arg0) {
  // TODO Auto-generated method stub
  if(arg0.getSource() == tf1){
    tf1.setText("textfield1");
  }else if(arg0.getSource() == tf2){
    tf2.setText("textfield2");
  }
}
/**
 * @param args
 */
public static void main(String[] args) {
  // TODO Auto-generated method stub
  new TestTextField();
}