Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- class TextFieldExample implements ActionListener {
- JFrame frame;
- JTextField text1;
- JLabel label1;
- TextFieldExample(){
- frame = new JFrame();
- text1 = new JTextField(20);
- frame.setLayout(new FlowLayout());
- label1 = new JLabel("working");
- //register the actionListner to textField
- text1.addActionListener(this);
- frame.add(text1);
- frame.add(label1);
- frame.setSize(300,300);
- frame.setVisible(true);
- }
- //This method is called when user press "enter" or "return" keyword is textField
- public void actionPerformed(ActionEvent e) {
- System.out.println(text1.getText());
- label1.setText("The typed text is:"+text1.getText());
- }
- }
- public class GUI{
- public static void main(String[] args){
- new TextFieldExample();
- }
- }
Advertisement
Comments
-
- In this program actionPerformed(ActionEvent e) method is called when user press "enter" or "return" keyword in TextField.
Add Comment
Please, Sign In to add comment
Advertisement