Help me with this program.....plsssssssss
i am writing this code. I want to do the following :
1/ when i click for the first time the image 2.png(which is a squirrel) appears on the screen and move.
2/ before clicking the background should be there.
MY PROBLEM :: when i click the background + squirrel appears but the squirrel does not move. if i remove the if statement or turn it to true the program goes well. but i dont understand, that when i click the if statement is always true because i assign value 1 to click in mouseClicked method, but still the squirrel doesnt move.
And is there a way to bring the background beforehand only.
HOPE YOU UNDERSTOOD MY PROBLEM>>>>:confused:
Code:
package MyScreen;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
public class MoveByMouse extends Applet implements MouseListener,MouseMotionListener,Runnable
{
int posX=0,posY=10;
int a,b,click=0,i=0;
Image sq,bg;
Thread t;
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
sq = getImage(getDocumentBase(),"22.PNG");
bg = getImage(getDocumentBase(),"STAGE I - Morning Glory 2.JPG");
}
public void mouseClicked(MouseEvent e)
{
posX=e.getX();
posY=e.getY();
click=1;
repaint();
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
public void paint(Graphics g)
{
setSize(1024, 668);
g.drawImage(bg,0,0,null);
g.drawImage(sq,950-(10*(i*i)), 620-(50*i),null);
}
public void start()
{
if(click==1)
{
try
{
t= new Thread(this);
t.start();
}
catch(Exception e){}
}
}
public void run()
{
for(;i<30;)
{
try
{
repaint();
Thread.sleep(200);
i++;
}
catch(Exception e){}
}
}
}