Hi,
I�m new to animation and wanted to implement a sort of offscreen animation.
First trying to use "standard" java I have a problem and would be greatfull if
someone could offer me a tip (either in java2d or in standard).
I want to use a background image wich is the size of 400,400 and a forground
image of a car 60,60 (both gifs)
the background image should be drawn on a panel (JPanel ?) and the car at 0,0.
Animation is by changing the view of the BACKGROUND image (since the panel is
only 200,200).
This worked fine (except for flickering) until I had the ideasa of drawing the
scene in memory and then putting it on the screen. Now here is the relevant code
: It hangs at createImage(200,200), which obviously returns null. Then of course
I cannot draw on the offscreen Graphics since it is also null. Where is the
error ?
createImage is not supposed to return null
thanks in advance
//Beschreibung:Ihre Beschreibung
package testgta;
import java.awt.*;
import javax.swing.JPanel;
import java.awt.image.*;
import java.awt.event.*;
public class Bean1 extends Panel {
BorderLayout borderLayout1 = new BorderLayout();
private java.awt.Image bild;
private java.awt.Image bild2;
private java.awt.Image offScreenImage;
private Graphics offScreen;
public Bean1() {
try {
offScreenImage= createImage(200,200);
if (offScreenImage== null) System.out.println("null");
offScreen = offScreenImage.getGraphics();
if (offScreen==null) System.out.println("gnull");
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
this_mouseClicked(e);
}
});
this.setLayout(borderLayout1);
}
public void setBild(java.awt.Image newBild) {
ImageObserver op;
bild = newBild;
}
public void setBild2(java.awt.Image newBild) {
ImageObserver op;
bild2 = newBild;
}
public java.awt.Image getBild() {
return bild;
}
public void paint(Graphics g)
{ // super.paint();
if (bild!=null){
for (int i=0;i<400;i++) {
offScreen.drawImage(bild2,0,0,200,200,i,0,200+i,400,Color.blue,null);
offScreen.drawImage(bild,0,0,this);
//g.setColor(Color.lightGray);
//g.drawImage(bild2,0,0,this);
//g.drawImage(bild2,0,0,200,200,i,0,200+i,400,Color.blue,null);
//g.drawImage(bild,0,0,this);
//g.fillRect(i, 0,64,64);
g=offScreen;
}
}
}
void this_mouseClicked(MouseEvent e) {
paint(this.getGraphics());
System.out.println("huhu");
}
}
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".