abdulr 0 Share Posted December 27, 2018 how do i have a rectangle area on my screen - if clicked either hide or show the onPaint function Link to comment Share on other sites More sharing options...
Nex 2516 Share Posted December 27, 2018 boolean hidePaint = false; Rectangle rect = new Rectangle(296, 444, 200, 16); Rectangle closePaint = rect; Rectangle openPaint = rect; Point p; public void onMouse(MouseEvent e) { p = e.getPoint(); if (closePaint.contains(p) && !hidePaint) { hidePaint = true; } else if (openPaint.contains(p) && hidePaint) { hidePaint = false; } } @Override public void onPaint(Graphics g) { if (!hidePaint) { ....... } if (hidePaint) { ..... } } Evil Bob and Semper Fi 1 1 Link to comment Share on other sites More sharing options...
abdulr 0 Author Share Posted December 27, 2018 thank you Link to comment Share on other sites More sharing options...
Evil Bob 5 Share Posted December 27, 2018 3 hours ago, Nex said: boolean hidePaint = false; Rectangle rect = new Rectangle(296, 444, 200, 16); Rectangle closePaint = rect; Rectangle openPaint = rect; Point p; public void onMouse(MouseEvent e) { p = e.getPoint(); if (closePaint.contains(p) && !hidePaint) { hidePaint = true; } else if (openPaint.contains(p) && hidePaint) { hidePaint = false; } } @Override public void onPaint(Graphics g) { if (!hidePaint) { ....... } if (hidePaint) { ..... } } If the rectangle for closing and opening the paint points to the same memory address, you could take advantage of this and cut the number of lines of code in half. private boolean hidePaint = false; private final Rectangle PAINT_BUTTON = new Rectangle(296, 444, 200, 16); @Override public void onMouse(MouseEvent e) { if (PAINT_BUTTON.contains(e.getPoint())) hidePaint = !hidePaint; } @Override public void onPaint(Graphics g) { if (!hidePaint) { // ... } else { // ... } } Nex 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now