Kann Code nicht ausführen

Status
Nicht offen für weitere Antworten.

tempomat

Mitglied
Habe den folgenden Quellcode, den ich nicht zum laufen bringen kann. Ich kann es einfach nicht starten.

Problem:
Ich habe die test.java - Datei erstellt, von der aus ich das starten will, jedoch ohne Erfolg.
 
Code:
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);
	}

Code:
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;
	}
}
 
Eben nicht, denn bin nun auch auf eclipse umgestiegen. Ich kriege diesen "Mist" einfach nicht zum laufen. :bahnhof:
 
also wenns ein funktionierendes Applet ist, dann kann Eclipse das
ansonsten kommen irgendwelche Fehlermeldungen?

edit: also ich krieg 1 Mio Fehlermeldungen
wo is z.b. das Interface "Controller"?

edit2:
Habs mir mal runtergeladen ...

Code:
import netscape.javascript.*;

das package fehlt dir um es ausführen zu können
 
Endlich konnte ich das Teil zum starten bringen, jedoch kann das Teil meinen Controller nicht erkennen.

Einer eine Idee?

- Kennt vielleicht jemand einen Java - Code, bei dem eine Controller Kennung erfolgreich funktioniert? So könnte ich das dann einfach einbauen.
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Zurück
Oben