//Vector.java

//import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.geom.*;
import java.util.*;
import java.text.*;

class PaintPanel extends JPanel{
    PaintPanel(){
        dipole = 0.01;
        setOpaque(true);
    //    double dipole;
    //    dipole = my_antenna;
    //    setBorder(BorderFactory.createLineBorder(Color.RED,5));
    }  
      
    private double dipole;
    public void setdipole(double dipole){
        this.dipole = dipole;
    }
    
    @Override
        protected void paintComponent(Graphics g){
            //double dipole;
            //dipole = my_antenna;
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            double xstart, xend, ystart, yend, ystart2, yend2;
            xstart = (double)getSize().width/2.0-50;
            xend = (double)getSize().width/2.0-50;
            ystart = (double)getSize().height/2.0-3.0;
            yend = ystart - (double)getSize().height/3.0 * dipole/10.0;
            ystart2 = (double)getSize().height/2.0+3.0;
            yend2 = ystart2 + (double)getSize().height/3.0 * dipole/10.0;
            
            // z-axis
            //drawLineThick(g,xstart,ystart,xstart,15,1, Color.red);
            drawLineThick(g,xstart,20,xstart,10,1, Color.red);
            drawDashLineThick(g, xstart, ystart, xstart, 20, 1, 5, Color.red);
            //MaestroG.drawArrow((int)xstart, 15, 5, g);
            drawLineThick(g,xstart,10,xstart+2,17,1, Color.red);
            drawLineThick(g,xstart,10,xstart-2,17,1, Color.red);
            
            g.setColor(Color.black);
            MaestroG.subscripter("z","","",g, 11, (int)xstart+10, 17);
            
            // dipole
            if(dipole <=2.0){
                drawLineThick(g,xstart,ystart,xend,yend,3, Color.black);
                drawLineThick(g,xstart,ystart2,xend,yend2,3, Color.black);
            }
            else{
                drawLineThick(g,xstart,ystart,xend,yend,3, Color.black);
                drawLineThick(g,xstart,ystart2,xend,yend2,3, Color.black);
            }
            
            // transmission line
            drawLineThick(g,25,ystart+1,xstart,ystart+1,1, Color.gray);
            drawLineThick(g,25,ystart2-1,xstart,ystart2-1,1, Color.gray);
            
            // measuring arrows for dipole length
            
            // horizontal lines
            drawLineThick(g,xstart+52,yend,xstart+68,yend,1, Color.gray);
            drawLineThick(g,xstart+52,yend2,xstart+68,yend2,1, Color.gray);
            
            //vertical line
            g.setColor(Color.gray);
            if(dipole <=2.0){
                //drawLineThick(g,xstart+60,yend-20,xstart+60,yend2+20,1, Color.gray);
                g.drawLine((int)xstart+60,(int)yend-20,(int)xstart+60,(int)yend2+20);
                MaestroG.drawArrow((int)xstart+60, (int)yend-9, 6, g);
                MaestroG.drawArrow((int)xstart+60, (int)yend2+9, 5, g);
            }
            else{
                //drawLineThick(g,xstart+60,yend,xstart+60,yend2,1, Color.gray);
                g.drawLine((int)xstart+60,(int)yend,(int)xstart+60,(int)yend2);
                MaestroG.drawArrow((int)xstart+60, (int)yend2-9, 6, g);
                MaestroG.drawArrow((int)xstart+60, (int)yend+9, 5, g);
            }
            
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            g.setColor(Color.black);
            MaestroG.subscripterSansItalic("l",""," = "+MaestroA.rounder(dipole,2)+(" \u03bb"),g,20,(int)xstart+75,(int)ystart2+5);
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        }
        public void changeBorderSize(int size){
            setBorder(BorderFactory.createLineBorder(Color.RED,size));
        }
        
        public void drawLineThick(Graphics g, double x1, double y1, double x2, double y2, int thick, Color color){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setPaint(color);
            g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));

            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

            Line2D.Double line = new Line2D.Double(x1,y1,x2,y2);
            g2d.draw(line);

            g2d.setStroke(new BasicStroke(1));
            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        }
        
        private void drawDashLineThick(Graphics g, double x1, double y1, double x2, double y2, int thick, int dash, Color color){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setPaint(color);
            g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
            float[] dashPattern = {dash,dash};
            g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER,10.0F,dashPattern,0));  
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

            Line2D.Double line = new Line2D.Double(x1,y1,x2,y2);
            g2d.draw(line);

            g2d.setStroke(new BasicStroke(1));g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));

            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        }
}



class PaintPanel2 extends JPanel{
    PaintPanel2(){
        setOpaque(true);
    //    setBorder(BorderFactory.createLineBorder(Color.RED,5));
    }  
      
