Hello,
Here are the class files DrawImage.java and Board.java which are supposed to load jvm.png , if not is ther another way of loading sprites with JFrame or java.applet.Applet
package gms;
import java.awt.EventQueue;
import javax.swing.JFrame;
public class DrawImage extends JFrame {
public DrawImage() {
initUI();
}
private void initUI() {
add(new Board());
pack();
setTitle("uc");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
DrawImage c = new DrawImage();
c.setVisible(true);
}
});
}
}
Board.java
package gms;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class Board extends JPanel {
private Image uc;
public Board() {
initBoard();
}
private void initBoard() {
loadImage();
int w = uc.getWidth(this);
int h = uc.getHeight(this);
setPreferredSize(new Dimension(w, h));
}
private void loadImage() {
ImageIcon ii = new ImageIcon("jvm.png");
uc = ii.getImage();
}
@Override
public void paintComponent(Graphics g) {
g.drawImage(uc, 0, 0, null);
}
}
Thanks