This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes simple frame, gridbag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "simple frame, gridbag" Watch "simple frame, gridbag" New topic
Author

simple frame, gridbag

kevin goon
Ranch Hand

Joined: Jun 12, 2001
Posts: 62
Could anyone explain the two questions below??
Q1)
import java.awt.*;
import java.awt.event.*;

public class Test {
public static void main( String args[] ) {
String s = "Happy";
Frame f = new Frame();
Button btn = new Button();
btn.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent e ){
System.out.println( "Message is " + s );
}
}
);
f.add( btn );
f.setVisible( true );
}
}

��A. both compile and runtime is successful but nothing is displayed
��B. both compile and runtime is successful and
if you click button display "Message is Happy
��C. compile is successful but runtime is fail
��D. compile is failed because String s cannot be used .........
��E. compile is failed because class Test ......... not implements ActionListener

ans) D why??

Q2
48. Which statement is true about GridBagLayout ?

��A. Values of weightx and weighty must be in the range 0.0 to 1.0
��B. The fill value for a component is irrelavant if the anchar value is CENTER
��C. The last component in a row must be flagged using the REMAINDER value
��D. The anchor value for a component is irrelavant if the fill value for
the component is BOTH
��E. At most one row can change height and at most one column may change width
when the container is resized

ans ??
thank you so much!

V Srinivasan
Ranch Hand

Joined: Aug 16, 2000
Posts: 99
Hi,
Anonymous Inner Class can access only the final variables of enclosing Class. If you say final string s = "Happy" it will work.
Thanks & regards,
V.Srinivasan
Daniel Wu
Ranch Hand

Joined: Jun 13, 2001
Posts: 58
Originally posted by kevin goon:
48. Which statement is true about GridBagLayout ?

��A. Values of weightx and weighty must be in the range 0.0 to 1.0
��B. The fill value for a component is irrelavant if the anchar value is CENTER
��C. The last component in a row must be flagged using the REMAINDER value
��D. The anchor value for a component is irrelavant if the fill value for
the component is BOTH
��E. At most one row can change height and at most one column may change width
when the container is resized

ans ??
thank you so much!

I think the answer is D.
Jyotsna Umesh
Ranch Hand

Joined: May 09, 2001
Posts: 94
For Question 1 D option is right but i think E should also be right as the class needs to implement ActionListener, isn't it?
For ques. 2 I think ans. is D
Jyotsna
Scott Appleton
Ranch Hand

Joined: May 07, 2001
Posts: 195
Jyotsna, for Q1 answer E is incorrect because class Test does not have to implement the ActionListener interface. Test is not acting as an ActionListener -- the button btn is acting as its own ActionListener by creating an anonymous implementation of an ActionListener and adding that implementation as an ActionListener in the same statement.
Jyotsna Umesh
Ranch Hand

Joined: May 09, 2001
Posts: 94
Thanks Scott, I missed the point.
Jyotsna
kevin goon
Ranch Hand

Joined: Jun 12, 2001
Posts: 62
int m = 0;
while (m++ < 2)
System.out.println(m);


prints 1,2 why?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple frame, gridbag