
-----------------------------------
deville75
Thu Mar 09, 2006 1:20 am

Multiple swing Windows
-----------------------------------
It's been a while since i've done swing and the experience i have itself isnt very much.  I have a program that opens multiple windows, but wen i close one all of them close.  How do I close only one at a time?

-----------------------------------
wtd
Thu Mar 09, 2006 1:49 am


-----------------------------------
Obviously somewhere you've said that the window-closing event for any oif the windows terminates the entire application.  Only set this for a "main" window.

-----------------------------------
deville75
Thu Mar 09, 2006 1:01 pm


-----------------------------------
ok i think i've found out how. I'm just wondering if this is an efficient or valid way, becuase sometimes things work even tho it shouldn't be done that way.

Basically the program would make instances of other classes that would open a new window. So i had one class called Mainform and when u clicked on one of the buttons it created a new object of the class NewWindow for example, which would open a new window. At first, I had the following code in both of the classes:


setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);


but now i deleted this from the NewWindow class and it works like it should. Is this proper?

-----------------------------------
wtd
Thu Mar 09, 2006 1:08 pm


-----------------------------------
You tested it.  It worked.  Why ask me if it's proper or not? :)

You have to have confidence in your code.  You have to be willing to stand up to a challenge and say, "yes, my code does work!"

Of course, you also have to be ready to be wrong from time to time.  ;)

Yes, removing that is fine.

-----------------------------------
Justin_
Thu Mar 09, 2006 8:44 pm


-----------------------------------
That's shocking coming from you wtd.  You give the impression that it's best to follow the standards...

-----------------------------------
wtd
Thu Mar 09, 2006 8:58 pm


-----------------------------------
Where am I advocating something non-standard in this thread?

Some of your posts lately have been really odd, Justin_.  Please give more thought to them in the future.

-----------------------------------
Justin_
Thu Mar 09, 2006 9:07 pm


-----------------------------------
Yeah, maybe something is wrong with me cause I don't see how you don't understand what I mean.  The guy asked if his way of doing things was standard, essentially.  And you replied with an uplifting speech about how he should go about and do his own thing with confidence as long as it works.

-----------------------------------
wtd
Thu Mar 09, 2006 9:11 pm


-----------------------------------
There is no one set way of doing things when the behavior desired varies.  Is he using weird code not included in the standard library?  If not, then yes... there's an issue with standards, but otherwise, if it works, go with it.

Of course, there might be better ways to get the job done, but that doesn't mean the first attempt was wrong.

-----------------------------------
Justin_
Thu Mar 09, 2006 9:17 pm


-----------------------------------
Yes but imagine you were new to programming and you put together a method of doing something but were unsure if it was considered proper, or standard, or whatever you want to call it.  Essentially something that isn't frowned upon by other programmers.  And to take a shortcut, you decided to ask a gifted programmer if it was okay to do something in such a way.  What you said about confidence, although its okay to be confident, in the end all confidence will do is slow you down.  If you're using deprecated code without realizing it, the longer you wait to learn the contemporary, the longer you are wasting your time.  

I think its perfectly valid to ask if something is okay.  Especially if you're new.

-----------------------------------
wtd
Thu Mar 09, 2006 9:19 pm


-----------------------------------
It is... however...

If you write some code, and it works, then do not ask me if it works.  :)

-----------------------------------
Justin_
Thu Mar 09, 2006 9:23 pm


-----------------------------------

Code:
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);



but now i deleted this from the NewWindow class and it works like it should. Is this proper? 

Good thing no one asked you if it works.[/quote]

-----------------------------------
wtd
Thu Mar 09, 2006 9:33 pm


-----------------------------------
Oh, and I did answer the question.  Perhaps you would care to read my posts.

Please do not try to flame me.

-----------------------------------
Justin_
Thu Mar 09, 2006 9:48 pm


-----------------------------------
Redherring are we?  

If you write some code, and it works, then do not ask me if it works.  

I was merely responding to your statement.  I wouldn't flame you, but we are in a kind of debate here.

-----------------------------------
deville75
Sat Mar 11, 2006 2:05 pm


-----------------------------------
LOL

OMG :shock: WUT HAV I STARTED!

-----------------------------------
wtd
Sat Mar 11, 2006 2:09 pm


-----------------------------------
It's not your fault.  :)

-----------------------------------
Justin_
Sat Mar 11, 2006 4:20 pm


-----------------------------------
Just to clarify, I enter debates with an academic objective.  wtd was getting a little defensive there for no reason.

-----------------------------------
md
Sat Mar 11, 2006 4:58 pm


-----------------------------------
I disagree. I would argue that wtd's position is well justified, whereas you are arguing for the sake of arguing. A working solution is the first goal; once you know it works you can worry about if it conforms to conventions, which you don't need to follow if you prefer not to.

-----------------------------------
Justin_
Sat Mar 11, 2006 5:07 pm


-----------------------------------
You might be right Cornflake, but I did feel that wtd was giving mixed messages and not understanding where I was coming from.
