Results 1 to 2 of 2
- 06-29-2010, 04:16 AM #1sahildave1991 Guest
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:
Java 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){} } } }
-
Please do not duplicate post questions here. This post will be locked.
Similar Threads
-
changing my program to array working program
By Chewart in forum New To JavaReplies: 39Last Post: 11-18-2009, 06:53 PM -
Execute A program from a Program!
By Moncleared in forum Advanced JavaReplies: 2Last Post: 02-22-2009, 04:17 PM -
Executing a program within a program
By gibsonrocker800 in forum New To JavaReplies: 5Last Post: 05-12-2008, 08:24 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM


LinkBack URL
About LinkBacks

Bookmarks