Computer Science Canada

Multiple swing Windows

Author:  deville75 [ Thu Mar 09, 2006 1:20 am ]
Post subject:  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?

Author:  wtd [ Thu Mar 09, 2006 1:49 am ]
Post subject: 

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.

Author:  deville75 [ Thu Mar 09, 2006 1:01 pm ]
Post subject: 

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:


code:
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);



but now i deleted this from the NewWindow class and it works like it should. Is this proper?

Author:  wtd [ Thu Mar 09, 2006 1:08 pm ]
Post subject: 

You tested it. It worked. Why ask me if it's proper or not? Smile

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. Wink

Yes, removing that is fine.

Author:  Justin_ [ Thu Mar 09, 2006 8:44 pm ]
Post subject: 

That's shocking coming from you wtd. You give the impression that it's best to follow the standards...

Author:  wtd [ Thu Mar 09, 2006 8:58 pm ]
Post subject: 

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.

Author:  Justin_ [ Thu Mar 09, 2006 9:07 pm ]
Post subject: 

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.

Author:  wtd [ Thu Mar 09, 2006 9:11 pm ]
Post subject: 

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.

Author:  Justin_ [ Thu Mar 09, 2006 9:17 pm ]
Post subject: 

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.

Author:  wtd [ Thu Mar 09, 2006 9:19 pm ]
Post subject: 

It is... however...

If you write some code, and it works, then do not ask me if it works. Smile

Author:  Justin_ [ Thu Mar 09, 2006 9:23 pm ]
Post subject: 

Quote:

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]

Author:  wtd [ Thu Mar 09, 2006 9:33 pm ]
Post subject: 

Oh, and I did answer the question. Perhaps you would care to read my posts.

Please do not try to flame me.

Author:  Justin_ [ Thu Mar 09, 2006 9:48 pm ]
Post subject: 

Redherring are we?

Quote:
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.

Author:  deville75 [ Sat Mar 11, 2006 2:05 pm ]
Post subject: 

LOL

OMG Shocked WUT HAV I STARTED!

Author:  wtd [ Sat Mar 11, 2006 2:09 pm ]
Post subject: 

It's not your fault. Smile

Author:  Justin_ [ Sat Mar 11, 2006 4:20 pm ]
Post subject: 

Just to clarify, I enter debates with an academic objective. wtd was getting a little defensive there for no reason.

Author:  md [ Sat Mar 11, 2006 4:58 pm ]
Post subject: 

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.

Author:  Justin_ [ Sat Mar 11, 2006 5:07 pm ]
Post subject: 

You might be right Cornflake, but I did feel that wtd was giving mixed messages and not understanding where I was coming from.


: