Hi everyone. I'm trying to load and image to a program but for some reason it's not working.
Main code:
package javdrawimagetst; import javax.swing.JFrame; public class JavDrawImagetst { public static void main(String[] args) { JFrame w = new JFrame("Images"); w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); w.setSize(640, 480); Screen s = new Screen(); w.add(s); w.setVisible(true); } }
csecond class:
package javdrawimagetst; import java.awt.*; import javax.swing.*; public class Screen extends JPanel{ private Image youLost; public Screen(){ loadImages(); } public void loadImages(){ youLost = new ImageIcon("You_lostPNG.png").getImage(); repaint(); } public void paintComponent(Graphics g){ super.paintComponent(g); g.setColor(Color.RED); g.fillRect(32, 32, 65, 76); g.drawImage(youLost, 32, 54, this); } }
The image is in the folder. Is it because I'm trying to draw on a paintcomponent?