CardLayout Demo

This example shows the CardLayout manager. Pressing any one of three button available will show a different "card". Ex.If red Button is clicked,the panel with re background is Shown. Panels in card layout are switched using show() method.

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


public class CardLayoutDemo extends Frame implements ActionListener
{


Panel cardPanel;
Panel p1,p2,p3;
Panel buttonP;

Button b1,b2,b3;
CardLayout cLAyout;

Display a Label Contaning Both an Icon and A String

The following example illustrates how to create and display a label containing both an
icon and a string. The applet begins by getting its content pane. Next, an ImageIcon
object is created for the file france.gif. This is used as the second argument to the
JLabel constructor. The first and last arguments for the JLabel constructor are the label
text and the alignment. Finally, the label is added to the content pane.

import java.awt.*;
import javax.swing.*;
/* */
public class SwingProgram extends JApplet{
public void init()
{
//get content pane
Container cp= getContentPane();
// Create an Icon