Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Problems with mouseDrag in visual j++ 6.0

amigolokoamigoloko Member Posts: 28
Hi, I have a little problem with the event drag , i need to do kind of a puzzle , I have a image that is divide in 4 so it is all mix and I have to order in the correct way, so the technique need to be with the mousedrag, so when i select a peace of the image the image travel with the mouse until i drop it in the correct space and then te image over there go to the space that dont have any image.

here is the code i alrready have it but is with mousedown so when i click in one of the image and on the other one they switch their places.

/code
import java.awt.*;
import java.applet.*;

public class Applet1 extends Applet
{
Image principal;
Image pieza1,pieza2,pieza3,pieza4;
String im[]={"","esc4.jpg","esc3.jpg","esc2.jpg","esc1.jpg"};
int lugar,anterior,actual;
public void init()
{
//principal=getImage(getDocumentBase(),"escudo.jpg");//principal es una ovejota de tipo image
setBackground(Color.black);
}
public void paint(Graphics g)
{
pieza1=getImage(getDocumentBase(),im[1]);
pieza2=getImage(getDocumentBase(),im[2]);
pieza3=getImage(getDocumentBase(),im[3]);
pieza4=getImage(getDocumentBase(),im[4]);
g.drawImage(pieza1,25,25,this);
g.drawImage(pieza2,235,25,this);
g.drawImage(pieza3,25,236,this);
g.drawImage(pieza4,235,236,this);
}
public boolean mouseDown(Event evt, int x, int y)
{
if(x>=25 && x<=233 && y>=25 && y<=234)
{
if(lugar==0)
{
anterior=1;
lugar=1;
}
else
{
actual=1;
lugar=2;
}
}
if(x>=234 && x<=443 && y>=25 && y<=234)
{
if(lugar==0)
{
anterior=2;//mousedrag
lugar=1; //mouseup
}
else
{
actual=2;//mousedrag
lugar=2;//mouseup
}
}
if(x>=25 && x<=233 && y>=235 && y<=445)
{
if(lugar==0)
{
anterior=3;
lugar=1;
}
else
{
actual=3;
lugar=2;
}
}
if(x>=234 && x<=443 && y>=235 && y<=445)
{
if(lugar==0)
{
anterior=4;
lugar=1;
}
else
{
actual=4;
lugar=2;
}
}
if(lugar==2) //mouseup
{
im[0]=im[anterior];
im[anterior]=im[actual];
im[actual]=im[0];
lugar=0;
repaint();
}

return true;
}

}
/code
Sign In or Register to comment.