I am trying to make a main menu and i am now working on the play button. Everything works fine except that it doesn't load an image. The image is in the source folder and this is the code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
public class GameFrame extends JFrame implements ActionListener{
JButton play;
GameFrame() {
ImageIcon icon = new ImageIcon("playButton.png");
play = new JButton();
play.setBounds(500,100,250,100);
play.addActionListener(this);
play.setText("hi");
play.setFocusable(false);
play.setIcon(icon);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
this.setSize(1000,700);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setUndecorated(false);
this.setVisible(true);
this.add(play);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==play) {
System.out.println("hi");
}
}
}