/*
Title : Program for demonstrating Layouts in Java
Author: Yasar Shaikh
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class LayoutDemo extends Frame implements ActionListener
{
Button b1,b2,b3,b4,b5,b6;
Button l1,l2,l3;
CheckboxGroup cbg;
Checkbox c1,c3,c2;
Panel p1,p2,main;
LayoutDemo l;
public LayoutDemo()
{
p1=new Panel();
p2=new Panel();
main=new Panel();
l=this;
p1.setLayout(new FlowLayout());
p2.setLayout(new GridLayout());
cbg=new CheckboxGroup();
c1=new Checkbox("Left",cbg,false);
c2=new Checkbox("Center",cbg,false);
c3=new Checkbox("Right",cbg,false);
l1=new Button("Flow");
l2=new Button("Grid");
l3=new Button("Border");
b1=new Button("Button 1");
b2=new Button("Button 2");
b3=new Button("Button 3");
b4=new Button("Button 4");
b5=new Button("Button 5");
b6=new Button("Button 6");
p1.add(b1); p1.add(b2);
p1.add(b3); p1.add(b4);
p1.add(b5); p1.add(b6);
p1.add(c1);p1.add(c2);p1.add(c3);
p2.add(l1);p2.add(l2);p2.add(l3);
l1.addActionListener(this);
l2.addActionListener(this);
l3.addActionListener(this);
main.setLayout(new BorderLayout());
main.add(p1,BorderLayout.NORTH);
main.add(p2,BorderLayout.SOUTH);
add(main);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==l2)
{
l.setSize(700,700);
repaint();
p1.setLayout(new GridLayout(3,3));
}
else if(ae.getSource()==l3)
{
l.setSize(800,800);
repaint();
main.add(p1,BorderLayout.WEST);
}
else
{
l.setSize(600,600);
repaint();
p1.setLayout(new FlowLayout());
}
}
public static void main(String ar[])
{
LayoutDemo l=new LayoutDemo();
l.setSize(600,600);
l.setVisible(true);
}
}
/*
PS: Save the above program with the name LayoutDemo.java (case-sensitive)
and then compile it with "javac LayoutDemo.java" command and execute
it with "java LayoutDemo" command in command prompt/terminal.
*/
WHAT'S NEW?
Loading...
0 comments:
Post a Comment