I have some problem drawin an image icon out on the screen and animate it, the thing is i cant even see the image being displayed so i guess its something wrong.
Here is a piece of the code
public class Board extends JPanel implements ActionListener { Image Ghost; Timer timer; int x,y; public Board(){ setBackground(Color.BLACK); ImageIcon ii = new ImageIcon(("ghost.jpeg")); Ghost= ii.getImage(); setDoubleBuffered(true); x=y=10; timer = new Timer(25,this); timer.start(); } public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D)g; g2d.drawImage(Ghost,x,y,this); g.dispose(); } @Override public void actionPerformed(ActionEvent event) { x += 1; y += 1; if (y > 240) { y = -45; x = -45; } repaint(); } }
I put the ghost image in the directory where im doing the test. Is it my path thats wrong do i need some more to find the actual image ?