Im new to Java and when tring to get some textures into my game I got this error stated ImageIO cannot b resolved. Here is my code:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class gameLoop extends Applet implements Runnable, KeyListener{
public int x, y;
public Image offscreen;
public Graphics d;
public boolean up, down, left, right;
public BufferedImage background,foreground,w1,w2,w3,w4;
public void run() {
x = 100;
y = 100;
try {
background = ImageIO.read(new File("gameBackground.png"));
foreground = ImageIO.read(new File("gameForeground.png"));
w1 = ImageIO.read(new File("playerWalk1"));
w2 = ImageIO.read(new File("playerWalk2"));
w3 = ImageIO.read(new File("playerWalk3"));
w4 = ImageIO.read(new File("playerWalk4"));
} catch (IOException e1) {
e1.printStackTrace();
}
while(true){
if (left == true){
x-=5;
}if (right == true){
x+=5;
}if (up == true){
y-=5;
}if (down == true){
y+=5;
}
repaint();
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == 37){
left = true;
}
if (e.getKeyCode() == 38){
up = true;
}
if (e.getKeyCode() == 39){
right = true;
}
if (e.getKeyCode() == 40){
down = true;
}
}
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == 37){
left = false;
}
if (e.getKeyCode() == 38){
up = false;
}
if (e.getKeyCode() == 39){
right = false;
}
if (e.getKeyCode() == 40){
down = false;
}
}
public void keyTyped(KeyEvent e) {}
}
My other java class:
import java.applet.Applet;
import java.awt.Graphics;
public class Game extends gameLoop {
public void init(){
setSize(854,480);
Thread th = new Thread(this);
th.start();
offscreen = createImage(854, 480);
d = offscreen.getGraphics();
addKeyListener(this);
}
public void paint(Graphics g){
d.clearRect(0, 0, 854, 480);
d.drawImage(background, 0, 0, this);
d.drawOval(x, y, 20, 20);
g.drawImage(offscreen, 0, 0, this);
}
public void update(Graphics g){
paint(g);
}
}
Can someone help me.