+ 3

Java Question

How to make selected item of different when open by two different buttons when they open the mainframe with combobox in java https://github.com/Abrico2001/TwoButtonMainFrame/tree/master/src/twoButtonMainFrame

28th Jul 2019, 12:34 AM
abraha Tekulu
abraha Tekulu - avatar
19 Respostas
+ 3
abraha Tekulu Indeed... I believe my understanding matches your understanding perfectly. Apologies if that wasn't clear in my detailed response. It's difficult to be concise when explaining how someone else's code works using a text based platform like SoloLearn. Let me know if my explanation is difficult to understand or if you are unable to find a solution based on this explanation. I can try to make a video where I show the code using a debugger and then implement a simple fix. However, due to my busy work schedule, I may not have time until this weekend. Also, I'm not sure how difficult it would be to follow a technical video like this spoken in English without translations for you. Let me know and we can try something that might work.
30th Jul 2019, 7:21 AM
David Carroll
David Carroll - avatar
+ 6
abraha Tekulu I must say, this code was very difficult to follow and figure out what was going on and what was expected. The names are very esoteric and I've probably spent more time on trying to figure out what the code is supposed to do and what it wasn't doing. That said, I think I understand the issue after having reread your question multiple times and stepped through the code to observe the behavior. I'm going to follow up with an attempt at an explanation in my next post. However, I'm probably not the best person to help with this particular project moving forward. I simply don't have the time to spend on something this confusing. I do hope you find someone who does work with Java Swing to provide you assistance. See my next response for a direct answer. I'll need a few minutes. [UPDATE:] I'll need to respond in a few hours. I just realized it's time for me to meet with my dev team.
30th Jul 2019, 2:24 AM
David Carroll
David Carroll - avatar
+ 5
Before I forget, which IDE do you use?
28th Jul 2019, 2:55 AM
David Carroll
David Carroll - avatar
+ 4
David Carroll I add the code to github. You can run the code , run Twobuttontest class as main. Then open the child class 1) within B1 then Select "Cooperation" combobox item from "Type" , also select one item from component one and from component two , "save" button 2) the same with B2 ) see what will happen when .... The main point when we do action with B1 nothing should happen on B2
28th Jul 2019, 1:06 AM
abraha Tekulu
abraha Tekulu - avatar
+ 3
Just saying that Stack Overflow could be a great site/resource for these questions.
29th Jul 2019, 6:03 AM
Sonic
Sonic - avatar
+ 3
abraha Tekulu Are these the only files in your Eclipse project? I was hoping to simply do a git clone and run the project as you already have it set up.
29th Jul 2019, 8:51 PM
David Carroll
David Carroll - avatar
+ 3
[Solution Part 2 of 2] See Link: https://github.com/Abrico2001/TwoButtonMainFrame/blob/master/src/twoButtonMainFrame/HidingAndCooprationCombo.java#L183 frame.add(topPanel); frame.setSize(getPreferredSize()); frame.setVisible(true); Note, that Line 183 doesn't actually replace the previous (topPanel). Rather, it simply appends it to the static (frame). However, the initial (topPanel) appears each time a button is clicked showing the previously selected combo box options. If you add the following code after Line 183, you'll see the value increase in the console output: System.out.println("Content Component Count: " + frame.getContentPane().getComponentCount()); So far, I've only explained why this is happening. I have a feeling you will be able to use this information to find a solution for loading a different (topPanel) for each respective button. I hope this was helpful. Best of luck on this, ~David Carroll
30th Jul 2019, 6:49 AM
David Carroll
David Carroll - avatar
+ 3
BTW... Is this for a class project or something like that. It doesn't matter either way. I'm just curious. šŸ˜‰
30th Jul 2019, 7:29 AM
David Carroll
David Carroll - avatar
+ 2
David Carroll I use eclipse
28th Jul 2019, 9:07 AM
abraha Tekulu
abraha Tekulu - avatar
+ 2
abraha Tekulu I haven't. Apologies. I've got quite a bit on my plate at the moment with work. However, I will try to set aside 30 minutes or so to review everything in the next day or so. In the meantime, hopefully someone here can assist with this Java Swing related question.
29th Jul 2019, 8:49 PM
David Carroll
David Carroll - avatar
+ 2
[Solution Part 1 of 2] abraha Tekulu My understanding of the issue is as follows: You have multiple buttons on one instance of a JFrame derived class that should each open a separate instance of the another JFrame derived class with form controls storing their own respective values. However, each button "appears" to open a shared instance of the same JFrame derived class. You want to understand why and how to make it so each button opens their own respective instances with their own respective values. In your demo, each button does open a new instance of the same JFrame derived class. However, the JFrame that appears isn't the new instance being created. Rather, it's a static JFrame (frame) declared on line 59 that is displayed everytime you click a button. This occurs on line 183 to 185, where you add an instance of a JPanel (topPanel) to the static (frame) variable, then set the size and visibility to appear. (Continued...)
30th Jul 2019, 6:47 AM
David Carroll
David Carroll - avatar
+ 1
I use eclipse
29th Jul 2019, 2:42 AM
Shyam
+ 1
Sonic I will post at that also thanks
29th Jul 2019, 6:04 AM
abraha Tekulu
abraha Tekulu - avatar
+ 1
David Carroll I want to open 1frame each....then if B1 .... Opens child frame... Select combobox values... "Cooperation"..."hello1" ...."hello1".......then save button to dispose the frame.but when I open B2 I see items selected but I didn't want ,I want to select different items with that button.... like "hello2" ..."hello2" when I performing the same action as B1
30th Jul 2019, 6:57 AM
abraha Tekulu
abraha Tekulu - avatar
+ 1
David Carroll thanks very much for your efforts. I will try your ideas and suggestions later and I will inform you.
30th Jul 2019, 7:07 AM
abraha Tekulu
abraha Tekulu - avatar
+ 1
David Carroll ok great I will also send you video , by running what Iam doing and what my question is. I will share it the video to YouTube and I will share you the link.if you speak English it is not a problem for me , I speak English.
30th Jul 2019, 7:25 AM
abraha Tekulu
abraha Tekulu - avatar
+ 1
No, class project ,I sent you only some part of the code. Mainly logic part is large , it is thesis project , David.
30th Jul 2019, 7:34 AM
abraha Tekulu
abraha Tekulu - avatar
0
David Carroll do you run the code?
29th Jul 2019, 2:29 PM
abraha Tekulu
abraha Tekulu - avatar
0
David Carroll I minimize the code ,I want to run it see what the output is.so I want to understand what my question is.
29th Jul 2019, 9:21 PM
abraha Tekulu
abraha Tekulu - avatar