0% found this document useful (0 votes)
3 views4 pages

Java Practic Le 4

The document is a Java program that demonstrates the use of CardLayout in a Swing application. It creates a JFrame with two buttons that allow users to switch between different levels of content. The program sets up the layout and handles button actions to navigate through the cards.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Java Practic Le 4

The document is a Java program that demonstrates the use of CardLayout in a Swing application. It creates a JFrame with two buttons that allow users to switch between different levels of content. The program sets up the layout and handles button actions to navigate through the cards.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Import java.awt.

*;

Import java.awt.event.*;

Import javax.swing.JFrame;

Import javax.swing.*;

Public class CardLayoutDemo extends JFrame implements ActionListener {

CardLayout card;

JButton b1, b2, b3;

Container c;

CardLayoutDemo()

C = getContentPane();

Card = new CardLayout(40, 30);

c.setLayout(card);

b1 = new JButton(“First Level”);

b2 = new JButton(“Second Level”);

b1.addActionListener(this);

b2.addActionListener(this);

c.add(“a”, b1);

c.add(“b”, b2);

}
Public void actionPerformed(ActionEvent e)

Card.next(c);

Public static void main(String[] args)

CardLayoutDemo cl = new CardLayoutDemo();

cl.setSize(400, 400);

cl.setVisible(true);

cl.setDefaultCloseOperation(EXIT_ON_CLOSE);

********************************OUTPUT **********************************
****************************OUTPUT**************************

You might also like