Saturday, 9 September 2017

Applet program for choice

import java.awt.event.*;
import java.awt.*;
public class choice extends Frame implements ActionListener
{
   Choice c1,c2,c3;
   Button b1,b2,b3,b4;
   TextField tx;
  choice(String s)
   {
       super(s); 
       setLayout(null);
     setSize(getToolkit().getScreenSize());
     c1=new Choice();
      c2=new Choice();
     c3=new Choice();
     tx=new TextField(15);
     b1=new Button("add");
     b2=new Button("copy");
     b3=new Button("remove");
     b4=new Button("removeall");
     tx.setBounds(10,50,130,30);
     c1.setBounds(160,50,70,30);
     c2.setBounds(230,50,70,30);
     c3.setBounds(330,50,70,30);
      b1.setBounds(100,100,50,30);
      b2.setBounds(160,100,50,30);
        b3.setBounds(220,100,50,30);
        b4.setBounds(280,100,50,30);
     c1.add("java");
     c1.add("cobol");
     c1.add("pascal");
     c1.select(1);   
     b1.addActionListener(this);
     b2.addActionListener(this);
     b3.addActionListener(this);
     b4.addActionListener(this);
/*anonymous inner class*/
     addWindowListener(new WindowAdapter()
    {
            public void windowClosing(WindowEvent e)
             {
                     setVisible(false);
                     dispose();
                      System.exit(0);
            }
               public void windowIconified(WindowEvent e)
               {
                        c1.removeAll();
                         c2.removeAll();
                         c3.removeAll();
                  }
   });
     c1.addItemListener(new ItemListener()
{
   public void itemStateChanged(ItemEvent o)
  {
     c3.add(c1.getSelectedItem());
  }
}
); 
     add(tx);
     add(c1);   
     add(c2);
     add(b1);
     add(c3);
     add(b2);
     add(b3);
     add(b4);
   }
   public void actionPerformed(ActionEvent e)
   { 
      if(e.getSource()==b1)
       c1.add(tx.getText());
       else if(e.getSource()==b2)
       {         
        String s=c1.getSelectedItem();
        c2.add(s);
       }
       else if(e.getSource()==b3)
       c1.remove(c1.getSelectedIndex());
       else if(e.getSource()==b4)
      {
            c1.removeAll();
             c2.removeAll();
            c3.removeAll();
      }   
    }
  public static void main(String args[])
     {
               choice c=new choice("choice");
                c.setVisible(true);
      }
  }




   

No comments:

Post a Comment

Featured post

Development Of JAVA Program