mouse moving crosshair over image problem

Hello,

I am quite a newbe at Java and using the trail and error development method (or copy and paste method)

Now I am facing the following problem:

I made a program with an image that is draw out of received data. After that I want to draw a huge cursor crosshair (two lines at image size) over that image. It should move when I move my mouse.

I can t get it done by redrawing the entire image every mouse motion. That will result in a slow motion crosshair.

The program start with:

public class MyProg extends javax.swing.JFrame {

Container cont;

public byte[] BulkIn = new byte[6000];

public DrawField drawscreen;

public CrossHair crosshair;

/** Creates new form MyProg */

public MyProg() {

drawscreen = new DrawField(BulkIn);

.

The DrawField part (where the image is drawn) start like:

class DrawField extends JPanel implements Printable {

byte[] BulkData;

Lines BlueLine,RedLine,WhiteLine,GreenLine,CyanLine,YellowLine,OrangeLine,PinkLine;

static BufferedImage imgs;

static BufferedImage raster;

static BufferedImage buffImg;

..

The CrossHair part starts with:

class CrossHair extends JComponent{

Container cont ;

int x_Pos,y_Pos;

int x_offset,x_end,y_offset,y_end;

public void paint(Graphics g) {

g.setColor(Color.yellow);

g.drawLine(x_offset,y_Pos,x_end,y_Pos);

g.drawLine(x_Pos,y_offset,x_Pos,y_end);

.

Now, when I reach crosshair.repaint(); nothing happens.

When I change "class CrossHair extends Jcomponent" into "class CrossHair extends Jpanel", the crosshair is drawn perfectly, however, my original image is gone.

My intention was to draw the crosshair on some kind of glasspane, but until now with no success.

Help!

[1869 byte] By [waldoor] at [2007-9-26 2:45:53]
# 1

You'll have to redraw everything each time you reposition the cursor.

Your best bet to speed things up (and look nice) are:

1. Use double buffering

2. Redraw only over the area where the cursor needs to first be erased (ie might only be a30x30 area). You can achieve this by setting the clipping area of the pictures drawn.

JDunlop at 2007-6-29 10:28:19 > top of Java-index,Security,Cryptography...