import javax.swing.*;
import java.awt.event.*;
public class JButtonExample
{
public static void main(String[] args)
{
JFrame frame = new JFrame("ActionListener Example");
JButton btn = new JButton("Click here");
btn.setBounds(70,80,100,30);
//Change button text on click
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
btn.setText("OK");
}
});
frame.add(btn);
frame.setSize(250,250);
frame.setLayout(null);
frame.setVisible(true);
}
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==button) {
button.setText("Button Clicked!");
}}
<input type="button" value="Button Text" id="myButton1"></input>