    private double myfrequency;
    public void setmyfrequency(double myfrequency){
        this.myfrequency = myfrequency;
    }
    
    @Override
        protected void paintComponent(Graphics g){
            
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            g.setColor(Color.black);
            //g.setFont(state.ttfFont.deriveFont(Font.BOLD,16f));
            g.setFont(new Font("SanSerif",Font.BOLD,18));

            g.drawString("Instructions", 15,30);

            int xcolumn1 = 25; int xcolumn2 = 25; int xcolumn3 = 25;
            int ystart; int y;
            int ytext; int deltaY = 25;
            String s; int nextX;
            ystart = 70;
            ytext = ystart;
            // ASSUMPTIONS
            g.setColor(Color.red);
            //g.setFont(state.ttfFont.deriveFont(Font.BOLD,15f));
            g.setFont(new Font("SanSerif",Font.BOLD,17));
            g.drawString("Assumption", xcolumn1,ytext);
            g.setColor(Color.black);
            //g.setFont(state.ttfFont.deriveFont(14f));
            g.setFont(new Font("SanSerif",Font.PLAIN,16));

            ytext += deltaY;
            s = "\u2022 Far Field approximation";
            nextX = STR.displayString(s,g,xcolumn1,ytext);
            
            ytext += 2*deltaY;
            // INPUT
            g.setColor(Color.red);
            //g.setFont(state.ttfFont.deriveFont(Font.BOLD,15f));
            g.setFont(new Font("SanSerif",Font.BOLD,17));

            g.drawString("Input", xcolumn2,ytext);
            g.setColor(Color.black);
            //g.setFont(state.ttfFont.deriveFont(14f));
            g.setFont(new Font("SanSerif",Font.PLAIN,16));

            ytext += deltaY;
            //INPUT
            s = "\u2022 Dipole length in units of wavelength";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "\u2022 Selection of Field or Power radiation pattern";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            
            ytext += 2*deltaY;

            // OUTPUT
            g.setColor(Color.red);
            //g.setFont(state.ttfFont.deriveFont(Font.BOLD,15f));
            g.setFont(new Font("SanSerif",Font.BOLD,17));
            g.drawString("Displayed Information", xcolumn3,ytext);
            g.setColor(Color.black);
            //g.setFont(state.ttfFont.deriveFont(14f));
            g.setFont(new Font("SanSerif",Font.PLAIN,16));
            ytext += deltaY;
            s = "\u2022 3D wireframe representation of the radiation pattern in cartesian coordinates";
            nextX = STR.displayString(s,g,xcolumn3,ytext);
            
            g.setColor(Color.blue.darker());
            ytext += 2*deltaY;
            s = "The 3D wireframe representation of the dipole radiation "+
                "pattern can be animated to illustrate";  //8/4/14
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "pattern variation with respect to dipole length ranging from "+
                "0.01 \u03bb to 10 \u03bb. The orientation ";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "of the diagram can be modified by clicking and dragging "+
                "inside the picture.";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            //ytext += deltaY;
            //s = "";
            //nextX = STR.displayString(s,g,xcolumn2,ytext);
                       
            drawCopyRight(g);
            
            
        }
        
    
    public void drawCopyRight(Graphics g) {
            int deltaY = 20;
            int startingY = getSize().height - 70;
            int startingX = 0;
            FontMetrics fm;
            g.setColor(Color.black);
            g.setColor(Color.black);
            //g.setFont(normalfont14);
            //g.setFont(state.ttfFont.deriveFont(14f));
            g.setFont(new Font("SanSerif",Font.PLAIN,14));
            fm = g.getFontMetrics();
            g.drawString("Applet Design: Umberto Ravaioli",
                         startingX+10,startingY+deltaY);

            //MaestroG.superscripter("Interactive Java","TM"," platform:  www.amanogawa.com",
            //                       g,14,startingX,startingY+2*deltaY);
            ////String s = "Interactive Java"+STR.SUP+"TM"+STR.ENDSUP+" platform:  www.amanogawa.com";
            ////int nextX = STR.displayString(s,g,startingX+10,startingY+2*deltaY);
            ////int lineLength = fm.stringWidth("Interactive JavaTM platform:  www.amanogawa.com");
            ////lineLength+= 10;

            //g.setFont(state.ttfFont.deriveFont(14f));
            ////g.drawString("All Rights Reserved",startingX+10,startingY+3*deltaY);
            ////g.drawLine(startingX,startingY+5,
            ////           startingX+lineLength+10,startingY+5);
            ////g.drawLine(startingX+lineLength+10,startingY+5,
            ////           startingX+lineLength+10,startingY+4*deltaY);
        }    
    
