well this is part of some uni work we have to do. I've followed the instructions to make the buffer work, but for some reason it's not being recognised. We have not been told to declare the buffer image, or anything, and i'm quite stuck here. Any help would be much appreciated.
i'm sure it's a simple error, but i've tried searching but no results have been able to help me.
Any help would be much appreciated.
Lee.
Code:
public void paintComponent(Graphics gPanel){
if (this.buffer == null) {
Dimension d = getSize();
this.buffer = new BufferedImage(d.width, d.height,
BufferedImage.TYPE_INT_ARGB_PRE);
this.g2Buffer = (Graphics2D) this.buffer.getGraphics();
this.g2Buffer.setColor(Color.white);
this.g2Buffer.fillRect(0, 0, d.width, d.height);
// This time we'll draw with a broad pen
this.g2Buffer.setStroke(new BasicStroke(8.0f));
}
Ellipse2D ellipse;
if (drawing) {
this.g2Buffer.setColor(Color.white);
this.g2Buffer.setXORMode(Color.red); // into the overwrite mode
ellipse = new Ellipse2D.Float(xStart, yStart,
Math.abs(xOld - xStart), Math.abs(yOld - yStart));
this.g2Buffer.draw(ellipse);
ellipse = new Ellipse2D.Float(xStart, yStart,
Math.abs(xEnd - xStart), Math.abs(yEnd - yStart));
this.g2Buffer.draw(ellipse);
this.g2Buffer.setPaintMode(); // out of XOR overwrite mode
xOld = xEnd; // store last end point
yOld = yEnd;
}
if (mouseReleased) {
this.g2Buffer.setColor(Color.red);
ellipse = new Ellipse2D.Float(xStart, yStart,
Math.abs(xEnd - xStart), Math.abs(yEnd - yStart));
this.g2Buffer.draw(ellipse);
mouseReleased = false;
}
gPanel.drawImage(this.buffer, 0, 0, this);
}
private int xStart = 0;
private int yStart = 0;
private int xEnd, yEnd;
private int xOld = 0;
private int yOld = 0;
private boolean drawing = false;
private boolean mouseReleased = false;
i'm sure it's a simple error, but i've tried searching but no results have been able to help me.
Any help would be much appreciated.
Lee.