Seach

check box and button demo


package bxxc;
import java.awt.*;
import java.awt.Event.*;
import java.awt.event.*;
public class Bxxc extends Frame implements ItemListener,ActionListener
{

    Checkbox c1,c2;
    Button b1;
public  Bxxc()
{
    Frame f=new Frame("demo");
    f.setSize(100, 100);
    c1=new Checkbox();
    c1.setLabel("disable");
    c1.setLocation(20, 20);
    c2=new Checkbox("enable");
    c2.setLocation(20, 40);
    b1=new Button("show");
    b1.setLocation(20, 60);
    b1.addActionListener(this);
    Panel p=new Panel();
    p.add(b1);
    p.add(c1);
    p.add(c2);
    c1.addItemListener(this);
    f.add(p);
    c2.addItemListener(this);
    p.setSize(100, 100);
    f.setVisible(true);
    p.setVisible(true);
   
    f.addWindowListener(new WindowAdapter() {

          //  @Override
            public void windowClosing(WindowEvent e) {
               
                System.exit(0);
                //super.windowClosing(e);
            }
   
    });
}

     public void itemStateChanged(ItemEvent e) {
 
      // Object o[]=new Object[20];
       //o[0]=e.getItem();
//String s=o[0].toString();
       if(e.getSource()==c1)
       {
           b1.setVisible(false);
       }
       else if(e.getSource()==c2)
       {
           b1.setVisible(true);
       }
       
    }
  
    public void actionPerformed(ActionEvent e) {
      
    Frame fx=new  Frame("redirected form");
    fx.setSize(200, 200);
    fx.addWindowListener(new WindowAdapter() {

            //@Override
            public void windowClosing(WindowEvent e) {
             
                System.exit(0);// super.windowClosing(e);
            }
           
   
           
    });
    //System.out.println("clicked");
    fx.setVisible(true);
  
    }
   

    public static void main(String[] args)
    {
        Bxxc d= new Bxxc();
    }
}

No comments: