Hallo Leute!
Leider muss ich in einem Thread ein Bild laden und es im Applet darstellen. Ich habe das per "drawImage" versucht, aber es hat leider nicht funktioniert.
Andere Grafikfunktionen sind problemlos, nur "drawImage" geht nicht. Woran kann das liegen? Am Imageobserver?
Habt ihr eine Idee? Es wäre toll, wenn jemand mir Weiterhelfen könnte.
Leider muss ich in einem Thread ein Bild laden und es im Applet darstellen. Ich habe das per "drawImage" versucht, aber es hat leider nicht funktioniert.
Andere Grafikfunktionen sind problemlos, nur "drawImage" geht nicht. Woran kann das liegen? Am Imageobserver?
Habt ihr eine Idee? Es wäre toll, wenn jemand mir Weiterhelfen könnte.
Java:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.image.MemoryImageSource;
public class at4 extends Applet implements MouseListener, MouseMotionListener {
int width, height;
int mx, my; // the mouse coordinates
int bh, bb, testx, testy;
Image img;
Graphics buffergrafikausgabe;
Image buffergrafik;
int x = 0, y = 0;
public void init() {
width = getSize().width;
height = getSize().height;
setBackground(Color.black);
addMouseMotionListener(this);
buffergrafik = createImage(width, height);
buffergrafikausgabe = buffergrafik.getGraphics();
img = this.getImage(getDocumentBase(), "Bild1.jpg");
}
public void mouseMoved(MouseEvent e) {
mx = e.getX();
my = e.getY();
testx = mx + bb;
testy = my + bh;
repaint();
new AAA(this, mx, my, 5, 5, buffergrafikausgabe, img);
e.consume();
}
public void paint(Graphics g) {
buffergrafikausgabe.setColor(Color.red);
g.drawImage(buffergrafik, 0, 0, this);
}
public void update(Graphics g) {
paint(g);
}
}
class AAA extends Thread implements ImageObserver {
int xPos, yPos, bb, bh; /* position of the target */
Applet myMaster; /* who to repaint */
Graphics xx; /* Graphics to draw on */
Image imgX;
public AAA(Applet a, int x, int y, int bb, int bh, Graphics g, Image img) {
xPos = x;
yPos = y;
myMaster = a;
xx = g;
start();
imgX = img;
}
public void init() {
}
public void run() {
int i,r;
xx.setColor(Color.blue);
for (i = 10; i > -20; i -= 20)
xx.drawRect(xPos, yPos, 5, 5);
xx.drawImage(imgX, xPos, yPos, xPos + 5, yPos + 5, xPos, yPos,
xPos + 5, yPos + 5, this);
myMaster.repaint();
try {
sleep(200);
} catch (InterruptedException e) {
}
}
}