Results 1 to 6 of 6
  1. #1
    munishmhr is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default mouselistener and mouseactionlistener

    can any one tell why this is giving me following errors:
    mouse_event.java:19: illegal start of expression
    public void mousePressed(MouseEvent e){
    ^
    mouse_event.java:19: illegal start of expression
    public void mousePressed(MouseEvent e){
    ^
    mouse_event.java:19: ';' expected
    public void mousePressed(MouseEvent e){
    ^
    mouse_event.java:19: ';' expected
    public void mousePressed(MouseEvent e){
    ^
    mouse_event.java:26: illegal start of expression
    public void mouseClicked(MouseEvent e){
    ^
    mouse_event.java:26: illegal start of expression
    public void mouseClicked(MouseEvent e){
    ^
    mouse_event.java:26: ';' expected
    public void mouseClicked(MouseEvent e){
    ^
    mouse_event.java:26: ';' expected
    public void mouseClicked(MouseEvent e){
    ^
    mouse_event.java:33: illegal start of expression
    public void mouseEntered(MouseEvent e){
    ^
    mouse_event.java:33: illegal start of expression
    public void mouseEntered(MouseEvent e){
    ^
    mouse_event.java:33: ';' expected
    public void mouseEntered(MouseEvent e){
    ^
    mouse_event.java:33: ';' expected
    public void mouseEntered(MouseEvent e){
    ^
    mouse_event.java:40: illegal start of expression
    public void mouseExited(MouseEvent e){
    ^
    mouse_event.java:40: illegal start of expression
    public void mouseExited(MouseEvent e){
    ^
    mouse_event.java:40: ';' expected
    public void mouseExited(MouseEvent e){
    ^
    mouse_event.java:40: ';' expected
    public void mouseExited(MouseEvent e){
    ^
    mouse_event.java:47: illegal start of expression
    public void mouseReleased(MouseEvent e){
    ^
    mouse_event.java:47: illegal start of expression
    public void mouseReleased(MouseEvent e){
    ^
    mouse_event.java:47: ';' expected
    public void mouseReleased(MouseEvent e){
    ^
    mouse_event.java:47: ';' expected
    public void mouseReleased(MouseEvent e){
    ^


    /*
    <applet code=mouse_event width=3000 height=300>
    </applet>
    */
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    public class mouse_event extends Applet implements MouseListener,MouseMotionListener{
    int xPos=0;
    int yPos=0;
    String msg="";
    public void init(){
    addMouseListener(this);
    addMouseMotionListener(this);
    Font f1=new Font(new Font("TimesNewRoman",font.BOLD,18));
    setFont(f1);
    }
    public static void main(String s[]){
    public void mousePressed(MouseEvent e){
    xPos=e.getX();
    yPos=e.getY();
    msg="you pressed";
    repaint();
    }

    public void mouseClicked(MouseEvent e){
    xPos=e.getX();
    yPos=e.getY();
    msg="you Clicked";
    repaint();
    }

    public void mouseEntered(MouseEvent e){
    xPos=e.getX();
    yPos=e.getY();
    msg="you Entered";
    repaint();
    }

    public void mouseExited(MouseEvent e){
    xPos=e.getX();
    yPos=e.getY();
    msg="you Exited";
    repaint();
    }

    public void mouseReleased(MouseEvent e){
    xPos=e.getX();
    yPos=e.getY();
    msg="you Released";
    repaint();
    }

    public void mouseDragged(MouseEvent e){
    xPos=e.getX();
    yPos=e.getY();
    msg="you Dragged";
    repaint();
    }

    public void mouseMoved(MouseEvent e){
    xPos=e.getX();
    yPos=e.getY();
    msg="you Moved";
    repaint();
    }
    }
    public void paint(Graphics g){
    g.drawString(msg+"x="+xPos+"yPos="+yPos,xPos,yPos) ;
    }
    }
    Last edited by munishmhr; 08-26-2009 at 12:00 PM.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    1.) Please use code tags when posting code.
    2.) You have put a method inside the main method. That is not valid Java program structure.

  3. #3
    munishmhr is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default

    so what do u actully want me to do with program

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Well you have
    Java Code:
    public static void main(String s[]){
    public void mousePressed(MouseEvent e){
    xPos=e.getX();
    yPos=e.getY();
    msg="you pressed";
    repaint();
    }
    The main method needs to be a separate method with it's own closing brace before the start of the mousePressed method.

  5. #5
    munishmhr is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default

    thanks fr rply now i deleted the main method

    now it is working
    Last edited by munishmhr; 08-26-2009 at 12:24 PM.

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Quote Originally Posted by munishmhr View Post
    thanks fr rply now i deleted the main method

    now it is working
    Yep, you don't need that main method since you are creating an applet anyway.

Similar Threads

  1. mouseListener trouble please help!
    By linux1man in forum AWT / Swing
    Replies: 6
    Last Post: 06-03-2009, 01:57 AM
  2. Mouselistener questions
    By jigglywiggly in forum New To Java
    Replies: 0
    Last Post: 05-07-2009, 09:59 PM
  3. i need help for MouseListener
    By sfaxianovic in forum New To Java
    Replies: 2
    Last Post: 08-21-2008, 03:30 AM
  4. MouseListener
    By Aswq in forum New To Java
    Replies: 12
    Last Post: 07-18-2008, 08:10 AM
  5. I need help with my MouseMotionAdapter and MouseListener.
    By MurderfaceX4 in forum New To Java
    Replies: 1
    Last Post: 12-07-2007, 03:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •