Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Mouse motion/listener problems

Options
  • 21-04-2004 1:06pm
    #1
    Closed Accounts Posts: 2,951 ✭✭✭


    I dont know exactly _how_ this went wrong as i thought it would work. I have my application almost finished. An image editor using java advanced imaging. I implemented a "crop" function which allows the user to select a piece of an image with the mouse, in effect to drag the mouse over an area , then to click the crop button. This all works!, however the cursor does not show when the mouse is being dragged, i mean you cannot see the shape you are selecting to crop, you know like on the desktop when you click and drag the mouse you can see the box its drawing. Here is my code. as i say it actually is selecting the area, just you cannot see the box being drawn. Any help MUCH appreciated. Thanks lads

    //atributes for the crop
    private float x,y,width,height;
    private boolean dragging;

    public void mouseClicked(MouseEvent e){}
    public void mouseMoved(MouseEvent e){}
    public void mouseEntered(MouseEvent e){}
    public void mouseExited(MouseEvent e){}


    public void mouseReleased(MouseEvent e)
    {
    if(dragging)
    {
    width=x-e.getX();
    height=y-e.getY();

    if(width<0)
    width*=(-1);

    if(height<0)
    height*=(-1);

    dragging=false;
    }
    }

    public void mousePressed(MouseEvent e)
    {
    x=e.getX();
    y=e.getY();
    }

    public void mouseDragged(MouseEvent e)
    {dragging=true;}

    public BackgroundPanel()
    {
    openDialog();
    setBackground(Color.gray);

    srcImageScroll.addMouseListener(this);
    srcImageScroll.addMouseMotionListener(this);

    }



    note: srcImageScroll is of type DisplayJAI


Comments

  • Registered Users Posts: 6,306 ✭✭✭OfflerCrocGod


    Originally posted by L5
    public void mouseDragged(MouseEvent e)
    {
    dragging=true;
    }
    from what I understand of what you are trying to achive you should be drawing a rectangle inside the MouseDragged event handler a fillrect should do for testing.


Advertisement