java Practical 4

 avatar
Rohit143
java
2 years ago
1.8 kB
16
Indexable
Never
import java.awt.*;
import java.awt.event.*;



/**
 MyFrame extends Frame

 */
 class MyFrame extends Frame implements ItemListener{
     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);

         Label label =new Label("By Rohit Nandagawali");
         label.setBounds(20, 40, 200, 20);

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


         windows.addItemListener(this);
         macos.addItemListener(this);
         linux.addItemListener(this);

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

         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 void itemStateChanged(ItemEvent ie) {
         if(windows.getState())
            cl.first(mainp);
         else if(macos.getState())
            // cl.next(mainp);
            cl.show(mainp,"two");
        else 
            cl.last(mainp);
         
     }

    
}
public class practical4 {
    public static void main(String[] args) {
        new MyFrame();
    }
}