I am just able to select one images from multiple images and dragging of images is not possible on entire screen,Below are the three images displayed Java Applet ,I wanted to select it and then drag it anywhere on the Applet Frame
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<applet code="SelectingImage" width=500 height=300>
<param name=img1 value=arrow1.jpg>
<param name=img2 value=Home.jpg>
<param name=img3 value=arrow2.jpg>
</applet>
*/
public class SelectingImage extends Applet implements
MouseListener,MouseMotionListener{
Image img[]=new Image[3];
int y=10;
int a;
int dx,dy;
int xpos,ypos;
int x[]=new int[3];
boolean imgdrag,imgclick,enabled=true;
public void init(){
try{
MediaTracker mt=new MediaTracker(this);
img[0]=getImage(getDocumentBase(),getParameter("img1"));
img[1]=getImage(getDocumentBase(),getParameter("img2"));
img[2]=getImage(getDocumentBase(),getParameter("img3"));
for(int i=0;i<3;i++){
x[i]=(i+1)*150;
mt.addImage(img[i],i);
}
mt.waitForAll();
addMouseListener(this);
}
catch (InterruptedException e) { };
}
public void paint(Graphics g){
for(int i=0;i<3;i++){
g.drawImage(img[i],x[i],y,null);
}
for(int i=0;i<3;i++){
if(xpos>=x[i] && xpos<=img[i].getWidth(null)+x[i] &&
ypos>=10 && ypos<=img[i].getHeight(null))
{
g.drawRect(x[i],10,img[i].getWidth(null),img[i].getHeight(null));
a=i;
imgclick=true;
break;
}
else{
imgclick=false;
}
}
if(imgclick){
g.drawImage(img[a],xpos,ypos,null);
}
}
public void mouseClicked (MouseEvent me)
{
xpos=me.getX();
ypos=me.getY();
showStatus("Mouse at"+me.getX());
repaint();
}
public void mouseEntered (MouseEvent me) {
}
public void mousePressed (MouseEvent me) {}
public void mouseReleased (MouseEvent me) {}
public void mouseExited (MouseEvent me) {}
public void mouseDragged(MouseEvent me){
xpos=me.getX();
ypos=me.getY();
showStatus("Mouse at"+me.getX());
repaint();
}
public void mouseMoved(MouseEvent me){
xpos=me.getX();
ypos=me.getY();
repaint();
}
}
sorry for wrong indentation of code since iam newbie