This code will change the messages of a button after it was clicked
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package latihan6;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author ASUS N43S
*/
public class Latihan6 {
JButton button1;
public Latihan6 (){
JFrame frame = new JFrame();
frame.setSize(300,300);
frame.setLocation(1,1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button1 = new JButton ("Please Click !!!!");
frame.add(button1,BorderLayout.PAGE_END);
AnActionListener myListener = new AnActionListener ();
button1.addActionListener(myListener);
frame.setVisible(true);
}
class AnActionListener implements ActionListener
{
public void actionPerformed (ActionEvent e) //event handler
{
button1.setText("Already Clicked");
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new Latihan6 ();
}
}
Screen Shot Before Click
Screen Shot After Clicked