0

The Second GUI does not appear...

I made 2 interfaces (in the same folder), put a button on one of them and wrote code (I tried many ways) so that the second one opens and the first one closes. The problem is that when you press the button, only the first one disappears, but the second one does not appear. why? what should I do?

30th Apr 2020, 1:11 AM
Hyst1k
Hyst1k - avatar
14 Réponses
+ 3
Hyst1k here's an example with swing. Not pretty, but I think it demonstrates what you're after. https://code.sololearn.com/ci4fKjl9qEQX/?ref=app
30th Apr 2020, 5:59 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
I'm guessing that you're using swing. Should be more like; btn1.setVisible(false); btn2.setVisible(true); You may also need to set the value of enabled for the particular button. This should all be done in the buttons action/ event handler. If you're using one handler for both buttons you'll need to identify the button being passed to the handler. If you want more help you'll need to post your code. Either here in the playground, even though it doesn't work there, or zip it up and post a link to it for download. I typically suggest that you shouldn't use the wysiwyg software until you know how things are supposed to work without them. Just build some things. They don't have to be pretty or polished, but try building yourself a library of easy to read examples for yourself to refer back to when needed.
30th Apr 2020, 4:07 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Impossible for me to tell without seeing the original code. Glad you got it sorted out though. Maybe next time just copy a minimum working example of your code to the playground and post it (kinda like what I did). It makes it much easier to decipher what the issue is.
30th Apr 2020, 6:08 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Share your code and maybe someone will be able to help you. And maybe describe what is intended of it a bit better. Give examples etc.
30th Apr 2020, 1:32 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Which Java GUI engine are you using?
30th Apr 2020, 1:39 AM
Gordon
Gordon - avatar
+ 1
Ill give you the code,just wait 5 min
30th Apr 2020, 6:09 PM
Hyst1k
Hyst1k - avatar
+ 1
It looks like scope resolution issues. Are we talking about just the code in the jToggleButton1ActionPerformed method? If so it doesn't look like there is access to Ventana2 in this file anywhere that I can see. It is destroyed at the end of the method. Also, ask yourself "what is 'this' in the context of the method". If you were trying to access the button passed by the event you could do something like; JToggleButton tempBtn = (JToggleButton)evt.getSource(); // cast to object type tempBtn.setVisible(false);
30th Apr 2020, 6:48 PM
ChaoticDawg
ChaoticDawg - avatar
0
Gordon NetBeans 8.1
30th Apr 2020, 3:08 AM
Hyst1k
Hyst1k - avatar
0
ChaoticDawg Just a Button (Event) with a Interface1.setVisible(false); And Interface2.setVisible(True);
30th Apr 2020, 3:10 AM
Hyst1k
Hyst1k - avatar
0
ChaoticDawg I'm new to Java and GUI but I've already made some progress, you know? I know I haven't seen everything, but I was surprised by the fact that it didn't work, even if Ive already seen buttons and events. Whatever, thanks for your help, I'll see what I do
30th Apr 2020, 1:14 PM
Hyst1k
Hyst1k - avatar
0
ChaoticDawg ok man look
30th Apr 2020, 6:00 PM
Hyst1k
Hyst1k - avatar
0
I did it again from 0 (it didn't take much), step by step, and it worked, I'm not sure why but I think the error could have been some bug, don't you think? I did the exact same code but this time I put the button first and then the rest, it worked lol.
30th Apr 2020, 6:05 PM
Hyst1k
Hyst1k - avatar
0
Don't you know why? Thanks man, I appreciate your help
30th Apr 2020, 6:07 PM
Hyst1k
Hyst1k - avatar