import java.awt.;
import java.awt.event.;
import java.applet.*;
import java.awt.image.BufferedImage;
import java.awt.image.BufferStrategy;
import java.net.URL;
public class AppletGame extends Applet implements Runnable
{
Image bg;
//Global Variables
BufferedImage bi;
Graphics2D g2d;
Stars stars1, stars2;
boolean playing = false;
public static final int MAX_SOUNDS = 1;
AudioClip[] sounds;
//Initialize the Applet
public void init() {
//Set the size
setSize(640,480);
//Create double buffer
bi = new BufferedImage(640,480, BufferedImage.TYPE_INT_RGB);
g2d = bi.createGraphics();
//Load Display class
//Load Stars class
stars1 = stars2 = new Stars();
try
{
bg = getImage(getCodeBase(), "data/bg.png");
}
catch(Exception e)
{
System.out.print("Error loading Graphics");
}
//Load sound
sounds = new AudioClip[MAX_SOUNDS];
URL url;
for(int i = 0; i < MAX_SOUNDS; i++)
{
url = this.getClass().getResource("data/test" + i + ".au");
sounds[i] = getAudioClip(url);
}
playSound(0);
Thread t = new Thread(this);
t.start();
}
public void destroy() {
}
public void start()
{
//Initialize sound
}
public void playSound(int num)
{
// This will play your sound file.
if(!playing)
sounds[num].play();
playing = true;
}
//Basically our main method
public void run() {
//Our game loop
while(true)
{
//Make the stars move
stars1.starAI();
stars2.starAI();
//Call repaint
repaint();
}
}
//Stops graphics from flickering.
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g){
//Move graphics to the true 0,0.
g.translate(getInsets().left, getInsets().top);
//Graphics2D g2d = (Graphics2D)g;
//Draw the background
g2d.drawImage(bg, 0, 0,this);
//Background stars
stars1.drawStars(g2d);
//Foreground stars
stars2.drawStars(g2d);
//Display buffer
g.drawImage(bi, 0, 0, this);
}
public void stop() {
}
}
Please help me load sounds and graphics.