S3R0 Posted March 16, 2016 Share Posted March 16, 2016 Hello, I was wondering if someone could explain a little more in-depth as to how showing/hiding paint works, as far as getting intractable buttons working. I've been trying to follow this tutorial/snippit (bottom of page): http://osbot.org/forum/topic/59574-interactable-paint-not-working-on-osbot-2/ I'm just not sure where to create the buttons, where to place them, etc. Is there an easier way to implement showing and hiding paint with intractable buttons? (as if it's already kinda easy as it is ) Quote Link to comment Share on other sites More sharing options...
Botre Posted March 16, 2016 Share Posted March 16, 2016 You need a rectangle, a boolean and a mouse listener. Rectangle: https://docs.oracle.com/javase/7/docs/api/java/awt/Rectangle.html Has a contains(Point point) method MouseListener: https://docs.oracle.com/javase/7/docs/api/java/awt/event/MouseListener.html mouseClicked(MouseEvent e) MouseEvent has a method called getPoint() To register a MouseListener in OSBot: getBot().addMouseListener(MouseListener m) Create a rectangle Create a boolean Add a new MouseListener to the client When the mouse is clicked, grab the MouseEvent's point and check if the rectangle contains it, if so -> invert the boolean 2 Quote Link to comment Share on other sites More sharing options...
Vilius Posted March 16, 2016 Share Posted March 16, 2016 (edited) Our mouse class public class Mouse implements MouseListener { //create a boolean public boolean hidePaint; @Override public void mouseClicked(MouseEvent e) { //create our point variable Point p = e.getPoint(); //create our rectangle Rectangle rec = new Rectangle(x,y,width,height); //check if the rectangle contains point and change booleans state if(rec.contains(p)) hidePaint = !hidePaint; } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } } Main class public class Main extends Script{ //pas our mouse object Mouse mouse = new Mouse(); public void onStart(){ //add our mouse object as a mouse listener getBot().addMouseListener(mouse); } public void onPaint(Graphics2D g){ //check if our boolean is false if(!mouse.hidePaint){ //draw our stuff } } public int onLoop(){ return 0; } } Hope this helps Edited March 16, 2016 by Vilius 2 Quote Link to comment Share on other sites More sharing options...
S3R0 Posted March 16, 2016 Author Share Posted March 16, 2016 Thank you guys very much for explaining this to me. I really appreciate it. Everything seems to be working perfectly! Quote Link to comment Share on other sites More sharing options...
Ex0rcism Posted October 16, 2017 Share Posted October 16, 2017 On 3/16/2016 at 4:51 AM, Vilius said: Our mouse class public class Mouse implements MouseListener { //create a boolean public boolean hidePaint; @Override public void mouseClicked(MouseEvent e) { //create our point variable Point p = e.getPoint(); //create our rectangle Rectangle rec = new Rectangle(x,y,width,height); //check if the rectangle contains point and change booleans state if(rec.contains(p)) hidePaint = !hidePaint; } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } } Main class public class Main extends Script{ //pas our mouse object Mouse mouse = new Mouse(); public void onStart(){ //add our mouse object as a mouse listener getBot().addMouseListener(mouse); } public void onPaint(Graphics2D g){ //check if our boolean is false if(!mouse.hidePaint){ //draw our stuff } } public int onLoop(){ return 0; } } Hope this helps Thank you, this is exactly what I was looking for. Quote Link to comment Share on other sites More sharing options...