• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

simple frame, gridbag

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!

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


prints 1,2 why?
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic