import java.awt.*;
import java.applet.*;
/*
<applet code="GridLayoutDemo" width=300 height=200>
</applet>
*/public class GridLayoutDemo extends Applet
{
static final int n=4;
public void init()
{
setLayout(new GridLayout(n,n));
setFont(new Font("SansSerif",Font.BOLD,24));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
{
int k=i*n+j;
if(k>0)
add(new Button(""+k));
}
}
}
}
Border Layouts…
Example : BorderLayoutDemo
import java.awt.*;
import java.applet.*;
import java.util.*;
/*
<applet code="BorderLayoutDemo" width=400 height=200>
</applet>
*/
public class BorderLayoutDemo extends Applet
{
public void init()
{
setLayout(new BorderLayout());
add(new Button("This is across the top."),BorderLayout.NORTH);
add(new Label("The Footer message might go here."),BorderLayout.SOUTH);
add(new Button("Right"),BorderLayout.EAST);
add(new Button("Left"),BorderLayout.WEST);
String msg="The reason able man addas"+ "him self to the world;\n"+"the unreasonable onw presits in"+"trying to adopts the world to himself.\n"+"Therefre all progream depends"+"On the unreasonalbe man.\n\n"+"-George Berand shaw\n\n";
add(new TextArea(msg),BorderLayout.CENTER);
}
}
Insets…
Example : BorderText
import java.awt.*;
/*
<applet code="BorderText" width=200 height=300>
</applet>
*/
public class BorderText extends java.applet.Applet
{
public void init()
{
setLayout(new BorderLayout(5,5));
add("South",new Button("Button of the Applet"));
add("North",new Button("Top of the Applet"));
add("East",new Button("Right"));
add("West",new Button("Left"));
add("Center",new TextArea("Appears at the center"));
}
public Insets getInsets()
{
return new Insets(20,20,10,10);
}
}
Creating a Frame Window in an Applet…
Example : FrameApplet
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<applet code="FrameApplet.class"width=250 height=200>
</applet>
*/
class Frame2 extends Frame
{
Frame2(String title)
{
super(title);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we)
{
dispose();
}
});
}
}
public class FrameApplet extends Applet implements ActionListener
{
public void init()
{
Button b=new Button("Create Frame");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent ae)
{
Frame2 f2=new Frame2("My new Window");
f2.show();
f2.setSize(300,300);
}
}