    private double dipole;
    public void setdipole(double dipole){
        this.dipole = dipole;
    }
        
        public void changeBorderSize(int size){
            setBorder(BorderFactory.createLineBorder(Color.RED,size));
        }
        
        public void drawLineThick(Graphics g, double x1, double y1, double x2, double y2, int thick, Color color){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setPaint(color);
            g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));

            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

            Line2D.Double line = new Line2D.Double(x1,y1,x2,y2);
            g2d.draw(line);

            g2d.setStroke(new BasicStroke(1));
            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        }
        
        private void drawDashLineThick(Graphics g, double x1, double y1, double x2, double y2, int thick, int dash, Color color){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setPaint(color);
            g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
            float[] dashPattern = {dash,dash};
            g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER,10.0F,dashPattern,0));  
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

            Line2D.Double line = new Line2D.Double(x1,y1,x2,y2);
            g2d.draw(line);

            g2d.setStroke(new BasicStroke(1));g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));

            //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        }
}

public class Vector extends JFrame implements WindowListener{  
  
  // Draws the radiation pattern
  VectorCanvas vc;
  PaintPanel pp;
  PaintPanel2 pp2;
  
  public int anno_mio;

  // Slider for dipole length
  public JSlider jslider_dipole;
  public JSlider jslider_animation;
  
  public JLabel jlab_dipole;
  public JLabel jlambda;
  public JLabel jlambda2;
  public JLabel jcopyright;
  public JLabel janimation;
  public JLabel jtitle1;
  public JLabel jtitle2;
  public JLabel jtitle3;
  
  public JButton jstart;
  public JButton jstop;
  public JButton jback;
  public JButton jforth;
  public JButton jabout;
  public JButton jclose;
  public JButton jColorF;
  public JButton jColorP;
  
  public JRadioButton[] Field = new JRadioButton[2];
  public ButtonGroup field_power = new ButtonGroup();
  
  public JRadioButton[] Fill = new JRadioButton[1];
  
  public double direction = 1.0;
  
  public boolean running = false;
  public boolean goforth = true;
  
  public JPanel jtitle = new JPanel();
  public JPanel jcontrols = new JPanel();
  public JPanel jline1 = new JPanel();
  public JPanel jline2 = new JPanel();
  
  public JPanel jtitlep1 = new JPanel();
  public JPanel jtitlep2 = new JPanel();
  public JPanel jtitlep3 = new JPanel();
  public JPanel jtitlep4 = new JPanel();
  public JPanel jtitlep5 = new JPanel();
  public JPanel jtitlep6 = new JPanel();
  public JPanel jtitlep7 = new JPanel();
  public JPanel jtitlep8 = new JPanel();
  
  public JPanel jInst2 = new JPanel();
  public JPanel jInst3 = new JPanel();
  public JPanel jInst4 = new JPanel();
  public JPanel jInst5 = new JPanel();
  public JPanel jInst6 = new JPanel();
  
  public JPanel jback1 = new JPanel();
  public JPanel jback2 = new JPanel();
  public JPanel jback3 = new JPanel();
  
  public JPanel jaboutpanel = new JPanel();
  
  public JPanel jcontrols2 = new JPanel();
  public int sleep_factor = 200;
  public int Nside;
  public Panel p_one;
 
  Thread vai;
  public boolean forward = true;
  
  //--------------------------------------------
  public boolean LicenseExpired;
    
  public int this_month, today_week, this_year, this_hour, this_minute, today_month, 
	       today_year,this_zone, saving_time;
	
  public int annonuovo = 2006;
  public int anno = 2006;
        
  public double my_antenna = 0.01; // wavelengths
  GregorianCalendar Greg = new GregorianCalendar();
  
  //--------------------------------------------
  
