Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Enrollment Number: FCOW21706

Input:
FlowLayout
package demo;
import java.awt.*;
public class Layout {
public static void main(String args[]) throws Exception {
Frame f = new Frame();
FlowLayout fl = new FlowLayout(FlowLayout.CENTER);
Button b1 = new Button("Happy");
Button b2 = new Button("Sad");
Button b3 = new Button("Lonely");
Button b4 = new Button("Cheerful");
Button b5 = new Button("JOY");
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.setLayout(fl);

f.setSize(300, 300);
f.setVisible(true);
}}
Output:
Border Layout:

package demo;
import java.awt.*;
public class Layout
{
public static void main(String[] args) throws Exception
{
Frame f = new Frame();
Button b1 = new Button("NORTH");
Button b2 = new Button("SOUTH");
Label l3 = new Label("EAST");
Label l4 = new Label("WEST");
Button t5 = new Button("CENTER");
f.add(b1, BorderLayout.NORTH);
f.add(b2, BorderLayout.SOUTH);
f.add(l3, BorderLayout.EAST);
f.add(l4, BorderLayout.WEST);

f.add(t5, BorderLayout.CENTER);
f.setSize(300, 300);
f.setVisible(true);
}}
Output:
GridLayout:

package demo;
import java.awt.*;
public class Layout
{
public static void main(String[] args) throws Exception {
Frame f = new Frame();
GridLayout gl = new GridLayout(3, 3);
Button b1 = new Button("One");
Button b2 = new Button("Two");
Button b3 = new Button("Three");
Button b4 = new Button("Four");
Button b5 = new Button("Five");
Button b6 = new Button("Six");
Button b7 = new Button("Seven");
Button b8 = new Button("Eight");
Button b9 = new Button("Nine");
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.add(b6);
f.add(b7);
f.add(b8);
f.add(b9);

f.setLayout(gl);
f.setSize(300, 300);
f.setVisible(true);
}
}
Output:
Card Layout:
package demo;
import java.awt.*;
import java.awt.event.*;
class CardLayoutExample extends Frame
{
CardLayout card = new CardLayout(90, 20);
CardLayoutExample()
{
setLayout(card);
setVisible(true);
setSize(200,200);
Button b1 = new Button("first ");
Button b2 = new Button("Second");
Button b3 = new Button("Third");
add(b1);
add(b2);
add(b3);
}
public static void main(String args[])
{
CardLayoutExample ce=new CardLayoutExample();
}

}
Output:
p

You might also like