Flow Layout in Applet not working in child Object


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Flow Layout in Applet not working in child Object

Hybrid View

  1. #1
    Join Date
    Dec 2005
    Posts
    2

    Flow Layout in Applet not working in child Object

    As a starting point, this simple Flow Layout works:

    //*****start applet code example1****
    import java.awt.*;
    import java.applet.*;
    public class Layout extends Applet
    {
    Button okButton1;

    public void init()
    {
    setLayout(new FlowLayout());

    okButton1 = new Button("OneButton");

    add(okButton1);
    }
    }

    //******end applet code example 1****

    But if I try to invoke create the Layout in a child, it does not work:

    //******start code applet example 2****
    import java.awt.*;
    import java.applet.*;
    public class Layout2 extends Applet
    {

    LayoutChild myChild;

    public void init()
    {
    myChild = new LayoutChild();
    }
    }

    public class LayoutChild extends Applet
    {
    Button okButton1;

    public void init()
    {

    setLayout(new FlowLayout());

    okButton1 = new Button("OneButton");

    add(okButton1);
    }
    }

    //******end code applet example 2****

    I'm sure it is something simple. Anyone know? Thanks.

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    What do you mean it doesn't work? What does it do instead? And you should only have to use 1 "Applet", I'm not sure what you're trying to do here.

  3. #3
    Join Date
    Dec 2005
    Posts
    2
    I'm trying to have an Applet with many button present on say the left Nav bar. When you click on a particular button, a corresponding data entry form appears in the center of the page. Click a different button, then a different form appears.

    To keep the code clean, I want each entry form to be it's own object. Thus the need to have Swing components work down at the child object level.

    And by 'not working', I mean that in the second example, the swing components do not appear on the screen. (The compile works.)

    I was wondering if at the child level you must specifically get the Pane of the Applet and then add the components to that pane?

    What does work is if I pass the Applet obj down to the child like this:


    myChild = new LayoutChild(this);


    and then use the passed applet parameter to add components like this:


    myParent.setLayout(new FlowLayout());
    myParent.add(....



    But that defeats the idea of keeping the child Object self-contained. It seems to me that the child obj should be able to manage the swing components on its own without knowing anything about the parent object.

    So is there a way to add swing components to the child? Do I need to get the Applet Pane? I'm not sure how to do that...

    Thanks.
    Last edited by Semper; 12-20-2005 at 10:01 AM.

Similar Threads

  1. Replies: 10
    Last Post: 04-06-2005, 05:30 PM
  2. Replies: 3
    Last Post: 03-18-2005, 04:22 PM
  3. Replies: 1
    Last Post: 10-04-2002, 08:24 AM
  4. Even C++ had this much right...
    By Derek Mooney in forum .NET
    Replies: 94
    Last Post: 10-29-2001, 08:44 PM
  5. Replies: 7
    Last Post: 06-26-2001, 06:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center