  public static void main(String[] args){
        int xmove = 20;
        int ymove = 41;
        Vector f = new Vector();
        f.setSize(826+xmove,543+ymove);
        f.setVisible(true);
        //f.setLayout(new FlowLayout());
        f.setLayout(null);
  }   

  
  public Vector() {
      
      this_month = Greg.get(Calendar.MONTH);
	//System.out.println("  This is the month = "+this_month);
	today_week = Greg.get(Calendar.DAY_OF_WEEK);
	//System.out.println("  This is the day_week = "+today_week);
	this_year = Greg.get(Calendar.YEAR);
	this_hour = Greg.get(Calendar.HOUR_OF_DAY);
	//System.out.println("  This is the year = "+this_year);
	this_minute = Greg.get(Calendar.MINUTE);
	//System.out.println("  This is the minute = "+this_minute);
	today_month = Greg.get(Calendar.DAY_OF_MONTH);
	//System.out.println("  This is the day_month = "+today_month);
	today_year = Greg.get(Calendar.DAY_OF_YEAR);
	//System.out.println("  This is the day_year = "+today_year);
	this_zone = Greg.get(Calendar.ZONE_OFFSET);
	//System.out.println("  This is the zone_offset = "+this_zone/3600000);
	saving_time = Greg.get(Calendar.DST_OFFSET);
	//System.out.println("  This is the dst_offset = "+saving_time/3600000);
        
        if(anno > this_year){
                annonuovo = anno;
        }
        else{
                annonuovo = this_year;
        }
      
      try{
          SwingUtilities.invokeAndWait(new Runnable(){
              public void run(){
                 guiInit(); //initialize GUI 
              }
          });
      }
      catch(Exception exc){}    
        
        Runnable Ant_Thread = new Runnable(){
            public void run(){
                try{
                    for(; ;){
                        Thread.sleep(sleep_factor);
                        SwingUtilities.invokeLater(new Runnable(){
                            public void run(){
                                updateTime();
                            }
                        });
                    }
                }
                catch(InterruptedException exc){}
            }
        };
        
        vai = new Thread(Ant_Thread);
        vai.start();

        // Listeners
        this.addWindowListener(this);
               
  }
  
  void updateTime(){
           
           if(!running)return;
           
           if(vc.dipolelength >= 1.0){
               if(forward){
                   vc.dipolelength = vc.dipolelength + 0.01;
                   jforth.setVisible(false);
                   jback.setVisible(true);
               }
               else{
                   vc.dipolelength = vc.dipolelength - 0.01;
                   jforth.setVisible(true);
                   jback.setVisible(false);
               }
           }
           else{
               if(forward){
                   vc.dipolelength = vc.dipolelength + 0.005;
                   jforth.setVisible(false);
                   jback.setVisible(true);
               }
               else{
                   vc.dipolelength = vc.dipolelength - 0.005;
                   jforth.setVisible(true);
                   jback.setVisible(false);
               }
           }    
           
           if(vc.dipolelength >= 10.0){
                forward = false;
                vc.dipolelength = 10.0;
           }
           else if(vc.dipolelength <= 0.01){
                forward = true;
                vc.dipolelength = 0.01;
           }
           jslider_dipole.setValue((int)(vc.dipolelength*100));
           vc.repaint();
           
           my_antenna = vc.dipolelength;
           pp.setdipole(my_antenna);
           pp.repaint();
           
  }
  
  public void windowClosing(WindowEvent e) {
        dispose();
        System.exit(0);
    }
    
    public void windowOpened(WindowEvent evt){}
    
    public void windowIconified(WindowEvent evt){}
    
    public void windowClosed(WindowEvent evt){}
    
    public void windowDeiconified(WindowEvent evt){}
    
    public void windowActivated(WindowEvent evt){}
    
