Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
import java.applet.*;
import java.awt.*;
public class Simple extends Applet implements Runnable {
Controller controller = null;
Thread thread = null;
Image sheep = null;
int x = 50; // sprite's x axis
int y = 50; // sprite's y axis
Graphics buffer;
Image bufferImage;
int width; // applet's width
int height; // applet's width
public void init() {
this.sheep = getImage(getCodeBase(), "killer_sheep.gif");
}
public void start() {
Dimension d = getSize();
this.width = d.width;
this.height = d.height;
this.bufferImage = createImage(this.width, this.height);
this.buffer = bufferImage.getGraphics();
this.thread = new Thread(this);
}
public void stop() {
this.thread = null;
}
public void attach() {
try {
this.controller = new Joystick(this,
getParameter("stickarray"),
getParameter("device 1"));
} catch (Exception e) {
System.err.println("Couldn't attach to joystick "
+ "so switching to key based control: " + e);
this.controller = new Keyboard(this);
}
this.thread.start();
}
public void run() {
while (Thread.currentThread() == this.thread) {
// reads the state of the device
this.controller.poll();
// gets the axes
int x = this.controller.getX();
int y = this.controller.getY();
// advances the sprites position accordingly
if (x < 28672) this.x += (x - 28672)/2048;
else if (x > 36864) this.x += (x - 36864)/2048;
if (y < 28672) this.y += (y - 28672)/2048;
else if (y > 36864) this.y += (y - 36864)/2048;
repaint();
try {
Thread.sleep(40);
} catch (InterruptedException e) {}
}
}
public void paint(Graphics g) {
update(g);
}
public void update(Graphics g) {
this.buffer.setColor(getBackground());
this.buffer.fillRect(0, 0, this.width, this.height);
this.buffer.drawImage(this.sheep, this.x, this.y, this);
g.drawImage(bufferImage, 0, 0, this);
}
import java.applet.*;
import netscape.javascript.*;
public class Joystick implements Controller {
JSObject player = null;
public Joystick(Applet applet, String container, String device) {
JSObject window = JSObject.getWindow(applet);
JSObject stickArray = (JSObject) window.getMember(container);
this.player = (JSObject) stickArray.getMember(device);
}
public void poll() {
try {
this.player.call("poll", null);
} catch (Exception e) {}
}
public int getX() {
int x = CENTRE;
try {
x = ((Double) this.player.call("getX", null)).intValue();
} catch (Exception e) {}
return x;
}
public int getY() {
int y = CENTRE;
try {
y = ((Double) this.player.call("getY", null)).intValue();
} catch (Exception e) {}
return y;
}
public int getButtons() {
int buttons = 0;
try {
buttons = ((Double) this.player.call("getButtons", null)).intValue();
} catch (Exception e) {}
return buttons;
}
}
import netscape.javascript.*;