Mama! My own Layout

Hi folks! This page is under construction, and full-fledgedly so. Infact our manager cancelled his honeymoon to help create our own Layout Managers. :) We will be back here with the explanations soon. As of now, the programs can be tried out. See you. So long. And yes, thanx for visiting our page.


zzz.java

import java.awt.*;
import java.applet.*;
public class zzz extends Applet
{       public void init()
        {       setLayout(new aaa());
        }
}
/* Class aaa not found in new */

aaa.java

import java.awt.*;
import java.applet.*;
class aaa extends LayoutManager
{
}
/* Error: can't subclass interfaces:interface java.awt.LayoutManager */

aaa.java

import java.awt.*;
import java.applet.*;
class aaa implements LayoutManager
{
}
/* Error: 5 errors */

zzz.java

import java.awt.*;
import java.applet.*;
public class zzz extends Applet
{       public void init()
        {       setLayout(new aaa());
                add((new Button("Hell");
                add(new Button("Hello how are you");
                add (new TextField("hi",20);
        }
}
/* Class aaa not found in new */

aaa.java

import java.awt.*;
import java.applet.*;
class aaa implements LayoutManager
{       public void layoutContainer(Container p)
        {       System.out.println("In layoutContainer");
        }
        public Dimension minimumLayoutSize(Container p)
        {       System.out.println("In minimumLayoutSize");
                return (new Dimension(200,300));
        }
        public Dimension preferredLayoutSize(Container p)
        {       System.out.println("In preferredLayoutSize");
                Dimension d = new Dimension(200,40);
                return d;
        }
        public void addLayoutComponent(String n, Component c)
        {       System.out.println("In addLayoutComponent");
        }
        public void removeLayoutComponent(Component c)
        {       System.out.println("In removeLayoutComponent" );
        }
}

aaa.java

import java.awt.*;
import java.applet.*;
class aaa implements LayoutManager
{       public void layoutContainer(Container p)
        {       System.out.println("In layoutContainer");
                System.out.println(p.countComponents());
                Component c = p.getComponent(0);
                c.list();
                Dimension d = c.preferredSize();
                System.out.println("width "+ d.width + "height "+d.height); 
        }
        public Dimension minimumLayoutSize(Container p)
        {       System.out.println("In minimumLayoutSize");
                return (new Dimension(200,300));
        }
        public Dimension preferredLayoutSize(Container p)
        {       System.out.println("In preferredLayoutSize");
                Dimension d = new Dimension(200,40);
                return d;
        }
        public void addLayoutComponent(String n, Component c)
        {       System.out.println("In addLayoutComponent");
        }
        public void removeLayoutComponent(Component c)
        {       System.out.println("In removeLayoutComponent" );
        }
}

aaa.java

import java.awt.*;
import java.applet.*;
class aaa implements LayoutManager
{       public void layoutContainer(Container p)
        {       System.out.println("In layoutContainer");
                Component c = p.getComponent(0);
                Dimension d = c.preferredSize();
                c.reshape(1,30,d.width,d.height);
        }
        public Dimension minimumLayoutSize(Container p)
        {       System.out.println("In minimumLayoutSize");
                return (new Dimension(200,300));
        }
        public Dimension preferredLayoutSize(Container p)
        {       System.out.println("In preferredLayoutSize");
                Dimension d = new Dimension(200,40);
                return d;
        }
        public void addLayoutComponent(String n, Component c)
        {       System.out.println("In addLayoutComponent");
        }
        public void removeLayoutComponent(Component c)
        {       System.out.println("In removeLayoutComponent" );
        }
}

aaa.java

import java.awt.*;
import java.applet.*;
class aaa implements LayoutManager
{       public void layoutContainer(Container p)
        {       System.out.println("In layoutContainer");
                int n = p.countComponents();
                int i; int x = 1;int y = 10;
                for ( i = 0; i< n; i++ )
                {       Component c = p.getComponent(i);
                        Dimension d = c.preferredSize();
                        c.reshape(x,y,d.width,d.height);
                        x=x+d.width+10;
                        y = y+d.height+10;
                }
        }
        public Dimension minimumLayoutSize(Container p)
        {       System.out.println("In minimumLayoutSize");
                return (new Dimension(200,300));
        }
        public Dimension preferredLayoutSize(Container p)
        {       System.out.println("In preferredLayoutSize");
                Dimension d = new Dimension(200,40);
                return d;
        }
        public void addLayoutComponent(String n, Component c)
        {       System.out.println("In addLayoutComponent");
        }
        public void removeLayoutComponent(Component c)
        {       System.out.println("In removeLayoutComponent" );
        }
}

zzz.java

import java.awt.*;
import java.applet.*;
public class zzz extends Applet
{       Button a,b;TextField c;
        public void init()
        {       setLayout(new aaa());
                add(a=new Button("hell"));
                add(b=new Button("hello how are you"));
                add(c=new TextField("hell",60));
        }
         public boolean mouseUp(Event e, int x, int y)
         {      remove(a);
                 return true;
         }
}

zzz.java

import java.awt.*;
import java.applet.*;
public class zzz extends Applet
{       Button a,b;TextField c;
        public void init()
        {       setLayout(new aaa());
                add(a=new Button("hell"));
                add(b=new Button("hello how are you"));
                add(c=new TextField("hell",60));
        }
        public boolean mouseUp(Event e, int x, int y)
        {       remove(a);
                add("Good",new Button("aaa"));
                return true;
        }
}
/*
 For the first time the button with helllabel is removed from the screen,
 and a new button added, but the screen has to be redrawn
 Next time when clicked, only button added

*/

aaa.java

import java.awt.*;
import java.applet.*;
public class aaa implements LayoutManager
{       Container t;
        int n;
        int i,x,y;
        Component c;Dimension d;
        public void layoutContainer(Container p)
        {       t = p;
                n = p.countComponents();
                System.out.println("layoutContainer no =" + n);
                i=0;x = 1;y = 10;
                for (i=0;i


Grappling with the LayoutManager would have been tough on you (and believe me, they don't teach about Layout Managers even in the Harvard Business School!). Grab a coke and grope to the next topic "The Ribbons and the Topknots" or just lay your troubles, comments and suggestions on our shoulders.
Back to our Java page

Vijay Mukhi's Computer Institute
B-13, Everest Building, Tardeo, Bombay 400 034, India.
http://www.neca.com/~vmis
e-mail : vmukhi@giasbm01.vsnl.net.in
1