    public void windowDeactivated(WindowEvent evt){}
    
  
  private void guiInit(){
    setLayout(null);
    vc = new VectorCanvas(); 
    add(vc);
    
    //jColorF = new JButton("Graph Color - F");
    jColorF = new JButton("Frame Color");
    jColorF.setBounds(170,402,130,20);
    //add(jColorF);
    //jColorF.setVisible(true);
    jColorF.setVisible(false);
    
    jColorP = new JButton("Graph Color - P");
    jColorP.setBounds(170,402,130,20);
    //add(jColorP);
    jColorP.setVisible(false);
    
    
    Fill[0] = new JRadioButton("Apply Tint",true);
    //Fill[0].setBounds(170,422,130,20);   8/3/14
    Fill[0].setBounds(165,422,140,20);
    //add(Fill[0]);
    //Fill[0].setVisible(true);
    Fill[0].setVisible(false);
        
    Dimension dim = getSize();
    pp = new PaintPanel();
    pp.setBounds(10,55,303,225);
    pp.setBackground(Color.white);
    add(pp);
    
    //jclose = new JButton("Close");    8/8/14
    jclose = new JButton(" Close ");
    //jclose.setBounds(550,480,70,25);  8/8/14
    jclose.setBounds(545,480,80,25);
    add(jclose);
    jclose.setVisible(false);
    
    pp2 = new PaintPanel2();
    pp2.setBounds(10,55,806,480);
    pp2.setBackground(new Color(255,255,245));
    //pp2.setBorder(BorderFactory.createLineBorder(Color.gray,1));
    add(pp2);
    pp2.setVisible(false);
    
    Nside = 520;
    //Nside = Math.min(dim.width,dim.height);
    //if(Nside < 20){Nside = 20;}
    //System.out.println("Nside"+Nside);
    
    Field[0] = new JRadioButton("|Field|", true);
    Field[0].setContentAreaFilled(false);
    //Field[0].addItemListener(this);
    field_power.add(Field[0]);
    add(Field[0]);
    
    Field[1] = new JRadioButton("Power", false);
    Field[1].setContentAreaFilled(false);
    //Field[1].addItemListener(this);
    field_power.add(Field[1]);
    add(Field[1]);
    
    //Field[0].setBounds(20,400,70,25);    8/3/14
    //Field[1].setBounds(90,400,70,25);
    Field[0].setBounds(15,400,80,25);
    Field[1].setBounds(95,400,80,25);
    
    //vc.setBounds(10,10,Nside-20,Nside-20);
    vc.setBounds(320,11,Nside-20,Nside+4);
    
            p_one = new Panel();
	    p_one.setBackground(Color.black);
	    add(p_one);
	    p_one.setBounds(319,10,Nside-18,Nside+6);
            
    
    jtitle1 = new JLabel("Module 9.2B");
    jtitle1.setFont(new Font("Helvetica",Font.BOLD,14));
    jtitle1.setBounds(25,20,100,15);
    jtitle1.setForeground(Color.black);
    add(jtitle1);
    
    jtitle2 = new JLabel("3D Radiation Pattern");
    jtitle2.setFont(new Font("Helvetica",Font.BOLD,13));
    //jtitle2.setBounds(160,15,250,15);  8/8/14
    jtitle2.setBounds(140,15,250,15);
    jtitle2.setForeground(Color.red.darker());
    add(jtitle2);
    
    jtitle3 = new JLabel("of Linear Antenna");
    jtitle3.setFont(new Font("Helvetica",Font.BOLD,13));
    //jtitle3.setBounds(160,30,250,15);  8/8/14
    jtitle3.setBounds(140,30,250,15);
    jtitle3.setForeground(Color.red.darker());
    add(jtitle3);
    
    jslider_dipole = new JSlider(0,1000,0);
    //jslider_dipole.setBounds(200,Nside-2,280,58);
    jslider_dipole.setBounds(29,330,265,58);
    add(jslider_dipole);
    
    jslider_dipole.setMajorTickSpacing(500);
    jslider_dipole.setMinorTickSpacing(100);
    jslider_dipole.setPaintTicks(true);
    
    jslider_animation = new JSlider(0,500,300);
    jslider_animation.setBounds(19,480,285,53);
    //jslider_animation.setBounds(190,Nside+60,300,58);
    add(jslider_animation);
    
    jslider_animation.setMajorTickSpacing(500);
    jslider_animation.setMinorTickSpacing(50);
    jslider_animation.setPaintTicks(true);
    
    //jabout = new JButton("Instructions");  8/8/14
    jabout = new JButton(" Instructions ");
    //jabout.setPreferredSize(new Dimension(70,25));
    //jabout.setBounds(195,293,110,25);  // 8/3/14
    //jabout.setBounds(195,283,110,25);  8/8/14
    jabout.setBounds(190,283,120,25);
    add(jabout);
    
    
    jstart = new JButton("Start");
    //jstart.setPreferredSize(new Dimension(70,25));
    //jstart.setBounds(18,Nside+85,70,25);
    jstart.setBounds(120,450,70,25);
    add(jstart);
    
    jstop = new JButton("Stop");
    //jstop.setPreferredSize(new Dimension(70,25));
    //jstop.setBounds(100,Nside+85,70,25);
    jstop.setBounds(210,450,70,25);
    add(jstop);
    
    jback = new JButton(">");
    //jback.setPreferredSize(new Dimension(50,25));
    jback.setBounds(40,450,50,25);
    //jback.setEnabled(true);
    jback.setVisible(true);
    add(jback);
    
    jforth = new JButton("<");
    jforth.setPreferredSize(new Dimension(50,25));
    jforth.setBounds(40,450,50,25);
    //jforth.setEnabled(false);
    jforth.setVisible(false);
    add(jforth);
    
    //--------------------------------------------------------------------------
    // thin panel to make horizontal lines
    jline1.setBounds(20,280,285,1);
    jline1.setOpaque(true);
    jline1.setBackground(Color.gray);
    add(jline1);
    
    jline2.setBounds(20,395,285,1);
    jline2.setOpaque(true);
    jline2.setBackground(Color.gray);
    add(jline2);
    //--------------------------------------------------------------------------
    
    jstop.setEnabled(false);
    jstart.setEnabled(true);
            
    
    //Compiler says the assignment below is "unsafe".  Why?
    //Straight out of "Swing A Beginner's Guide"...
    
    Hashtable table = new Hashtable();
    table.put(new Integer(0), new JLabel("0"));
    //table.put(new Integer(100), new JLabel("1.0"));
    //table.put(new Integer(200), new JLabel("2.0"));
    //table.put(new Integer(300), new JLabel("3.0"));
    //table.put(new Integer(400), new JLabel("4.0"));
    table.put(new Integer(500), new JLabel("5.0"));
    //table.put(new Integer(600), new JLabel("6.0"));
    //table.put(new Integer(700), new JLabel("7.0"));
    //table.put(new Integer(800), new JLabel("8.0"));
    //table.put(new Integer(900), new JLabel("9.0"));
    table.put(new Integer(1000), new JLabel("10.0"));
    
    Hashtable table2 = new Hashtable();
    table2.put(new Integer(50), new JLabel("Slower"));
    table2.put(new Integer(450), new JLabel("Faster"));
    //-------------------------------------------------------------------------
    jslider_dipole.setLabelTable(table);
    jslider_animation.setLabelTable(table2);
        
    //jslider_dipole.setForeground(Color.red);
    //jslider_dipole.setLabelTable(jslider_dipole.createStandardLabels(1000));
    
    jslider_dipole.setPaintLabels(true);
    jslider_dipole.setBackground(Color.white);
    
    
    jslider_animation.setPaintLabels(true);
    jslider_animation.setBackground(Color.white);
    
    jcopyright = new JLabel("\u00a9  Amanogawa, "+annonuovo+" - All Rights Reserved");
    //jcopyright = new JLabel("All Rights Reserved");
    jcopyright.setForeground(Color.red.darker());
    jcopyright.setFont(new Font("Helvetica",Font.PLAIN,12));
    jcopyright.setBounds(10,550,350,15);
    add(jcopyright);
    
    //String text, text2;
    //text = "<html>\n"+"<font face=SanSerif>Dipole Length = "+MaestroA.rounder(vc.dipolelength,3)+"</font>";
    //text2 = "<html>\n"+"<font face=Serif> \u03bb</font>";
            
    jlab_dipole = new JLabel("Dipole Length = "+MaestroA.rounder(vc.dipolelength,3)+(" \u03bb"));
    //jlab_dipole = new JLabel(""+text+""+text2); 
    jlab_dipole.setFont(new Font("Serif",Font.BOLD,16));
    //jlab_dipole.setBounds(20,290,200,30);   // 8/3/14
    //jlab_dipole.setBounds(20,305,200,30);  8/8/14
    jlab_dipole.setBounds(20,305,220,30);
    jlab_dipole.setForeground(Color.red.darker());
    add(jlab_dipole);
    
    janimation = new JLabel("Animation");
    janimation.setFont(new Font("Serif",Font.BOLD,14));
    janimation.setBounds(40,425,150,20);
    janimation.setForeground(Color.blue.darker());
    add(janimation);
    
    jlambda = new JLabel(" \u03bb");
    jlambda.setFont(new Font("Serif",Font.BOLD,15));
    //jlambda.setBounds(480,Nside + 24,20,30);
    jlambda.setBounds(292,356,20,30);
    add(jlambda);
    
    // My own border...  much easier!!! JUST MADE WITH PANELS
    jtitlep1.setBounds(9,9,305,1);
    jtitlep1.setOpaque(true);
    jtitlep1.setBackground(Color.white);
    add(jtitlep1);
    
    jtitlep2.setBounds(12,46,300,1);
    jtitlep2.setOpaque(true);
    jtitlep2.setBackground(Color.white);
    add(jtitlep2);
    
    jtitlep3.setBounds(9,9,1,40);
    jtitlep3.setOpaque(true);
    jtitlep3.setBackground(Color.white);
    add(jtitlep3);
    
    jtitlep4.setBounds(311,12,1,35);
    jtitlep4.setOpaque(true);
    jtitlep4.setBackground(Color.white);
    add(jtitlep4);
    
    
    jtitle.setBounds(9,9,305,40);
    jtitle.setBorder(BorderFactory.createLineBorder(Color.gray,3));
    //jtitle.setBorder(BorderFactory.createEtchedBorder());
    jtitle.setOpaque(true);
    add(jtitle);
    
    // Make background of Instructions panel
    jInst4.setBounds(10,54,310,1);
    jInst4.setOpaque(true);
    jInst4.setBackground(Color.black);
    add(jInst4);
    jInst4.setVisible(true);
    
    jInst6.setBounds(319,10,1,45);
    jInst6.setOpaque(true);
    jInst6.setBackground(Color.black);
    add(jInst6);
    jInst6.setVisible(true);
    
    jInst3.setBounds(9,49,310,5);
    jInst3.setOpaque(true);
    jInst3.setBackground(Color.cyan);
    add(jInst3);
    jInst3.setVisible(true);
    
    jInst5.setBounds(314,8,5,47);
    jInst5.setOpaque(true);
    jInst5.setBackground(Color.cyan);
    add(jInst5);
    jInst5.setVisible(true);
    
    
    
    //jcontrols.setPreferredSize(new Dimension(300,50));
    //jcontrols.setBounds(9,Nside-4,Nside-18,124);
    jcontrols.setBounds(9,54,305,482);
    jcontrols.setBorder(BorderFactory.createLineBorder(Color.black));
    jcontrols.setBackground(Color.white);
    jcontrols.setOpaque(true);
    add(jcontrols);
    
    jaboutpanel.setBounds(9,10,813,526);
    jaboutpanel.setOpaque(true);
    jaboutpanel.setBorder(BorderFactory.createLineBorder(Color.black));
    jaboutpanel.setBackground(new Color(255,255,245));
    add(jaboutpanel);
    jaboutpanel.setVisible(false);
    
    jback2.setBounds(3,3,824,539);
    jback2.setOpaque(true);
    jback2.setBackground(Color.cyan);
    add(jback2);
    
    jback1.setBounds(0,0,830,545);
    jback1.setOpaque(true);
    jback1.setBackground(Color.black);
    add(jback1);
    
    jback3.setBounds(0,0,900,625);
    jback3.setOpaque(true);
    jback3.setBackground(Color.white);
    add(jback3);
    
    jstart.setVisible(false);
            jstop.setVisible(false);
            jabout.setVisible(false);
            pp.setVisible(false);
            vc.setVisible(false);
            jslider_dipole.setVisible(false);
            jslider_animation.setVisible(false);
  
            jlab_dipole.setVisible(false);
            jlambda.setVisible(false);
            jcopyright.setVisible(false);
            janimation.setVisible(false);
            jtitle1.setVisible(true);
            jtitle2.setVisible(true);
            jtitle3.setVisible(true);
            
            jback.setVisible(false);
            jforth.setVisible(false);
            jtitle.setVisible(true);
            jcontrols.setVisible(false);
            jline1.setVisible(false);
            jline2.setVisible(false);
            jtitlep1.setVisible(true);
            jtitlep2.setVisible(true);
            jtitlep3.setVisible(true);
            jtitlep4.setVisible(true);
            jtitlep5.setVisible(true);
            jtitlep6.setVisible(true);
            //jtitlep7.setVisible(false);
            //jtitlep8.setVisible(false);
            p_one.setVisible(false);
            
            jColorP.setVisible(false);
            jColorF.setVisible(false);
           
            //jback1.setVisible(false);
            //jback2.setVisible(false);
            //jback3.setVisible(false);

            jcontrols2.setVisible(false);
            jaboutpanel.setVisible(true);
            jclose.setVisible(true);
            pp2.setVisible(true);
    
    jslider_dipole.addChangeListener(
            new ChangeListener(){
                public void stateChanged(ChangeEvent ce)
                {
                   vc.dipolelength = (jslider_dipole.getValue()+1)*0.01 ;
                   if(vc.dipolelength >= 10.01){
                       vc.dipolelength = 10.0;
                       jslider_dipole.setValue(999);
                       forward = false;
                   }
                   if(vc.dipolelength <= 0.01){
                       vc.dipolelength = 0.01;
                       jslider_dipole.setValue(0);
                       forward = true;
                   }
                   
                    vc.repaint();
                   
                    my_antenna = vc.dipolelength;
                    pp.setdipole(my_antenna);
                    pp.repaint();
                   //String text3, text4;
                   //text3 = "<html>\n"+"<font face=SanSerif>Dipole Length = "+MaestroA.rounder(vc.dipolelength,3)+"</font>";
                   //text4 = "<html>\n"+"<font face=Serif> \u03bb</font>";
                   //jlab_dipole = new JLabel(""+text3+""+text2);
                   jlab_dipole.setText("Dipole Length = "+MaestroA.rounder(vc.dipolelength,3)+" \u03bb");
                }
            }
    );
    
    jslider_animation.addChangeListener(
            new ChangeListener(){
                public void stateChanged(ChangeEvent ce)
                {
                   sleep_factor = 500 - jslider_animation.getValue()+10 ;
                   vc.repaint();
                }
            }
    );
    
    jabout.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            jstart.setVisible(false);
            jstop.setVisible(false);
            jabout.setVisible(false);
            pp.setVisible(false);
            vc.setVisible(false);
            jslider_dipole.setVisible(false);
            jslider_animation.setVisible(false);
  
            jlab_dipole.setVisible(false);
            jlambda.setVisible(false);
            jcopyright.setVisible(false);
            janimation.setVisible(false);
            jtitle1.setVisible(true);
            jtitle2.setVisible(true);
            jtitle3.setVisible(true);

            jback.setVisible(false);
            jforth.setVisible(false);
            jtitle.setVisible(true);
            jcontrols.setVisible(false);
            jline1.setVisible(false);
            jline2.setVisible(false);
            jtitlep1.setVisible(true);
            jtitlep2.setVisible(true);
            jtitlep3.setVisible(true);
            jtitlep4.setVisible(true);
            jtitlep5.setVisible(true);
            jtitlep6.setVisible(true);
            jtitlep7.setVisible(false);
            jtitlep8.setVisible(false);
            jInst2.setVisible(true);
            jInst3.setVisible(true);
            jInst4.setVisible(true);
            jInst5.setVisible(true);
            jInst6.setVisible(true);
            p_one.setVisible(false);
            
            jColorP.setVisible(false);
            jColorF.setVisible(false);
           
            //jback1.setVisible(false);
            //jback2.setVisible(false);
            //jback3.setVisible(false);

            jcontrols2.setVisible(false);
            jaboutpanel.setVisible(true);
            jclose.setVisible(true);
            pp2.setVisible(true);
        }
    });
    
    jclose.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            jstart.setVisible(true);
            jstop.setVisible(true);
            jabout.setVisible(true);
            pp.setVisible(true);
            vc.setVisible(true);
            jslider_dipole.setVisible(true);
            jslider_animation.setVisible(true);
  
            jlab_dipole.setVisible(true);
            jlambda.setVisible(true);
            jcopyright.setVisible(true);
            janimation.setVisible(true);
            jtitle1.setVisible(true);
            jtitle2.setVisible(true);
            jtitle3.setVisible(true);
            
            jback.setVisible(true);
            jforth.setVisible(true);
            jtitle.setVisible(true);
            jcontrols.setVisible(true);
            jline1.setVisible(true);
            jline2.setVisible(true);
            jtitlep1.setVisible(true);
            jtitlep2.setVisible(true);
            jtitlep3.setVisible(true);
            jtitlep4.setVisible(true);
            jtitlep5.setVisible(true);
            jtitlep6.setVisible(true);
            jtitlep7.setVisible(true);
            jtitlep8.setVisible(true);
            
            jColorP.setVisible(true);
            jColorF.setVisible(true);
           
            p_one.setVisible(true);
            jcontrols2.setVisible(true);
            jaboutpanel.setVisible(false);
            jInst2.setVisible(false);
            jInst3.setVisible(false);
            jInst4.setVisible(false);
            jInst5.setVisible(false);
            jInst6.setVisible(false);
            jclose.setVisible(false);
            pp2.setVisible(false);
        }
    });
    
    jstart.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            jstart.setEnabled(false);
            jstop.setEnabled(true);
            jabout.setEnabled(false);
            running = true;
        }
    });
    
    jstop.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            jstop.setEnabled(false);
            jstart.setEnabled(true);
            jabout.setEnabled(true);
            running = false;
        }
    });
    
    jforth.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            //jforth.setEnabled(false);
            jforth.setVisible(false);
            //jback.setEnabled(true);
            jback.setVisible(true);
            forward = true;
            //direction = 1.0;
        }
    });
    
    jback.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            //jback.setEnabled(false);
            //jforth.setEnabled(true);
            jback.setVisible(false);
            jforth.setVisible(true);
            forward = false;
            //direction = -1.0;
        }
    });
    
    jColorF.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ce){
            Color color = JColorChooser.showDialog(Vector.this,"Choose Color", vc.color_line1);
            if(color != null){
                vc.color_line1 = color;
            }
            vc.repaint();
        }
    });
    
    jColorP.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ce){
            Color color = JColorChooser.showDialog(Vector.this,"Choose Color", vc.color_line2);
            if(color != null){
                vc.color_line2 = color;
            }
            vc.repaint();
        }
    });
    
    Fill[0].addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
           if(vc.IsPatchOn){
                vc.IsPatchOn = false;
           }
           else{
               vc.IsPatchOn = (true);
           }
           vc.repaint();
        }
    });
    
    
    Field[0].addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
           vc.exponent = 1.0;
           vc.IsPower = false;
           vc.repaint();
           //jColorF.setVisible(true);
           //jColorP.setVisible(false);
           
           jColorF.setVisible(false);
           jColorP.setVisible(false);
        }
    });
    
    Field[1].addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
           vc.exponent = 2.0;
           vc.IsPower = true;
           vc.repaint();
           //jColorP.setVisible(true);
           //jColorF.setVisible(false);
           
           jColorP.setVisible(false);
           jColorF.setVisible(false);
        }
    });
  }
  
  public void start(){}
  public void stop(){}
  public void destroy(){}
   
}


