source file name: CardLayoutDemo.java
import java.awt.*;
import java.awt.event.*;
public class CardLayoutDemo extends Frame implements ActionListener
{
CardLayout card;
Button b1,b2,b3;
Panel p;
public CardLayoutDemo()
{
p=new Panel();
card=new CardLayout(40,30);
p.setLayout(card);
b1=new Button("One");
b2=new Button("Two");
b3=new Button("Three");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
p.add("a",b1);p.add("b",b2);p.add("c",b3);
add(p);
}
public void actionPerformed(ActionEvent e)
{
card.next(p);
}
public static void main(String[] args)
{
CardLayoutDemo f=new CardLayoutDemo();
f.setTitle("Card Layout Demo");
f.setSize(400,400);
f.setVisible(true);
}
}
output:
click below button
0 Comments
Post a Comment