CrazyEngineers
  • Collect the balls in the bucket using java programming.

    Kaustubh Katdare

    Kaustubh Katdare

    @thebigk
    Updated: Oct 21, 2024
    Views: 972
    hello friends,
    here is some codes in java check it out.
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    /*<Applet code=&quot;p&quot; height=400 width=400></applet>*/
    public class p extends Applet implements MouseMotionListener,Runnable
    {
    int x,y,k,i,p,px,s=0;
    Image img,img1,img2;
    Thread t;
    String str;
    public void init()
    {
    addMouseMotionListener(this);
    t=new Thread(this);
    t.start();
    img=getImage(getDocumentBase(),&quot;dem.gif&quot😉;
    img1=getImage(getDocumentBase(),&quot;lig.gif&quot😉;
    img2=getImage(getDocumentBase(),&quot;lim.gif&quot😉;
    }
    public void run()
    {
    for(i=0;i<=4000;i++)
    {
    try
    {
    repaint();
    t.sleep(50);
    k=k+5;
    if(k==400)
    k=0;
    }
    catch(Exception e)
    {
    System.out.println(&quot;exception &quot😉;
    }
    }
    }
    public void mouseDragged(MouseEvent e)
    {}
    public void mouseMoved(MouseEvent e)
    {
    repaint();
    x=e.getX();
    y=e.getY();
    if(y>=380)
    {
    p=y;
    }
    }
    public void paint(Graphics g)
    {
    g.drawImage(img,x,p,20,20,this);
    g.drawImage(img1,20,k,20,20,this);
    if(p<=k)
    {
    if(x>=0 && x<=22)
    {
    g.drawString(&quot;AAHA MIL GYA&quot;,x,p);
    s++;
    g.drawImage(img2,x,p,20,20,this);
    }
    }
    str=&quot;total&quot;+Integer.toString(s);
    g.drawString(str,350,350);
    }
    }
    Keep your own images and provide the addresses for them.
    Enjoy it.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Home Channels Search Login Register