March 16, 20169 yr 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 )
March 16, 20169 yr 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
March 16, 20169 yr 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, 20169 yr by Vilius
March 16, 20169 yr Author Thank you guys very much for explaining this to me. I really appreciate it. Everything seems to be working perfectly!
October 16, 20178 yr 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.
Create an account or sign in to comment