CardLayout program

mail@pastecode.io avatar
unknown
java
2 years ago
1.4 kB
6
Indexable
Never
import java.awt.*;
import java.awt.event.*;



/**
 MyFrame extends Frame

 */
 class MyFrame extends Frame{
     Panel cb,p1,p2,p3,mainp;
     Checkbox windows,macos,linux;
     CheckboxGroup cbg;
     CardLayout cl; 
     MyFrame(){
         cbg = new CheckboxGroup();
         windows = new Checkbox("Windows ",true,cbg);
         macos = new Checkbox("macos ",false,cbg);
         linux = new Checkbox("linux ",false,cbg);

         cb = new Panel();
         cb.add(windows);
         cb.add(macos);
         cb.add(linux);

         windows.addItemListener((ItemEvent ie)->{cl.first(mainp);});
         macos.addItemListener((ItemEvent ie)->{cl.show(mainp,"two");});
         linux.addItemListener((ItemEvent ie)->{cl.last(mainp);});

         p1 = new Panel();
         p1.setBackground(Color.GREEN);

         p2= new Panel();
         p2.setBackground(Color.RED);

         p3= new Panel();
         p3.setBackground(Color.blue);

         mainp = new Panel();
         cl = new CardLayout();
         mainp.setLayout(cl);

         mainp.add("one",p1);
         mainp.add("two",p2);
         mainp.add("three",p3);

         add(cb,BorderLayout.NORTH);
         add(mainp,BorderLayout.CENTER);


        setVisible(true);
        setSize(500, 500);
     }
 
    
}
public class practical4 {
    public static void main(String[] args) {
        new MyFrame();
    }
}