Jump to content

Problem hiding/showing paint.


Molly

Recommended Posts

I am trying to hide/show my paint with the click of an area on the paint. My code is as follows:

 

public void mouseClicked(MouseEvent e) {
log("Clicked somewhere");
        Point clicked;
        Rectangle PaintButton = new Rectangle(475, 350, 19, 18);
        clicked = e.getPoint();
        if (PaintButton.contains(clicked) && !ShowPaint) {
        log("Showing paint");
            ShowPaint = true;
        } else if (PaintButton.contains(clicked) && ShowPaint) {
        log("Hiding paint");
            ShowPaint = false;
        }
 
    }
 
The paint will not toggle as I wish, any help is appreciated.

 

Link to comment
Share on other sites

Did the method you used print out anything at all?

try to use Mousereleased or Mousepressed instead smile.png

 

Try this:

public void mousePressed(MouseEvent e) {
    Point clicked = e.getPoint();;
    Rectangle paintButton = new Rectangle(475, 350, 19, 18);
    if (paintButton.contains(clicked))
        showPaint = !showPaint;
    
}

This just reverses the ShowPaint boolean.

 

in the onPaint method in you do the folowing:

public void onPaint(Graphics2D g){

   if(showPaint){
       //draw your paint :)

   }else{

      //draw a "X" or image so pll know where to click again on unhide it the paint

   }

}

 

PS: try the folow java conventions, they will make it easier to read for other people ^^

A variable starts with a "lowerCase" letter.

 

You can always pm me on skype when you got more questions!

 

Khaleesi

Edited by Khaleesi
Link to comment
Share on other sites

this.bot.addMouseListener(new java.awt.event.MouseListener() {




@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub


}


@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub


}


@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub


}


@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}


@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub


/*
* 
* GUI ON/OFF
* 
*/


 YOUR CODE HERE
}


});

MouseClicked = deprecated in OSbot 2, you need to attach your own mouseListener

 

Edited by denoxum
  • Like 1
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...