I have a program that detects when certain machines are online and creates a button with a green \"online\" icon to show this. I want to add the functionality to check perio
You should be able to do so using AbstractButton.setIcon().
It may require you to call invalidate()
on the button to get the change displayed.
changeButton = new JButton(icon1);
changeButton.addActionListener(
new ActionListener( )
{
private boolean flag = true;
@Override
public void actionPerformed( ActionEvent arg0 )
{
changeButton.setIcon( flag ? icon2 : icon1 );
flag = !flag;
}
}
);
add(changeButton);