Java

Java - Card Layout using Frame Demo.

Java - Card Layout using Frame Demo.
// Card Layout

import java.awt.*;
import java.awt.event.*;

public class card extends Frame
{
Button b1,b2,b3,b4;
Panel p1;
CardLayout cl;

card()
{
p1 = new Panel();
add(p1);

cl = new CardLayout();
p1.setLayout(cl);

b1 = new Button("one");
b1.addActionListener(new s());
p1.add(b1,"one");

b2 = new Button("two");
b2.addActionListener(new s());
p1.add(b2,"two");

b3 = new Button("three");
b3.addActionListener(new s());
p1.add(b3,"three");

b4 = new Button("four");
b4.addActionListener(new s());
p1.add(b4,"four");

addWindowListener(new w()); 
}

class w extends WindowAdapter
{ 
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
}

class s implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
cl.next(p1);
}
}

public static void main(String arg[])
{
card ff = new card();
ff.setVisible(true);
ff.setSize(300,300);
}
}

Senthilvelan Sambamoorthy

Senthilvelan Sambamoorthy is working as a Professor in Department of Master of Computer Applications, Paavai Engineering College, Namakkal, Tamilnadu, India, He is Masters in Computers Applications. Having 18+ years of experience and his area of interest is Java, JSP, Servlet, J2EE, C#, PHP, Python ASP.NET, SQL Server and etc.