import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Gui extends JFrame{
private JButton reg;
private JButton custom;
public Gui(){
super("The title");
setLayout(new FlowLayout());
reg = new JButton("reg button");
add(reg);
Icon b = new ImageIcon(getClass().getResource("1111.png"));
Icon x = new ImageIcon(getClass().getResource("222.png"));
custom = new JButton("Custom", b);
custom.setRolloverIcon(x);
add(custom);
HandlerClass handler = new HandlerClass();
reg.addActionListener(handler);
custom.addActionListener(handler);
}
private class HandlerClass implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JOptionPane.showMessageDialog(null, String.format("%s", e.getActionCommand()));
if (e.getSource() == reg) {
}
}
}
}
import javax.swing.JFrame;
public class Main {
public static void main(String[] args){
Gui go = new Gui();
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setSize(300, 200);
go.setVisible(true);
}
}