Q:

Java - Card Layout using Frame Demo

0

This Program is used to Demonstrate the CardLayout.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

// 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);
}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now