Problem in java.

Hello guy's,
Look at this coding in java.
This will run.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Mouseapp extends Applet implements MouseListener,MouseMotionListener
{
int x,y;
String msg="";
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseEntered(MouseEvent m)
{
x=m.getX();
y=m.getY();
msg="Mouse Entered";
repaint();
}
public void mouseExited(MouseEvent m)
{
x=10;
y=10;
msg="Mouse Exited";
repaint();
}
public void mousePressed(MouseEvent m)
{
x=m.getX();
y=m.getY();
msg="Mouse is pressed";
repaint();
}
public void mouseReleased(MouseEvent m)
{
x=m.getX();
y=m.getY();
msg="Mouse is Released";
repaint();
}
public void mouseClicked(MouseEvent m)
{
x=m.getX();
y=m.getY();
showStatus("Mouse is clicked at" + x + "," +y);
}
public void mouseDragged(MouseEvent m)
{
x=m.getX();
y=m.getY();
msg="IMS";
repaint();
}
public void mouseMoved(MouseEvent m)
{
x=m.getX();
y=m.getY();
showStatus("Mouse is moved at" + x + "," +y);
}
public void paint(Graphics g)
{
g.drawLine(10,20,x,y);
}
}
But look at this code.
Here i am not using all mouse listener modules.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class hp extends Applet implements MouseListener,MouseMotionListener
{
    int x,y;
    public void init()
    {
        addMouseListener(this);
        addMouseMotionListener(this);
    }
    public void mouseEntered(MouseEvent m)
    {
        x=m.getX();
        y=m.getY();
    }
    public void paint(Graphics g)
        {
            g.drawLine(10,20,x,y);
        }
}
Can any one tell me where i am wrong.
This code will display an error.

Replies

  • Manish Goyal
    Manish Goyal
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    /*
     
     
    */
    public class Hp extends Applet implements MouseListener,MouseMotionListener
    {
        int x,y;
        public void init()
        {
            addMouseListener(this);
            addMouseMotionListener(this);
        }
        public void mouseEntered(MouseEvent m)
        {
            x=m.getX();
            y=m.getY();
        }
    public void mouseExited(MouseEvent m)
        {}
    public void mouseReleased(MouseEvent m)
        {}
    public void mousePressed(MouseEvent m)
        {}
    public void mouseDragged(MouseEvent m)
        {}
    
    public void mouseMoved(MouseEvent m)
        {}
    
    public void mouseClicked(MouseEvent m){}
        public void paint(Graphics g)
            {
                g.drawLine(10,20,x,y);
            }
    }
    
    
    
    
    Try this

    save it as "Hp.java"

    and run it using appletviewer Hp.java
  • Morningdot Hablu
    Morningdot Hablu
    Thanks goyal!!
    It's working now.
    Can you tell me why it is necessary to use all the methods??
  • Morningdot Hablu
    Morningdot Hablu
    Anybody have idea how to do this with Adapter classes.
  • learner
    learner
    Can you please tell me how to compile two user defined classes in different packages on netbeans platform?
  • Morningdot Hablu
    Morningdot Hablu
    learner
    Can you please tell me how to compile two user defined classes in different packages on netbeans platform?
    Didn't understand what you want to say.

You are reading an archived discussion.

Related Posts

Hello friend's, I think most of our CEan's are new in ubuntu like environment. So a good way to resolved this problem is share your tips and tricks with us....
Hello friend's, I am thinking about designing a website in java. I just started to design home page for it. Any one interested in doing this.
Both sessions and cookies are used to store user information but what is the exact difference between sessions and cookies? when to use cookies and when to use sessions? @Big_k...
SPAIN has designed the world's first robot with its own " conscience "and " life " , which will entertain, teach and be a companion to humans who purchase it....
i am ccna certified , need some ideas about networking project live and working and can be used by students , security related or wireless