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

class PhiControls extends Panel implements AdjustmentListener, ActionListener{
	Antenna ant;
	
	Scrollbar slider1;
	final int ScrollMin=0;
	final int ScrollMax=361;
	public double phi;
	// CHANGE ==============================================================
        public Button bpa, bpb;
        //======================================================================
	
	public PhiControls (Antenna ant){
		super();
		this.ant = ant;
		setBackground(Color.white);
		setLayout(null);
                
                // CHANGE  =====================================================
                bpa = new Button("<");
                //bpa.setBackground(bgcolor);        
                bpb = new Button(">");
                //bpb.setBackground(bgcolor);
                //==============================================================
		
                // CHANGE ======================================================
                bpa.addActionListener(this);
                bpb.addActionListener(this);
                add(bpa); add(bpb);
                //==============================================================
		slider1=new Scrollbar(Scrollbar.HORIZONTAL,0,1,ScrollMin,ScrollMax);
		slider1.addAdjustmentListener(this);
		add(slider1);
		
		slider1.setBounds(1,1,298,15);
                slider1.setBackground(new Color(255,255,235));
                // CHANGE  =====================================================
                bpa.setBounds(1,1,14,15);
                bpb.setBounds(285,1,14,15);
                //==============================================================
		
		Panel pslider1 = new Panel();
		    pslider1.setBackground(Color.black);
		    add(pslider1);
		    pslider1.setBounds(0,0,300,17);

	    
	    
		phi=0.0;
	}
	
	public void paint(Graphics g){
	
		//g.setColor(Color.cyan);
		//g.fillRect(25,0,80,20);
		//g.setColor(Color.black);
		//g.drawString("\u03c6  = "+(int)(phi)+" \u00ba",35,15);
		//g.drawString((int)(phi)+"\u00ba",35,15);
		
	}

    	public void jrupdate(){
		Graphics g = getGraphics();
		//g.setColor(Color.cyan);
		//g.fillRect(25,0,80,20);
		//g.setColor(Color.black);
		
		//g.drawString("\u03c6  = "+(int)(phi)+" \u00ba",35,15);
		if(slider1.getValue()>360){
		    //g.drawString("360 \u00ba",35,15);
		    slider1.setValue(ScrollMax-1);
		}
		else{
		    //g.drawString((int)(phi)+" \u00ba",35,15);
		}
		g.dispose();
		
	}


	public void adjustmentValueChanged(AdjustmentEvent evt){
		if(slider1.getValue()>360){
		    phi=360.0;
		}
		else{
		    phi=(double)slider1.getValue();
		}
		jrupdate();
		ant.UpdateRadiation();
		ant.rcan1.redraw();
		ant.rcan2.redraw();
	}
        
        public void actionPerformed(ActionEvent evt){
            
                if(evt.getSource()==bpa){
                    slider1.setValue(slider1.getValue()-1);
                      
                    if(slider1.getValue()>360){
                        phi=360.0;
                    }
                    else{
                        phi=(double)slider1.getValue();
                    }
                    jrupdate();
                    ant.UpdateRadiation();
                    ant.rcan1.redraw();
                    ant.rcan2.redraw();
                    
                }
                else if(evt.getSource()==bpb){
                    slider1.setValue(slider1.getValue()+1);
                    
                    if(slider1.getValue()>360){
                        phi=360.0;
                    }
                    else{
                        phi=(double)slider1.getValue();
                    }
                    jrupdate();
                    ant.UpdateRadiation();
                    ant.rcan1.redraw();
                    ant.rcan2.redraw();
                    
                }
        }
}