ImageIcon icon1 = new ImageIcon("src/halum/lesson.gif");
ImageIcon icon2 = new ImageIcon("src/halum/lesson1-1.jpg");
JButton button1 = new JButton(icon1);
JButton button2 = new JButton(icon2);
JButton button3 = new JButton(icon1);
if(icon1.equals(icon2)) {
System.out.println("This line ain't gonna be shown dude. Because...");
}else {
System.out.println("They ain't same object you know :| ");
}
if (button1.getIcon()==button2.getIcon()) {
System.out.println("This is a better method. but They ain't same.");
}else {
System.out.println("Not gonna be printed");
}
if(button1.getIcon() == button3.getIcon()) {
System.out.println("this is true");
System.out.println("So this is what you should use");
}else {
System.out.println("Do we really need this else?");
}
if (button1.getIcon().equals(button3.getIcon())) {
System.out.println("This should work as well. As both buttons use same image icon");
}