// Title	: Abdulla						
// Programmer	:Abdulla Al-mutawa						        
// Date Written	: 11/01/00					
// Purpose	: For this assignment, we will need to implement 
//              : a user Interface Class that allows the user to 
//              : enter a number , and to assemble a series of these 
//              : numbers together then display this assemblage on the
//              : user interface . When the user indicates completion 
//              : the Interface Class will send to an instance of the 
//              : Sort Class (the other class which we create) the input 
//              : string the user has entered. 



// Imported libraries

  import java.awt.*;
  import java.applet.Applet;
  import java.awt.event.*;
               

// Main class 
    public class Interface extends Applet implements ActionListener
      
    {  
//create a variables list 
     
          
    private Button add_button          = new Button ("Add");
    private Button done_button         = new Button ("Done");
    private Button clear_button        = new Button ("Clear");
     
    private TextField one_field        = new TextField (12);
    private TextField two_field        = new TextField (12);
    private TextField three_field      = new TextField (12);
    private TextField four_field       = new TextField (12);
  
    private Label onelabel             = new Label ("Enter any number then press Add");
    private Label twolabel             = new Label ("Press Done to sort the # which u have entered");
    private Label threelabel           = new Label ("The # which u have entered");
    private Label fourlabel            = new Label ("# sorted Ascending");
    private Label fivelabel            = new Label ("# sorted Descending");
    private Label countlabel           = new Label ("U have been entered "); 
    
    private Panel a_panel              = new Panel ();
    private Panel b_panel              = new Panel ();
    private Panel c_panel              = new Panel ();
    
    String one    = " ";
    String two    = " ";
    String three  = " ";
    
    int value ;
    int number; 

    Sort mySort   = new Sort();

// init
    public void init()        
     
       {
//add list 
        
        setLayout(new BorderLayout());
        add("South",a_panel);
        a_panel.add(add_button);
        add_button.addActionListener(this);
        a_panel.add(done_button);
        done_button.addActionListener(this);
        a_panel.add(clear_button);
        clear_button.addActionListener(this);
       
        b_panel.setLayout(new GridLayout(9,1));
        add("North",b_panel);
        b_panel.add(onelabel);
        b_panel.add(twolabel);
        b_panel.add(one_field);
        one_field.addActionListener(this);
        b_panel.add(threelabel);
        b_panel.add(two_field );
        two_field.addActionListener(this);
        two_field.setBackground (Color.gray);
        b_panel.add(fourlabel);
        b_panel.add(three_field);
        three_field.addActionListener(this);
        three_field.setBackground (Color.gray);
        b_panel.add(fivelabel);
        b_panel.add(four_field);
        four_field.addActionListener(this);
        four_field.setBackground (Color.gray);
        
        add("West",c_panel);
        c_panel.add(countlabel);
        
       


}//end init

// actionPerformed
    public void actionPerformed(ActionEvent event) 
  
    {
   
      if   (event.getSource() == add_button) //when u press on add
           
         {
            number = Integer.parseInt(one_field.getText());
            one = one + number + ",";
            two_field.setText(one);
            mySort.getNumber(number);
            value++;
            one_field.setText("");
         } 
   
                 
      if     (event.getSource() == done_button)// when u press on done
       
         {                  
             mySort.sorted(); 
             two=mySort.getascending();
             three_field.setText(two);
             three= mySort.getdescending();
             four_field.setText(three);
                
         } 

                
    if      (event.getSource() == clear_button) //clear the screen  
               
         {
             one_field.setText(" ");
             two_field.setText(" ");
             three_field.setText(" ");
             four_field.setText(" ");
          
             one     =(" ");
             two     =(" ");
             three   =(" ");
             
             value=0;
             mySort.clear();
          }

            countlabel.setText("U have been entered "+value);//show the # Qun
            repaint();
}  //end actionPerformed
     
}//end class Interface
