This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Questions from geocities silicon valley

 
shabbir zakir
Ranch Hand
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 159
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please search for this topic it was discussed before
Cherry
 
Rakesh Sharma
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
But we have added this four times. Please provide the link for this topic.
 
shabbir zakir
Ranch Hand
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
Please explain me the answer for this query
 
Wasim Ahmed
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

No one has any comments.I am suprised.

 
Sowmya Vinay
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic