where is the problem. It does not show image properly.
default.png = *********
what i see = *********
I dont think there is a problem with png. It is also in my src and I refreshed it on eclipse.
codes:
import java.awt.*;
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JFrame jf = new JFrame();
jf.setTitle( "test");
jf.setLayout( new FlowLayout());
jf.setSize(350, 450);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.add(new Panel());
}
}
panel:
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class Panel extends JPanel {
// PROPERTIES
public ImageIcon icon;
// CONSTRUCTORS
public Panel() {
icon = new ImageIcon(this.getClass().getResource("default.png"));
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage(icon.getImage(), 0, 0, null);
}
}