button action listener java code example
Example 1: java add listent to button
JButton button = new JButton("Do Something");
button.addActionListener( new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println("Do Something Clicked");
}
});
Example 2: java swing button on click
JButton b = new JButton("push me");
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//your actions
}
});