implements ActionListener : Java by API examples (example source code) » java.awt » ActionListener

Java by API
C++
Java Products
Java Articles
Java by API Home  »   java.awt   » [  ActionListener  ]   
 



implements ActionListener

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class MainClass extends JPanel  implements ActionListener {
  JTextField jtf = new JTextField(15);
  public MainClass() {
      add(jtf)
      jtf.addActionListener(this)
    
    // Show text when user presses ENTER. 
    public void actionPerformed(ActionEvent ae) { 
      System.out.println(jtf.getText())
    

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new MainClass());

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200200);
    frame.setVisible(true);
  }

}
Related examples in the same category








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.