
-----------------------------------
Peissi
Sun Jan 15, 2012 9:51 pm

Insert song for applet java
-----------------------------------
can someone help me to insert a song inside this game code below??? Thanks !!!




import java.awt.*;// define interfaces and classes
import java.awt.event.*;//Provides interfaces and classes for dealing with different types of events fired by AWT components.
import java.awt.image.BufferStrategy;//Creates a new strategy for multi-buffering on this component.
import java.awt.image.BufferedImage;//Provides classes for creating and modifying images
import java.applet.Applet;//apply applet
import java.awt.geom.*;//Provides the Java 2D classes for defining and performing operations on objects related to two-dimensional geometry.
import java.util.Random; //Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes(a random-number generator)

public class Cutter extends Applet implements Runnable, KeyListener {
// create a class that implements the Runnable interface, and keylistener interface (adding the use of the keyboard)
        // Game Setup Variables
        final Random rnd = new Random();// Creates a new random number generator.
    Canvas canvas = new Canvas();//creating a new canvas (A Canvas component represents a blank rectangular area of the screen onto which the application can draw or from which the application can trap input events from the user.)
    boolean[] keyDown = new boolean[255];

        boolean bRunning, finish;// delcared variables as boolean
    BufferStrategy bufferStrategy;
    int width, height;//set height and width as integer numbers

    static final int delay = 25; //setting the speed of the enemy movements

        // Game Variables
        static final int UP = 1, DOWN = 2, LEFT = 3, RIGHT = 4;
        Color basic = new Color(204,204,255),//creating the color for the background
                  border = new Color(102,102,153),//creating the color for the outside border
                  cut = new Color(102,102,102);//setting the color the the cutting line
        int basicRGB = basic.getRGB(), borderRGB = border.getRGB();
        Area area;//declared area
        BufferedImage img;//delcared img as BufferedImage (create a BufferedImage of one of the predefined image types)
        int posx, posy, tox, toy;//declared variables as integers
        boolean killed, cutting;//boolean killed and cutting
        int[][] node = new int[100][2];
        int curnode, direction, rest;
        Rectangle[] enemy;
        int[][] speed;//declared speed as integers
        boolean[] active;
        int live = 3, level = 0;//declared live and level as integers, also set the live with 3 chances and the level start with 0 and can go up to infinity stages 

    public void start() {
                if (bRunning || finish) return;
                bRunning = true;
        if (bufferStrategy == null) {
                        setIgnoreRepaint(true);
            width = getSize().width;
                        height = getSize().height;

                        canvas.setIgnoreRepaint(true);
            canvas.setSize(width, height);
                        canvas.addKeyListener(this);

                        setLayout(null);
                        add(canvas);
                        canvas.setLocation(0, 0);

            // using buffer strategy as backbuffer
            canvas.createBufferStrategy(2);
            bufferStrategy = canvas.getBufferStrategy();
                        img = (BufferedImage) canvas.createImage(width-10,height-10);
                        startup();
        }

                new Thread(this).start();
                canvas.requestFocus();
    }
        public void stop() { bRunning = false; }
        public void finish() { finish = true; stop(); }

        private void startup() {
                posx = 10; posy = 10;
                area = new Area(new Rectangle(10,10,img.getWidth()-20,img.getHeight()-20));
                Graphics2D g = img.createGraphics();
                g.setColor(basic); g.fill(area);
                g.setColor(border); g.draw(area);
                g.dispose();

                level++;// there are infinit stages 
                enemy = new Rectangle[5+(level*2)];//set the number of enemy in each levels, the first stage with 7 enemy, then add 2 more in the second stage, and so on
                speed = new int[5+(level*2)][2];//set the speed of the enemy movements, as the stage goes up, the speed is faster
                active = new boolean[5+(level*2)];
                for (int i=0;i < enemy.length;i++) {
                        enemy[i] = new Rectangle(getRandom(50,img.getWidth()-100),getRandom(50,img.getHeight()-100),12+(level*2),12+(level*2));
                        speed[i][0] = getRandom(-3,3); speed[i][1] = getRandom(1,3);
                        active[i] = true;
                }
        }
        public void update() {
                if (live == 0) {
                        if (keyDown[KeyEvent.VK_SPACE]) { live = 3; level = 0; startup(); }
                        return;
                }

                for (int i=0;i < enemy.length;i++) {
                        if (active[i]) {
                                enemy[i].translate(speed[i][0],speed[i][1]);
                                if (!area.intersects(enemy[i])) { // enemy is out of bounds
                                        // return enemy position, and set it's new velocity
                                        enemy[i].translate(-speed[i][0],-speed[i][1]);
                                        speed[i][0] = getRandom(-3,3); speed[i][1] = getRandom(-3,3);
                                        if (speed[i][0] == 0 && speed[i][1] == 0) speed[i][getRandom(0,1)] = getRandom(1,3);
                                }

                                int x = enemy[i].x, y = enemy[i].y, xw = x+enemy[i].width, yh = y+enemy[i].height;
                                for (int j=0;j < curnode;j++) { // check for enemy collision with player cut
                                        if (node[j][0] == node[j+1][0]) { // vertical cut
                                                if (x = node[j][0])
                                                if ((y >= node[j][1] && yh = node[j][0] && xw  tox) posx -= 2; else if (posx < tox) posx += 2;
                        if (posy > toy) posy -= 2; else if (posy < toy) posy += 2;
                        if (posx >= tox-1 && posx = toy-1 && posy 