Author | Topic: Frames |
sree ranch hand |
posted April 19, 2000 01:12 PM
I have a doubt regarding frames. Could somebody please clarify that. Inorder to make a frame visible we have to give both setVisible() and setSize() right? But in the following example the frame is visible even after i commented the setSize(300,300) howcome???please clear this for me.
[This message has been edited by sree (edited April 19, 2000).] [This message has been edited by sree (edited April 19, 2000).] [This message has been edited by sree (edited April 19, 2000).]
|
satya5 ranch hand |
posted April 19, 2000 01:46 PM
As I understand, since the setVisible(true); is called, the frame is visible. However, it's size is not set (atleast on UNIX) since the SetSize() is commented out. Also, please note that a Grid of 2x3 was defined in the Do I make sense or did I get you wrong? Hope this helps. Regds. - satya
|
sree ranch hand |
posted April 19, 2000 02:23 PM
Satya thanks so much for your response.But i am still not clear. Almost every book is saying that by default the frame is invisible. In order to make it visible we have to use either setBounds(),setVisible() or setSize(),setVisible() or pack(),setVisible() right??? Now here even when i just give setVisible() or show() without these size specifying methods i could still very well see the frame. I am little confused with this. Am i not able to understand something here. Thanks a lot friends.
|
satya5 ranch hand |
posted April 19, 2000 03:18 PM
Try commenting out the setVisible() call and see what happens. I ran the code you posted and as expected I could see a small window pop-up on my screen (I am on UNIX). The awt package uses the underlying windowing system to a certain extent. I am not sure of the details to what extent..... This is what I observed : When I comment out setVisible(true); call, When I comment out setSize(300,300); (the setVisible I am not sure of other method calls. Regds. - satya
|
girish greenhorn |
posted April 20, 2000 03:45 AM
Sree, When you use setVisible() for a frame without using setSize() This is what I understand. Rgds
|
sree ranch hand |
posted April 20, 2000 11:25 AM
If you don't call setVisible() and setSize() then the frame doesn't appear. That's what i read. But when i tried not giving setSize() the frame is still being displayed with zero size on the upper left corner of the screen. Then i could resize it. But that doesn't mean that frame is invisible. But when i tried not giving setVisible() then it is totally invisible. Infact there is one question in R&H regarding this. Your application constructs a frame by calling Frame f = new Frame(); but when you run the code,the frame does not appear on the screen.What code will make the frame appear?(choose one) a)setSize(300,200); The answer given is 'e' but even f.setVisible(true) itself alone is working. Thanks. Please clear this for me.
|
sree ranch hand |
posted April 20, 2000 03:24 PM
Maha or Jim if it's not much of a trouble for you could you please clarify this for me. I am sorry i am bothering you. Thanks.
|
maha anna bartender |
posted April 20, 2000 04:30 PM
Sree, When a frame is created, it has 0(zero) pixel width and 0(zero) pixel height. And is an invisible frame also. The setSize(int w,int h) is related to setting the size of the frame. It is NOT related in any way to displaying the frame. The setVisible(boolean b) is the method which is actually responsible for bringing the frame to our eyes. So just setting the size alone WILL NOT make the frame visible.YOu have to give frameRef.setVisible(true); So having said that, given some choices if we have to pickup which will make the frame appear like that, as you say just setVisible(true) alone will make the frame appear. What I think is the author asks is , to pick up the more suitable answer from 5 of the above ans. And he specifically says 'Choose one' in Chapter 11 /page 341. If this qstn would have been a multiple choice , then we can select both d) and e). If there are some ansewers and only one answer has setVisible(true), and none of the other has the setVisible(true) as part of them, then we should select setVisible(true) only. Because this is the method which is responsible for making the frame visible.
|
sree ranch hand |
posted April 21, 2000 10:33 AM
Thanks Maha.
|
| | |