Molly Posted June 25, 2014 Share Posted June 25, 2014 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 More sharing options...
Ziy Posted June 25, 2014 Share Posted June 25, 2014 What is the log output when you try?Can we see your onPaint method? Link to comment Share on other sites More sharing options...
Khaleesi Posted June 25, 2014 Share Posted June 25, 2014 (edited) Did the method you used print out anything at all? try to use Mousereleased or Mousepressed instead 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 June 25, 2014 by Khaleesi Link to comment Share on other sites More sharing options...
FrostBug Posted June 25, 2014 Share Posted June 25, 2014 Did you remember to register your mouselistener? eg. bot.addMouseListener(yourListener); 1 Link to comment Share on other sites More sharing options...
Extreme Scripts Posted June 25, 2014 Share Posted June 25, 2014 If i'm not mistaken but I think in OSBot 2 mouseClicked is a deprecated method. 1 Link to comment Share on other sites More sharing options...
Apaec Posted June 25, 2014 Share Posted June 25, 2014 I'll show you how to do it when I'm home, you have to create a mouse action listener probably in your on start. I'll post here in 5hrs or so, if I don't just remind me Link to comment Share on other sites More sharing options...
denoxum Posted June 25, 2014 Share Posted June 25, 2014 (edited) 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 June 25, 2014 by denoxum 1 Link to comment Share on other sites More sharing options...
Molly Posted June 25, 2014 Author Share Posted June 25, 2014 (edited) Problem resolved, just had to add the listener since as you guys said mouseClicked is deprecated in Osbot 2. Edited June 25, 2014 by Molly Link to comment Share on other sites More sharing options...