Java Swing Program to demonstrate JButton Action TextField
Program
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.*;
import java.awt.event.*;
public class JButtonActionTextBox{
public static void main(String[] args) {
JFrame frm = new JFrame("JButton Action Listener");
JPanel pnl = new JPanel();
JTextField txtDisplay = new JTextField(20);
txtDisplay.setBounds(50, 50, 150, 20);
JButton btnSubmit = new JButton("Click Here");
btnSubmit.setBounds(50, 200, 100, 20);
btnSubmit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
txtDisplay.setText("Welcome to www.oodlescoop.com");
}
});
pnl.add(txtDisplay);
pnl.add(btnSubmit);
frm.add(pnl);
frm.setSize(300, 300);
frm.setVisible(true);
frm.setLayout(null);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Output