This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Questions from geocities silicon valley Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Questions from geocities silicon valley" Watch "Questions from geocities silicon valley" New topic
Author

Questions from geocities silicon valley

shabbir zakir
Ranch Hand

Joined: Nov 12, 2000
Posts: 183
import java.applet.*;
import java.awt.*;
public class Q16 extends Applet
{
Button okButton = new Button("Ok");
public void init()
{
add(okButton);
add(okButton);
add(okButton);
add(okButton);
add(new Button("Cancel"));
add(new Button("Cancel"));
add(new Button("Cancel"));
add(new Button("Cancel"));
setSize(300,300);
}
// <applet code = Q16.java width = 300 height = 300 > </applet>
}
This code compiles and exceutes with one "ok" Button and four "cancel" Buttons.
Why does this code does not show the other three buttons
Q.2)
: import java.applet.*;
2: import java.awt.*;
3:
4: public class Q20 extends Applet
5: {
6: Button okButton = new Button("Ok");
7:
8: public void init()
9: {
10: setLayout(new BorderLayout());
11:
12: add("South", okButton);
13: add("North", okButton);
14: add("East", okButton);
15: add("West", okButton);
16: add("Center", okButon);
17:
18: setSize(300,300);
19: }
20: }
Why does this code doesn't give any error beacause there is no such add method.
Cherry Mathew
Ranch Hand

Joined: Dec 26, 2000
Posts: 159
please search for this topic it was discussed before
Cherry
Rakesh Sharma
Ranch Hand

Joined: Dec 29, 2000
Posts: 37
Reply to your first Que is that you have created only one "OK" button. So what is you are adding it four times. It will be shown only once. For "Cancal" Buttons, you have created four Buttons and added then. So four "Cancel" Buttons are shown.
shabbir zakir
Ranch Hand

Joined: Nov 12, 2000
Posts: 183
hi!
But we have added this four times. Please provide the link for this topic.
shabbir zakir
Ranch Hand

Joined: Nov 12, 2000
Posts: 183
hi!
Please explain me the answer for this query
Wasim Ahmed
Ranch Hand

Joined: Jan 31, 2001
Posts: 90
Shabbir, The keyword is "new". You have created OK Button only one time(1 new) and Cancel Button 4 times(4 new). Whenever you use "new" keywrod with any type you create one new object of that type. Hope it helps, correct me if I am wrong.
shabbir zakir
Ranch Hand

Joined: Nov 12, 2000
Posts: 183

No one has any comments.I am suprised.

Sowmya Vinay
Greenhorn

Joined: Feb 01, 2001
Posts: 24
Wasim is correct regarding first question.
Regarding your second doubt,there is an add method as given by the following signature: add(String s,Component comp); Hence the program doesn't give any error. Please refer to the javadoc documentation of class Container in package java.awt. http://java.sun.com/products/jdk/1.2/docs/api/index.html

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions from geocities silicon valley
 
Similar Threads
Applet Question.
AWT
Buttons
applet&buttons
awt