Author Topic:   Intersting Question 4 U
Dre
unregistered
posted March 31, 2000 07:01 PM           
What is the result of attempting to compile and execute the following application?

1. import java.awt.*;
2.
3. public class Q2 extends Frame {
4. Q2() {
5. setSize(300, 300);
6. Button b = new Button("Apply");
7. add(b);
8. }
9.
10. public static void main(String args[]) {
11. Q2 that = new Q2();
12. that.setVisible(true);
13. }
14. }


i haven't seen 'that.' before...Try compiling the code!!

Howard Stern
ranch hand
posted March 31, 2000 09:05 PM             
A frame will be created with "Apply" button covering the whole area as it would with the default borderLayout as the layout manager. What is the catch?

rahul_mkar
greenhorn
posted March 31, 2000 09:05 PM             
Hi,

the code works fine. it compiles, shows a button. so what is the problem. that is just a literal. u can use any combination of letters as literals as long as it is not a reserved word and begins with a letter or a $ or a "_". also it must not be "true" ,"false" or "null".

------------------

nirvan sage
greenhorn
posted March 31, 2000 11:33 PM             
I think dre didnt notice that 'that' refers to an object.The code should work fine.

maha anna
bartender
posted April 01, 2000 07:29 AM             
The give java appln code is perfectly fine. Since BorderLayout is default for Frame, and 'Center' position is default position when no position is specified for add(..) method using this layout, one center button occupying all spaces of the frame WILL be displayed because the frame has setsize(..) and setVisible(true).

Dre,what are you trying to say..?
regds
maha anna

dre
unregistered
posted April 01, 2000 07:45 AM           
that.setVisible(true); <<
dre

dre
unregistered
posted April 01, 2000 07:49 AM           
that.setVisible(true);

I never seen 'that.' before, I know 'this' keyword, it means the current object, is 'that' a keyword too?

Milind
ranch hand
posted April 01, 2000 08:25 AM             
'that' is not a keyword and it's leagal !!
Regds,
Milind

maha anna
bartender
posted April 01, 2000 08:31 AM             
dre,
I think you are bringing the inherrent meaning of 'this' keyword here. The keyword 'this' and the identifier 'that' are no way related in Java language though they are somehow related in English Language. .

So the 'that' identifier is used as an object reference var here.
regds
maha anna

[This message has been edited by maha anna (edited April 01, 2000).]

|