Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

quick question about Frame

 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when creating applets
say i created two Panels, (via Panel p=new Panel)
then i need not specifically write a statement
for it to be added (via add) to the applet GUI
But when creating Frame
say i created two Panels, then i would need
to specifically write a statement for it to
be added (via add) to the Frame GUI.
like add(p); (Panel p = new Panel)
just wanted to reaffirm this......
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure what you are asking, but here is something that might help.
An Applet is a subclass of Panel, thus both use the FlowLayout manager by default.
A Frame is a subclass of Window, thus it uses the BorderLayout manager by default.
In all cases you need to explicitly add a Component to a container such as an Applet, Panel or Frame.
The BorderLayout manager needs to be told where the added component is to be placed (NORTH, SOUTH, WEST, EAST OR CENTER)
[ January 21, 2002: Message edited by: Rajinder Yadav ]
 
mark stone
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>In all cases you need to explicitly add a
>Component to a container such as an Applet,
>Panel or Frame.
not in case of Applet. eg create a Panel, you do not need to explicitly add it. But for Frame you would need to. that's what i am asking to confirm.
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I stated, an Applet is a subclass of Panel thus an Applet "is a" Panel.
You always need to explicitly add a component to a container, both Applet and Panel are containers.
Don't confuse the fact that an Applet is a Panel to meaning the JVM is adding the Panel to the Applet on your behalf.
[ January 21, 2002: Message edited by: Rajinder Yadav ]
 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Rajinder Yadav:
As I stated, an Applet is a subclass of Label, thus an Applet "is a" Label.


What do you mean an Applet is a subclass of Label? I'm confused by what you guys are talking about in this thread. Could you all add some clarification?
Thanks,
Rick
 
mark stone
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
very likely it is typo. what he meant was that
"Applet is a Panel"
i hope the Rjendar is ok with this

Originally posted by Rick Reumann:

What do you mean an Applet is a subclass of Label? I'm confused by what you guys are talking about in this thread. Could you all add some clarification?
Thanks,
Rick

 
Rajinder Yadav
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark for catching my typo, I must be tired!
 
mark stone
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one more.
we can put Panel inside a Frame fine.
can we put Window inside an Applet ??

Originally posted by Rajinder Yadav:
Thanks Mark for catching my typo, I must be tired!

 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
we cant put window inside an applet. they are top level containers and can't be put into another one. same for frame. it will pop up separately and u'll see "Warning: Applet Window" at the bottom of the applet if u r not using Swing's JApplet.
btw, even if we want a panel in applet we MUST add it explicitly to the applet. it can't add it 'automatically' to the applet. so we have two panels P1, P2 which r to be added to the applet Applet1 then we must say,
add(P1);add(P2) in the applet Applet1's init() method.
regards
maulin.
 
mark stone
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"we cant put window inside an applet. they are top level containers and can't be put into another one."
if we can put Panel (top-level) inside Frame
then why cannot we put Window in Applet ?
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi mark,
Panel isnt a Top-Level container. it has to be put in something. (Applet is a different case as it extends Panel and adds extra functionality so that browser can embedd it).
U can't pop up a panel like window. panel doesnt have Title, Border and those buttons to minimize, maximize, cancel (cross button)...
Well, in Swing u can have title to the panel using TitledBorder (I forgot the exact class) but still it can have window like functionality.
can we close an Applet? no. (we can close the browser window displaying it though)
can we minimize an Applet? no.
can we maximize an Applet? no.
hih,
maulin.
 
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic