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 2542 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) { ..... } } 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 { // ... } } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.