Download Online version 3.4
Transcript
Chapter 12
add(new
add(new
add(new
add(new
AWT Based Windows Programming
Button("
Button("
Button("
Button("
194
Spurs"));
Chelsea"));
West Ham"));
Crystal Palace"));
}
}
12.12.3 GridLayout
This layout manager divides the screen into a grid of rows and columns. Objects are added
at the top left and we move horizantally until the row is full.
import java.awt.*;
public class c1131 extends java.applet.Applet
{
public void init()
{
// layout using the GridLayout mananger
Font f=new Font("Arial",Font.PLAIN,20);
setFont(f);
setLayout(new GridLayout(4,2));
add(new Button(" QPR"));
add(new Button(" Arsenal"));
add(new Button(" Spurs"));
add(new Button(" Chelsea"));
add(new Button(" West Ham"));
add(new Button(" Crystal Palace"));
}
}
12.12.4 Gridlayout with size
Similar to GridLayout, but now the components can vary in size.
import java.awt.*;
public class c1132 extends java.applet.Applet
{
public void init()
{
// layout using the GridLayout mananger
Font f=new Font("Arial",Font.PLAIN,20);
setFont(f);
setLayout(new GridLayout(4,2,10,10));
add(new Button(" QPR"));
add(new Button(" Arsenal"));
add(new Button(" Spurs"));
add(new Button(" Chelsea"));
add(new Button(" West Ham"));
add(new Button(" Crystal Palace"));
}
© Ian D Chivers
email: ian.chivers@kcl.ac.uk