We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello. I am new to processing and want to start with a simple program. This program should display images in seperate windows with seperate window sizes. I also need a notification, if a window is closed/opened. I want to use the G4P library, but if I use the background image I always get the message, that the image size must be the same size as the application. How could I check if a window is closed/opened? I want to display a warning image if a value has reached, but it only have to display again, if the window is closed. I think its easy, but I dont know how. I hope someone could help me. Thanks for helping.
Answers
So what's the question? How to check if a window is opened/closed?
In that case, you would use
frame.getExtendedState()
. To show on your example it would work like this:Just note that this must be done in draw(), or some other looping function.
-- MenteCode.
I want to open a second window to the sketch window. And the second window should display an image. I started with G4P library and tryed the constructor with a background image, but the image have a different size of the sketch window and doesn't work. How can I display an image in the second window and I need to know, if this second window with the image is closed?
If you use the statement
`background(image);'
then the image MUST be the same size as the sketch/window display area. This is a Processing warning and nothing to do with G4P.
If you want to use the
background
statement with a GWindow then you have to use the constructor that takes a PImage object so it can create the window with a display size that is the same as the image.If you simply want to display an image in an existing GWindow then you should not use the
background
statement.If we have created a global GWindow reference called window with this statement
and in setup created the window with these statements
then in window's draw method we can display an image like this
where
img
is a preloaded PImage.To check whether this GWindow object is open or closed then use
Thanks for the helping. Is it possible not to draw the window in the setup but at a point in the code (in draw() function)? I want to open a seperate window, if a variable reached a certain value. If I creat the window in setup, the window shows at the start of the sketch. An if I try the method G4P.getOpenWindowsAsList().contains(window); I get the following error message: The method getOpenWindowsAsList(ArrayList) in the type G4P is not applicable for the arguments () What is my mistake? Thanks for your helping.
You can attempt to create the GWindow inside draw() but it may cause problems - I have not tried it myself.
If you create the window in setup and make it invisible, then when your variable reaches the appropriate value then make it visible.
Sorry I made a slight mistake in the code to test whether a window is open it should have been
Anyway the following example makes the GWindow in setup and makes it invisible. When the sketch runs the window will remain invisible for 10 seconds. Once visible click on the windows close icon and it will be reported that the window is closed.
Thank for you help. It works perfectly, but now I want to add a button to a GWindow. If the button is pressed, the window should become invisible. I can create a button, but how can I add it to the separate window and not to the mainsketch. window.add(button) does not work.
Thanks alot I figured that out. I have to give the constructor of the button the corresponding window in which the button should placed.