0% found this document useful (0 votes)
40 views6 pages

Ajp Exp 2

The document shows examples of using different layout managers in Java - BorderLayout, GridLayout, and GridLayout with spacing between buttons. BorderLayout positions components in north, south, east, west and center areas. GridLayout arranges components in a grid. GridLayout with spacing adds a gap between buttons. Each example creates a Frame, sets the layout, adds components, sets the size and makes the frame visible.

Uploaded by

Mayuri Ravan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views6 pages

Ajp Exp 2

The document shows examples of using different layout managers in Java - BorderLayout, GridLayout, and GridLayout with spacing between buttons. BorderLayout positions components in north, south, east, west and center areas. GridLayout arranges components in a grid. GridLayout with spacing adds a gap between buttons. Each example creates a Frame, sets the layout, adds components, sets the size and makes the frame visible.

Uploaded by

Mayuri Ravan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Border Layout

import java.awt.*;

class BorderLayoutex extends Frame

BorderLayoutex(){

BorderLayout b = new BorderLayout();

Button b1 = new Button("NORTH");

Button b2 = new Button("SOUTH");

Button b3 = new Button("EAST");

Button b4 = new Button("WEST");

add(b1,b.NORTH);

add(b2,b.SOUTH);

add(b3,b.EAST);

add(b4,b.WEST);

Label ll = new Label("Advanced Java Programming",Label.CENTER);

add(ll,b.CENTER);

setSize(800,800);

setVisible(true);

} public static void main(String args[]) {

BorderLayoutex l = new BorderLayoutex();

}}

Output:-
Grid Layout
import java.awt.*;

class GridLayoutex extends Frame

GridLayoutex() {

GridLayout gl = new GridLayout(3,2);

setLayout(gl);

Label l = new Label("User Name",Label.CENTER);

add(l);

TextField t = new TextField();

add(t);

Label l2 = new Label("Password",Label.CENTER);

add(l2);

TextField t2 = new TextField();

t2.setEchoChar('*');

add(t2);

Button b = new Button("Login");

add(b);

setSize(800,800);

setVisible(true);

} public static void main(String args[]) {

GridLayoutex gg = new GridLayoutex();

}}

Output:-
Grid Layout 5x5
import java.awt.*;
class GridLayout5x5 extends Frame
{
GridLayout5x5()
{
GridLayout gl = new GridLayout(5,5);
setLayout(gl);
Button b = new Button("Button 1");
add(b);
Button b2 = new Button("Button 2");
add(b2);
Button b3 = new Button("Button 3");
add(b3);
Button b4 = new Button("Button 4");
add(b4);
Button b5 = new Button("Button 5");
add(b5);
Button b6 = new Button("Button 6");
add(b6);
Button b7 = new Button("Button 7");
add(b7);
Button b8 = new Button("Button 8");
add(b8);
Button b9 = new Button("Button 9");
add(b9);
Button b10 = new Button("Button 10");
add(b10);
Button b11 = new Button("Button 11");
add(b11);
Button b12 = new Button("Button 12");
add(b12);
Button b13 = new Button("Button 13");
add(b13);
Button b14 = new Button("Button 14");
add(b14);
Button b15 = new Button("Button 15");
add(b15);
Button b16 = new Button("Button 16");
add(b16);
Button b17 = new Button("Button 17");
add(b17);
Button b18 = new Button("Button 18");
add(b18);
Button b19 = new Button("Button 19");
add(b19);
Button b20 = new Button("Button 20");
add(b20);
Button b21 = new Button("Button 21");
add(b21);
Button b22 = new Button("Button 22");
add(b22);
Button b23 = new Button("Button 23");
add(b23);
Button b24 = new Button("Button 24");
add(b24);
Button b25 = new Button("Button 25");
add(b25);

setSize(1000,800);
setVisible(true);
}
public static void main(String args[])
{
GridLayout5x5 gg = new GridLayout5x5();
}
}
Output:-
import java.awt.*;
class GridLayoutbutton extends Frame
{ GridLayoutbutton() {
GridLayout gl = new GridLayout(2,2,30,30);
setLayout(gl);
Button b1 = new Button("Button 1");
add(b1);
Button b2 = new Button("Button 2");
add(b2);
Button b3 = new Button("Button 3");
add(b3);
Button b4 = new Button("Button 4");
add(b4);
setSize(500,500);
setVisible(true);
} public static void main(String args[]) {
GridLayoutbutton gg = new GridLayoutbutton();
}}

You might also like