programming challenge in java-2

hello friend's,
check out this code
import java.applet.*;
import java.awt.*;
/**/
public class k extends Applet implements Runnable
{
Image img,im,p;
int x=0,y=0;
Thread t,t1;
public void init()
{
img=getImage(getDocumentBase(),"cc.gif");
}
public void start()
{
t=new Thread(this);
t.start();
}
public void run()
{
try
{
for(int i=0;i<=20;i++)
{
p=img;
repaint();
t.sleep(50);
x=x+20;
}
}
catch(InterruptedException e)
{
System.out.println("interrupted exception ");
}
}
public void paint(Graphics g)
{
g.drawImage(p,x,20,100,100,this);
}
}
This is a program which move an image and stop at some distance.
You have to edit it in this way that after 1st image stop 2nd image start to move from same position and stop just before 1st one.
.

Replies

  • Manish Goyal
    Manish Goyal
    check it out

    Really it was challenge 😀
    import java.applet.*;
    import java.awt.*;
    /**/
    public class k extends Applet implements Runnable
    {
        Image img[]=new Image[2],p;
        int x=0,y=0,limit=20,i,width=60,height=60;
        int ext=(limit*limit)+width;
        Thread t,t1;
        public void init()
        {
            img[0]=getImage(getDocumentBase(),"Desert.jpg");
            img[1]=getImage(getDocumentBase(),"Hydrangeas.jpg");
        }
        public void start()
        {
            t=new Thread(this);
            t.start();
        }
    
        public void run()
        {
        try{
            for(i=0;i<2;i++)
            {        x=0;
    
            
            for(int j=0;j<=limit;j++)
            {
                p=img[i];
                t.sleep(50);
                repaint();
                x=x+20;
            }
            limit=limit-1;
            }
    
    
        
            }catch(Exception e){}
    }
    
    
    public void paint(Graphics g)
        {
            if(i==0)
            {
                g.drawImage(p,x,30,width,height,this);
            }
            if(i>=1)
            {
                g.drawImage(p,x,30,width,height,this);
                g.drawImage(img[0],ext,30,width,height,this);
            }
        }
    
    }
    
  • Morningdot Hablu
    Morningdot Hablu
    Nice find goyal..!!
    So you are the winner of java programming challenge-2... 😁
    .
  • Morningdot Hablu
    Morningdot Hablu
    Well This was the solution what i want to post today on 4PM.
    Check out this.
    import java.applet.*;
    import java.awt.*;
    /**/
    public class k extends Applet implements Runnable
    {
    Image img,im,p;
    int x=0,y=0;
    Thread t,t1;
    public void init()
    {
    img=getImage(getDocumentBase(),"cc.gif");
    im=getImage(getDocumentBase(),"ee.jpg");
    }
    public void start()
    {
    t=new Thread(this);
    t.start();
    }
    public void run()
    {
    try
    {
    for(int i=0;i<=20;i++)
    {
    p=img;
    repaint();
    t.sleep(50);
    x=x+20;
    }
    for(int i=0;i<=15;i++)
    {
    p=im;
    repaint();
    t.sleep(100);
    y=y+20;
    }
    }
    catch(InterruptedException e)
    {
    System.out.println("interrupted exception ");
    }
    }
    public void paint(Graphics g)
    {
    if(p==img)
    {
    g.drawImage(p,x,20,100,100,this);
    }
    else
    {
    g.drawImage(img,x,20,100,100,this);
    g.drawImage(p,y,20,100,100,this);
    }
    }
    }
  • d_vipul
    d_vipul
    nice one guys........

You are reading an archived discussion.

Related Posts

Tata DOCOMO has launched its first co-branded mobile handset OneTouch Net Phone from Alcatel. OneTouch comes preloaded with a suite of Yahoo services alongwith two buttons to launch Yahoo services...
Hello CEans! Lets have our own encyclopedia of engineering terms. Pick a random engineering term,define it,explain it and submit it here. As good the explaination,better the information. Note😛lease provide true...
dear friends, what is meant by virtual memory can anybody explain me.
1.A person went to meet the politician on thursday.The politician was busy and told the person to come four days after the before day of the day after tomorrow..When did...
Urdhvaa, the national level technical extravaganza organized by MCET is an ode to stupendous growth made by science and technology over the years. With six departments encompassing myriad fields of...