private boolean hide = false;
Then need to set the area for when the mouse is clicked. Two rectangles are set, point p then gets the mouse click and if that point is in the rectangles opens/closes depending on what the boolean is set at.
public void mouseClicked(MouseEvent e) {
Point p;
Rectangle close = new Rectangle(490, 346, 20, 25);
Rectangle open = new Rectangle(490, 346, 20, 25);
p = e.getPoint();
if (close.contains(p) && !hide) {
hide = true;
} else if (open.contains(p) && hide) {
hide = false;
}
}
Then the paint just checks the boolean to see if its false/true and shows the corresponding image and other gibberish.
public void onPaint(Graphics g) {
if (!hide) {
//if boolean is currently not hiding then shows all information
g = (Graphics2D)g;
g.drawImage(img3, 7, 344, null);
//other important information down here
} else {
//if boolean says hidden then draws image where you want it to be
g.drawImage(img2, 490, 346, null);
//usually just a simple 'X' or show paint
}
}