基本小程序不符合Java安全标准

时间:2015-03-25 01:35:03

标签: java security applet

基本上我只想制作一个基本的弹跳球Applett,它可以在我的笔记本电脑上工作,但是当我尝试在线运行时,我得到一个提示说它被阻止了。我意识到这是因为新的安全措施,所以我应该如何改变它以使其更友好。感谢

import java.applet.*;
import java.awt.*;
import java.net.*;
import java.util.Random;

public class BouncingBall extends Applet implements Runnable{

Random rnd = new Random(500);
int r = rnd.nextInt(70);

int x_pos = 0;
int y_pos = 250;
int radius = 20;
int x_speed = 3;
int y_speed = 3;
int appletsize_x = 500;
int appletsize_y = 500;

private Graphics dbg;
private Image dbImage;

Thread th;

AudioClip bounce;
Image backImage;

public void init(){

}

public void start(){
    Thread th = new Thread(this);

    th.start();
}

public void stop(){

}

public void destroy(){

}

public void run(){
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

    while(true){

         if(x_pos > appletsize_x - radius){
            x_speed =- r;
        } else if(x_pos < radius){
            x_speed =+ r;
        }

        if(y_pos > appletsize_y - radius){
            y_speed =- r;
        } else if(y_pos < radius){
            y_speed =+ r;
        }

        x_pos += x_speed;
        y_pos += y_speed;

        repaint();
        try{
            Thread.sleep(20);
        }
        catch(InterruptedException ex){

        }



        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    }
}


 public void update(Graphics g){
     if(dbImage == null){
         dbImage = createImage (this.getSize().width, this.getSize().height);

         dbg = dbImage.getGraphics();
        }

        dbg.setColor(getBackground());
        dbg.fillRect(0,0, this.getSize().width, this.getSize().height);

        dbg.setColor(getForeground());
        paint(dbg);

        g.drawImage(dbImage, 0, 0, this);
}

public void paint(Graphics g){
    g.setColor(Color.red);
    g.fillOval(x_pos - radius, y_pos - radius, 2*radius, 2*radius);

    g.drawImage(backImage, 0, 0, this);

}

public boolean mouseDown (Event e, int x, int y){
    x_speed =- (x_speed);
    return true;
}

    public boolean keyDown(Event e, int key){
    if(key == Event.LEFT){
        x_speed = -10;
    } else if(key == Event.RIGHT){
        x_speed = 10;
    } else if(key == Event.UP){
        y_speed = -10;
    } else if(key == Event.DOWN){
        y_speed = 10;
    }else if (key == 32){
        x_speed = 0;
        y_speed = 0;
    } else if (key == 45){
        x_speed = 10;
    } else {
        System.out.println("Character: " + (char)key + " Integer value: " + key);
    }
    return true;
}

}

0 个答案:

没有答案