package swing1; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class card1 { JFrame f; JButton b1,b2; JPanel p,p1,p2,p3; JLabel l1,l2,l3; card1() { f=new JFrame("testing card layout"); f.setSize(400,400); f.setLayout(null); f.setBackground(Color.red); b1=new JButton("prev"); b1.setBounds(90,30,70,30); b2=new JButton("next"); b2.setBounds(170,30,70,30); l1=new JLabel("I m on CARD 1"); l2=new JLabel("I m on CARD 2"); l3=new JLabel("I m on CARD 3"); p=new JPanel(new CardLayout()); p.setBackground(Color.red); p1=new JPanel(new FlowLayout()); p2=new JPanel(new FlowLayout()); p3=new JPanel(new FlowLayout()); //p=(panel).add(f.getContentPane()); f.add(p); p.add(l1,""); f.add(b1); f.add(b2); p.add(p1,"1"); p.add(p2,"2"); p.add(p3,"3"); f.setVisible(true); process pp=new process(); b1.addActionListener(pp); b2.addActionListener(pp); } class process implements ActionListener { public void actionPerformed(ActionEvent e) { if(e.getSource()==b2) { new CardLayout().show(p1, null); } else { new CardLayout().show(p2, null); } } } public static void main(String args[]) { card1 cd=new card1(); } }