Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Mouse motion/listener problems

  • 21-04-2004 01: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, Registered Users 2 Posts: 6,345 ✭✭✭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