• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple frame, gridbag

 
kevin goon
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Scott, I missed the point.
Jyotsna
 
kevin goon
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int m = 0;
while (m++ < 2)
System.out.println(m);


prints 1,2 why?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic