JTextFieldの簡単な例 - アールメカブ

アールメカブ


JTextFieldの簡単な例

Eclipse

import java.awt.Headl
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;essException;
 
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();
}
 
Link: Programming(4984d) 日録2007_11月(5990d) Eclipse(6012d)
Last-modified: 2007-11-09 (金) 09:33:12 (6012d)