Jump to content

Hide and unhiding paint.


Guest Apogee

Recommended Posts

Guest Apogee

I have a working paint, i also have the button to hide/unhide it. (The PNG image, not the coded side.)

I've looked through the API, and i'm still unsure of how to hide and show paint.

Link to comment
Share on other sites

Guest Apogee

 

you just listen for mouse actions and change a boolean dependent on the mouse action.

 

PSEUDO CODE

IF NOT HIDEPAINT
    SHOWPAINT
END IF

IF MOUSEACTION ON DESTATION
    CHANGE BOOLEAN
END IF

That sadly only helps with the idea. I am completely new to scripting. If you could tell me how to set a png image to be clicked to show/hide paint, that would be incredibly helpful and i would be very thankful. :)

Still looking how to do this.

Link to comment
Share on other sites

You need to create a Rectangle object to reference the area where your hide paint button is, and a boolean value to reflect whether it was clicked to show or hide the paint. Then override the mousePressed listener like so (obviously creating the needed variables):

@Override
public void mousePressed(MouseEvent e) {
    if (hidePaintRectangle.contains(e.getPoint())) {
        showPaint = !showPaint;
    }
}
  • Like 1
Link to comment
Share on other sites

I do this:

set a boolean defined as:

    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

            }

    }
Link to comment
Share on other sites

Guest Apogee

I do this:

set a boolean defined as:

 

    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

            }

    }

 

 

Helped me beautifully. Thank you very much.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...