/**
* @(#)TestCardLayout.java
*
* TestCardLayout application
*
* @author
* @version 1.00 2007/1/21
*/
import java.awt.*;
import java.awt.event.*;
public class TestCardLayout extends Frame
{
CardLayout cl=new CardLayout();
Panel plCenter=new Panel(cl);
public TestCardLayout()
{
GridLayout gl=new GridLayout(5,1);
Panel plWest=new Panel(gl);
Button first=new Button("first");
Button prev=new Button("prev");
Button next=new Button("next");
Button three=new Button("three");
Button last=new Button("last");
plWest.add(first);
plWest.add(prev);
plWest.add(next);
plWest.add(three);
plWest.add(last);
plCenter.add(new Button("one"),"1");
plCenter.add(new Button("two"),"2");
plCenter.add(new Button("three"),"3");
plCenter.add(new Button("four"),"4");
plCenter.add(new Button("five"),"5");
add(plWest,"West");
add(plCenter);
class MyactionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("first"))
{
cl.first(plCenter);
}
else if(e.getActionCommand().equals("prev"))
{
cl.previous(plCenter);
}
else if(e.getActionCommand().equals("next"))
{
cl.next(plCenter);
}
else if(e.getActionCommand().equals("three"))
{
cl.show(plCenter,"3");
}
else
{
cl.last(plCenter);
}
}
}
MyactionListener ml=new MyactionListener();
first.addActionListener(ml);
prev.addActionListener(ml);
next.addActionListener(ml);
three.addActionListener(ml);
last.addActionListener(ml);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
e.getWindow().dispose();
}
});
}
public static void main(String[] args)
{
// TODO, add your application code
System.out.println("Hello World!");
TestCardLayout mainFrame=new TestCardLayout();
mainFrame.setTitle("TestCardLayout");
mainFrame.setBounds(300,200,400,400);
mainFrame.setVisible(true);
}
}