//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.awt.geom.Ellipse2D.Double;
import java.util.*;
import java.text.*;

public class Vector extends JFrame implements WindowListener{  
  
  // Draws the vectors diagram
  VectorCanvas vc;
  
  PaintPanel pp;
  PaintPanel2 pp2;
  
  public int anno_mio;
  
  // Slider for myfrequency length
  // These input define k magnitude  [ k = omega * sqrt(mu epsilon) ]
  public JSlider jslider_myfrequency;
  public JSlider jslider_myfrequency2;
  public JSlider jslider_epsilon_r;
  
  // Define k-orientation
  public JSlider jslider_ktheta;
  public JSlider jslider_kphi;
  
  // Define E-vector
  public JSlider jslider_Emagnitude;
  public JSlider jslider_Ephase;
  public JSlider jslider_Ephi;
  
  //public JSlider jslider_animation;
  
  public JLabel jlab_myfrequency;
  public JLabel jlab_epsilon, jlab_epsilon2, jlab_epsilon3;
  public JLabel jlab_theta;
  public JLabel jlab_phi;
  
  public JLabel jlab_Emag;
  public JLabel jlab_rotate;
  
  public JLabel jlambda;
  public JLabel jlambda2;
  //public JLabel jcopyright;
  //public JLabel janimation;
  public JLabel jtitle1;
  public JLabel jtitle2;
  
  //public JButton jstart;
  //public JButton jstop;
  //public JButton jback;
  //public JButton jforth;
  public JButton jInstructions;
  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 jback1 = new JPanel();
  public JPanel jback2 = new JPanel();
  public JPanel jback3 = new JPanel();
  
  public JPanel jInstructionspanel = 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 jcontrols2 = new JPanel();
  public int sleep_factor = 200;
  public int Nside, Nside1, Nside2;
  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 frequency = 10.0; // GHz
  GregorianCalendar Greg = new GregorianCalendar();
  
  //--------------------------------------------
  
  public static void main(String[] args){
        int xmove = 20;
        int ymove = 41;
        Vector f = new Vector();
        f.setSize(926+xmove,619+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 
                 pp.repaint();
              }
          });
      }
      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();        
        this.addWindowListener(this);
  }

class PaintPanel extends JPanel{
    PaintPanel(){
        myfrequency = 10.0;
        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);
            int xstart = 10;
            int ystart = 10;
            int deltay = 20;
            int deltayy = 26;
            int y;
            
            y = ystart+5;   // 9/17/14
            
            g.setColor(Color.black);
            MaestroG.subsupspecial2("  \u03b7","","  = "+MaestroA.rounder(vc.medium_impedance,3),""," [ \u03a9 ]",g, 14, xstart+10, y);
            y += deltayy;
            MaestroG.subsupspecial2("| k |",""," = "+MaestroA.rounder(vc.k_magnitude,6)+" [ rad m","-1"," ]",g, 14, xstart+10, y);
            y += deltay;
            MaestroG.subsupspecial2(" k","x","  = "+MaestroA.rounder(vc.kx,6)+" [ rad m","-1"," ]",g, 14, xstart+10, y);
            y += deltay;
            MaestroG.subsupspecial2(" k","y","  = "+MaestroA.rounder(vc.ky,6)+" [ rad m","-1"," ]",g, 14, xstart+10, y);
            y += deltay;
            if(jslider_ktheta.getValue() != 900){
                MaestroG.subsupspecial2(" k","z","  = "+MaestroA.rounder(vc.kz,6)+" [ rad m","-1"," ]",g, 14, xstart+10, y);
            }
            else{
                MaestroG.subsupspecial2(" k","z","  = 0.0 [ m","-1"," ]",g, 14, xstart+10, y);
            }
            
            y += deltayy;
            MaestroG.subsupspecial2("| E |",""," = "+MaestroA.rounder(vc.E_magnitude,6)+" [ V/m ]","","",g, 14, xstart+10, y);
            y += deltay;
            if(jslider_ktheta.getValue() != 900){
                MaestroG.subsupspecial2(" E","x","  = "+MaestroA.rounder(vc.Ex,6)+" [ V/m ]","","",g, 14, xstart+10, y);
            }
            else{
                MaestroG.subsupspecial2(" E","x","  = 0.0 [ V/m ]","","",g, 14, xstart+10, y);
            }
            y += deltay;
            MaestroG.subsupspecial2(" E","y","  = "+MaestroA.rounder(vc.Ey,6)+" [ V/m ]","","",g, 14, xstart+10, y);
            y += deltay;
            MaestroG.subsupspecial2(" E","z","  = "+MaestroA.rounder(vc.Ez,6)+" [ V/m ]","","",g, 14, xstart+10, y);
            
            y += deltayy;
            //  8/4/14
            //MaestroG.subsupspecial2("| H |",""," = "+MaestroA.rounder(vc.H_magnitude,6)+" [ A/m ]","","",g, 14, xstart+10, y);
            MaestroG.subsupspecial2("| H |",""," = "+MaestroA.rounder(vc.H_magnitude,6)+" [ A/m ]","","",g, 14, xstart+5, y);
            y += deltay;
            if(jslider_ktheta.getValue() != 900){
                MaestroG.subsupspecial2(" H","x","  = "+MaestroA.rounder(vc.Hx,6)+" [ A/m ]","","",g, 14, xstart+10, y);
            }
            else{
                MaestroG.subsupspecial2(" H","x","  = 0.0 [ A/m ]","","",g, 14, xstart+10, y);
            }
            y += deltay;
            MaestroG.subsupspecial2(" H","y","  = "+MaestroA.rounder(vc.Hy,6)+" [ A/m ]","","",g, 14, xstart+10, y);
            y += deltay;
            MaestroG.subsupspecial2(" H","z","  = "+MaestroA.rounder(vc.Hz,6)+" [ A/m ]","","",g, 14, xstart+10, y);
            
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            g.setColor(Color.black);
            //MaestroG.subscripterSansItalic("I",""," = "+MaestroA.rounder(myfrequency,2)+(" [A]"),g,20,xstart,y);
            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,25);

            //g.setFont(state.ttfFont.deriveFont(14f));
            //g.setFont(new Font("SanSerif",Font.PLAIN,14));
            //g.drawString("This module can accomodate linearly polarized plane "+
            //            "waves in both lossy and lossless media.",15,50);

            int xcolumn1 = 25; int xcolumn2 = 25; int xcolumn3 = 25;
            int ystart; int y;
            int ytext; int deltaY = 25;
            String s; int nextX;
            ystart = 50;
            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 Loss-less and non-magnetic dielectric medium with real";
            nextX = STR.displayString(s,g,xcolumn1,ytext);
            ytext += deltaY;
            s = "    impedance  "+STR.ITAL+"\u03b7"+STR.ENDITAL+"  and permeability  "+STR.ITAL+"\u03bc = \u03bc"+STR.ENDITAL+STR.SUB+"0"+STR.ENDSUB;
            nextX = STR.displayString(s,g,xcolumn1,ytext);
            
            ytext += deltaY+5;
            // 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 Relative permittivity  "+STR.ITAL+"\u03b5"+STR.ENDITAL+""+STR.SUB+"r"+STR.ENDSUB+" of the medium";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "\u2022 Wave frequency  "+STR.ITAL+"f"+STR.ENDITAL;
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "\u2022 Elevation angle "+STR.ITAL+"\u03b8"+STR.ENDITAL+" and azimuth angle "+STR.ITAL+"\u03c6"+STR.ENDITAL+" of the wave vector "+STR.ITAL+"k"+STR.ENDITAL+"";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "\u2022 Magnitude of the Electric field or magnitude of the Magnetic field";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "\u2022  Rotation angle "+STR.ITAL+"\u03c8"+STR.ENDITAL+" of the fields about the wave vector "+STR.ITAL+"k"+STR.ENDITAL+"";
            nextX = STR.displayString(s,g,xcolumn2,ytext);

            ytext += deltaY + 5;

            // 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 representation of the orthogonal relationship between the wave vector and the electromagnetic fields ";
            nextX = STR.displayString(s,g,xcolumn3,ytext);
            ytext += deltaY;
            s = "\u2022 Numerical values for medium impedance and the cartesian coordinates of the three vectors";
            nextX = STR.displayString(s,g,xcolumn3,ytext);
            
            g.setColor(Color.blue.darker());
            ytext += 3*deltaY/2;
            s = "This application provides an interactive 3D representation"+
                " of the fields and the wave vector of an";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "electromagnetic wave.  An arbitrary wave vector orientation "+
                "can be specified by selecting elevation angle and";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "azimuth angle.  The magnitude of the wave vector is determined by "+
                "the frequency and the medium permittivity.  ";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "The orientation of the electromagnetic fields can be specified"+
                " by selecting the rotation angle on the plane";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "perpendicular to the wave vector.";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
                       
            drawCopyRight(g);
            
            // draw diagram
            double x1 = 600.0; double y1 = 30.0; double x2 = 660.0; double y2 = 130.0;
            double rado = 90.0;
            
            Ellipse2D mosto = new Ellipse2D.Double(x2-rado,y2-rado/2,2*rado,rado);
            //g2d.draw(mosto);
            
            //AffineTransform perp;
            //perp = new AffineTransform();
            //perp.setToRotation(Math.toRadians(-6));
            //g2d.transform(perp);
            
            //g2d.translate(30.0,0.0);
            
            g2d.rotate(-Math.PI/6,x2,y2); // tilt the ellipse
            g2d.draw(mosto);
            
            g2d.rotate(Math.PI/6,x2,y2);  // rotate back
            
            drawDashLineThick(g, x2, y2, x2-100, y2+50, 1, 5, Color.lightGray);
            drawLineThick(g, x2, y2, x2+100, y2, 1, Color.lightGray);
            
            // E vector
            g.setFont(new Font("Serif",Font.BOLD | Font.ITALIC,20));
            g.setColor(Color.red);
            s = "E";
            nextX = STR.displayString(s,g,(int)x2+50,(int)y2-10);
            drawLineThick(g, x2, y2, x2+65, y2, 3, Color.red);
            drawLineThick(g, x2+65, y2, x2+55, y2+4, 3, Color.red);
            drawLineThick(g, x2+65, y2, x2+55, y2-4, 3, Color.red);
            
            // H vector
            g.setFont(new Font("Serif",Font.BOLD | Font.ITALIC,20));
            g.setColor(Color.blue);
            s = "H";
            nextX = STR.displayString(s,g,(int)x2+25,(int)y2-40);
            drawLineThick(g, x2, y2, x2+20, y2-55, 3, Color.blue);
            drawLineThick(g, x2+20, y2-55, x2+12, y2-46, 3, Color.blue);
            drawLineThick(g, x2+20, y2-55, x2+21, y2-44, 3, Color.blue);
            
            //drawLineThick(g, x1, y1, x1, y2+37, 1, Color.lightGray);
            drawDashLineThick(g, x1, y1, x1, y2+57, 1, 5, Color.magenta.brighter());
                        
            // k-vector
            g.setFont(new Font("Serif",Font.BOLD | Font.ITALIC,20));
            g.setColor(Color.gray);
            s = "k";
            nextX = STR.displayString(s,g,(int)x1+20,(int)y1+15);
            drawLineThick(g, x1, y1, x2, y2, 3, Color.black);
            drawLineThick(g, x1, y1, x1+3, y1+15, 3, Color.black);
            drawLineThick(g, x1, y1, x1+12, y1+10, 3, Color.black);
            
            // angles
            
            // angle theta
            g.setFont(new Font("Serif",Font.ITALIC,20));
            g.setColor(Color.black);
            s = "\u03b8";
            nextX = STR.displayString(s,g,(int)x2-20,(int)y2-50);
            
            // angle phi
            g.setFont(new Font("Serif",Font.ITALIC,20));
            g.setColor(Color.black);
            s = "\u03c6";
            nextX = STR.displayString(s,g,(int)x2-50,(int)y2+15);
            
            // angle psi
            g.setFont(new Font("Serif",Font.ITALIC,20));
            g.setColor(Color.black);
            s = "\u03c8";
            nextX = STR.displayString(s,g,(int)x2+30,(int)y2+15);
            
            //drawLineThick(g, x2+60, y2+60, x2, y2, 2, Color.lightGray); // 
            drawDashLineThick(g, x2+60, y2+60, x2, y2, 1, 5, Color.magenta.brighter());
            
            // xyz axes
            g.setFont(new Font("Serif",Font.BOLD | Font.ITALIC,18));
            g.setColor(Color.gray);
            s = "x";
            nextX = STR.displayString(s,g,(int)x1-75,(int)y2-5);
            drawLineThick(g, x1-70, y2, x2, y2, 2, Color.lightGray); // x
            drawLineThick(g, x1-70, y2, x1-60, y2-3, 2, Color.lightGray);
            drawLineThick(g, x1-70, y2, x1-60, y2+3, 2, Color.lightGray);
            
            g.setFont(new Font("Serif",Font.BOLD | Font.ITALIC,18));
            g.setColor(Color.gray);
            s = "y";
            nextX = STR.displayString(s,g,(int)x2+15,(int)y2+80);
            drawLineThick(g, x2+30, y2+70, x2, y2, 2, Color.lightGray); // y
            drawLineThick(g, x2+30, y2+70, x2+30, y2+61, 2, Color.lightGray);
            drawLineThick(g, x2+30, y2+70, x2+24, y2+64, 2, Color.lightGray);
            
            g.setFont(new Font("Serif",Font.BOLD | Font.ITALIC,19));
            g.setColor(Color.gray);
            s = "z";
            nextX = STR.displayString(s,g,(int)x2+9,(int)y1-15);
            drawLineThick(g, x2, y1-20, x2, y2, 2, Color.lightGray); // z
            drawLineThick(g, x2, y1-20, x2+3, y1-10, 2, Color.lightGray);
            drawLineThick(g, x2, y1-20, x2-3, y1-10, 2, Color.lightGray);
            
            g.setColor(Color.black);
            g.setFont(new Font("SanSerif",Font.PLAIN,12));
            s = "\u2022";
            nextX = STR.displayString(s,g,(int)x1-3,(int)y2+35);
            
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF); 
            
        }
        
        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);
        }
    
        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);
        }
}


  // This is to close the Window ---------------------
  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){}
  //---------------------------------------------------

  
  void updateTime(){
           
           if(!running)return;
           jslider_myfrequency.setValue((int)(vc.frequency));
           vc.repaint();
           
           frequency = vc.frequency;
           pp.setmyfrequency(frequency);
           pp.repaint();
           
  }
  
  private void guiInit(){
    setLayout(null);
    vc = new VectorCanvas(); 
    add(vc);
    
    Dimension dim = getSize();
    pp = new PaintPanel();
    pp.setBounds(12,280,299,280);
    pp.setBackground(Color.white);
    add(pp);
    
    //jclose = new JButton("Close");  8/8/14
    jclose = new JButton(" Close ");
    //jclose.setBounds(600,560,70,25);   8/8/14
    jclose.setBounds(600,560,80,25);
    add(jclose);
    jclose.setVisible(false);
        
    pp2 = new PaintPanel2();
    pp2.setBounds(10,55,910,556);
    pp2.setBackground(new Color(255,255,245));
    //pp2.setBorder(BorderFactory.createLineBorder(Color.gray,1));
    add(pp2);
    pp2.setVisible(false);
    
    Nside = 600;
    Nside1 = 770;
    Nside2 = 520;
        
    Field[0] = new JRadioButton("Select E", true);
    Field[0].setContentAreaFilled(false);
    //Field[0].addItemListener(this);
    field_power.add(Field[0]);
    add(Field[0]);
    
    Field[1] = new JRadioButton("Select H", false);
    Field[1].setContentAreaFilled(false);
    //Field[1].addItemListener(this);
    field_power.add(Field[1]);
    add(Field[1]);
    
    Field[0].setBounds(40,240,120,25);
    Field[1].setBounds(180,240,120,25);
    
    vc.setBounds(320,11,Nside,Nside);
    
            p_one = new Panel();
	    p_one.setBackground(Color.black);
	    add(p_one);
	    p_one.setBounds(319,10,Nside+2,Nside+2);
            
    jtitle1 = new JLabel("Module 7.1");
    jtitle1.setFont(new Font("Helvetica",Font.PLAIN,14));
    jtitle1.setBounds(25,20,80,15);
    jtitle1.setForeground(Color.black);
    add(jtitle1);
    
    jtitle2 = new JLabel("Linking E to H");
    jtitle2.setFont(new Font("Helvetica",Font.BOLD,16));
    jtitle2.setBounds(140,20,250,25);
    jtitle2.setForeground(Color.red.darker());
    add(jtitle2);
    
    jslider_myfrequency = new JSlider(0,100,10);
    //jslider_myfrequency.setBounds(29,80,265,55);
    jslider_myfrequency.setBounds(30,80,270,20);
    add(jslider_myfrequency);
    
    jslider_myfrequency.setMajorTickSpacing(50);
    jslider_myfrequency.setMinorTickSpacing(10);
    jslider_myfrequency.setPaintTicks(false);
    jslider_myfrequency.setPaintLabels(false);
    jslider_myfrequency.setBackground(Color.white);
    
    jslider_myfrequency2 = new JSlider(0,999,0);
    //jslider_myfrequency2.setBounds(37,135,249,40);
    jslider_myfrequency2.setBounds(30,100,270,20);
    add(jslider_myfrequency2);
    jslider_myfrequency2.setMajorTickSpacing(500);
    jslider_myfrequency2.setMinorTickSpacing(100);
    jslider_myfrequency2.setPaintTicks(false);
    jslider_myfrequency2.setPaintLabels(false);
    jslider_myfrequency2.setBackground(Color.white);
    
    jslider_epsilon_r = new JSlider(100,10000,100);
    jslider_epsilon_r.setBounds(30,140,270,20);
    add(jslider_epsilon_r);
    jslider_epsilon_r.setMajorTickSpacing(50);
    jslider_epsilon_r.setMinorTickSpacing(10);
    jslider_epsilon_r.setPaintTicks(false);
    jslider_epsilon_r.setPaintLabels(false);
    jslider_epsilon_r.setBackground(Color.white);
    
    jslider_ktheta = new JSlider(0,1800,450);
    jslider_ktheta.setBounds(30,180,130,20);
    add(jslider_ktheta);
    //jslider_ktheta.setMajorTickSpacing(50);
    //jslider_ktheta.setMinorTickSpacing(10);
    jslider_ktheta.setPaintTicks(false);
    jslider_ktheta.setPaintLabels(false);
    jslider_ktheta.setBackground(Color.white);
    
    jslider_kphi = new JSlider(0,3600,0);
    jslider_kphi.setBounds(170,180,130,20);
    add(jslider_kphi);
    //jslider_kphi.setMajorTickSpacing(50);
    //jslider_kphi.setMinorTickSpacing(10);
    jslider_kphi.setPaintTicks(false);
    jslider_kphi.setPaintLabels(false);
    jslider_kphi.setBackground(Color.white);
    
    jslider_Emagnitude = new JSlider(0,1000,100);
    jslider_Emagnitude.setBounds(30,220,130,20);
    add(jslider_Emagnitude);
    jslider_Emagnitude.setMajorTickSpacing(500);
    jslider_Emagnitude.setMinorTickSpacing(100);
    jslider_Emagnitude.setPaintTicks(false);
    jslider_Emagnitude.setPaintLabels(false);
    jslider_Emagnitude.setBackground(Color.white);
    
    jslider_Ephi = new JSlider(0,3600,0);
    jslider_Ephi.setBounds(170,220,130,20);
    add(jslider_Ephi);
    //jslider_Ephi.setMajorTickSpacing(50);
    //jslider_Ephi.setMinorTickSpacing(10);
    jslider_Ephi.setPaintTicks(false);
    jslider_Ephi.setPaintLabels(false);
    jslider_Ephi.setBackground(Color.white);
    
    //jInstructions = new JButton("Instructions");  8/8/14
    jInstructions = new JButton(" Instructions ");
    //jInstructions.setPreferredSize(new Dimension(70,25));
    //jInstructions.setBounds(100,575,110,25);   8/8/14
    jInstructions.setBounds(95,575,120,25);
    add(jInstructions);
    
    //--------------------------------------------------------------------------
    // thin panel to make horizontal lines
    //jline1.setBounds(20,270,285,1); 8/9/14  move up a little so #s not cut off
    jline1.setBounds(20,268,285,1);
    jline1.setOpaque(true);
    jline1.setBackground(Color.gray);
    add(jline1);
    
    jline2.setBounds(20,565,285,1);
    jline2.setOpaque(true);
    jline2.setBackground(Color.gray);
    add(jline2);
    //--------------------------------------------------------------------------
    
    //Compiler says the assignment below is "unsafe".  Why?
    //Straight out of "Swing A Beginner's Guide"...
    //  NOT USED HERE ANYWAY
    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(50), new JLabel("50.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(100), new JLabel("100.0"));
    
    Hashtable table2 = new Hashtable();
    table2.put(new Integer(50), new JLabel("Slower"));
    table2.put(new Integer(450), new JLabel("Faster"));
    //-------------------------------------------------------------------------
    jslider_myfrequency.setLabelTable(table);
    
    jlab_myfrequency = new JLabel("Frequency = 10.0 [GHz]");
    jlab_myfrequency.setFont(new Font("Serif",Font.BOLD,16));
    //jlab_myfrequency.setBounds(40,53,200,30);   8/8/14
    jlab_myfrequency.setBounds(40,53,220,30);
    jlab_myfrequency.setForeground(Color.red.darker());
    add(jlab_myfrequency);
    
    jlab_epsilon = new JLabel("\u03b5");
    jlab_epsilon.setFont(new Font("Serif",Font.BOLD,20));
    //jlab_epsilon.setBounds(40,110,10,30);
    jlab_epsilon.setBounds(40,110,20,30);
    jlab_epsilon.setForeground(Color.red.darker());
    add(jlab_epsilon);
    
    jlab_epsilon2 = new JLabel("r");
    jlab_epsilon2.setFont(new Font("Serif",Font.BOLD,16));
    jlab_epsilon2.setBounds(50,115,10,30);
    jlab_epsilon2.setForeground(Color.red.darker());
    add(jlab_epsilon2);
    
    jlab_epsilon3 = new JLabel(" = 1.0");
    jlab_epsilon3.setFont(new Font("Serif",Font.BOLD,16));
    jlab_epsilon3.setBounds(60,113,200,30);
    jlab_epsilon3.setForeground(Color.red.darker());
    add(jlab_epsilon3);
    
    jlab_theta = new JLabel("\u03b8 = 45.0\u00ba");
    jlab_theta.setFont(new Font("Serif",Font.BOLD,16));
    jlab_theta.setBounds(40,153,200,30);
    jlab_theta.setForeground(Color.red.darker());
    add(jlab_theta);
    
    jlab_phi = new JLabel("\u03c6 = 0.0\u00ba");
    jlab_phi.setFont(new Font("Serif",Font.BOLD,16));
    //jlab_phi.setBounds(180,153,200,30);   8/4/14
    //jlab_phi.setBounds(190,153,200,30);   8/8/14
    jlab_phi.setBounds(210,153,200,30);
    jlab_phi.setForeground(Color.red.darker());
    add(jlab_phi);
    
    jlab_Emag = new JLabel("| E | = 10.0 [V/m]");
    jlab_Emag.setFont(new Font("Serif",Font.BOLD,16));
    jlab_Emag.setBounds(40,193,200,30);
    jlab_Emag.setForeground(Color.red.darker());
    add(jlab_Emag);
    
    jlab_rotate = new JLabel("\u03c8 = 0.0\u00ba");
    jlab_rotate.setFont(new Font("Serif",Font.BOLD,16));
    //jlab_rotate.setBounds(180,193,200,30);    8/4/14
    //jlab_rotate.setBounds(190,193,200,30);    8/8/14
    jlab_rotate.setBounds(210,193,200,30);
    jlab_rotate.setForeground(Color.red.darker());
    add(jlab_rotate);
    
    jlambda = new JLabel("");
    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);
    
    jcontrols.setBounds(9,54,305,558);
    jcontrols.setBorder(BorderFactory.createLineBorder(Color.black));
    jcontrols.setBackground(Color.white);
    jcontrols.setOpaque(true);
    add(jcontrols);
    
    // 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,10,5,45);
    jInst5.setOpaque(true);
    jInst5.setBackground(Color.cyan);
    add(jInst5);
    jInst5.setVisible(true);
    
    jInst2.setBounds(9,10,912,602);
    jInst2.setOpaque(true);
    jInst2.setBorder(BorderFactory.createLineBorder(Color.black));
    jInst2.setBackground(new Color(255,255,245));
    add(jInst2);
    jInst2.setVisible(true);
    
    jInstructionspanel.setBounds(3,3,924,615);
    jInstructionspanel.setOpaque(true);
    //jInstructionspanel.setBorder(BorderFactory.createLineBorder(Color.black));
    jInstructionspanel.setBackground(Color.cyan);
    add(jInstructionspanel);
    jInstructionspanel.setVisible(true);
    
    jInstructions.setVisible(false);
    pp.setVisible(false);
    vc.setVisible(false);
    jslider_myfrequency.setVisible(false);
    jlab_myfrequency.setVisible(false);
    jslider_myfrequency2.setVisible(false);

    jslider_epsilon_r.setVisible(false);
    jlab_epsilon.setVisible(false);
    jlab_epsilon2.setVisible(false);
    jlab_epsilon3.setVisible(false);
    jlab_theta.setVisible(false);
    jlab_phi.setVisible(false);
    jlab_Emag.setVisible(false);
    jlab_rotate.setVisible(false);
    Field[0].setVisible(false);
    Field[1].setVisible(false);
    jslider_ktheta.setVisible(false);
    jslider_kphi.setVisible(false);
    jslider_Emagnitude.setVisible(false);
    //jslider_Ephase.setVisible(false);
    jslider_Ephi.setVisible(false);
    jlambda.setVisible(false);
    jcontrols.setVisible(false);
    jline1.setVisible(false);
    jline2.setVisible(false);
    p_one.setVisible(false);
    jcontrols2.setVisible(false);
    jInstructionspanel.setVisible(true);
    jInst2.setVisible(true);
    jInst3.setVisible(true);
    jInst4.setVisible(true);
    jInst5.setVisible(true);
    jInst6.setVisible(true);
    jclose.setVisible(true);
    pp2.setVisible(true);

    jback2.setBounds(3,3,924,615);
    jback2.setOpaque(true);
    jback2.setBackground(Color.cyan);
    add(jback2);
    
    jback1.setBounds(0,0,930,621);
    jback1.setOpaque(true);
    jback1.setBackground(Color.black);
    add(jback1);
    
    jback3.setBounds(0,0,1200,700);
    jback3.setOpaque(true);
    jback3.setBackground(Color.white);
    add(jback3);
    
    jslider_ktheta.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce)
            {
               vc.k_magnitude = 2.0*Math.PI*vc.frequency*1.0E9/(vc.light_velocity*Math.sqrt(vc.epsilon_r));
               vc.theta_rate = jslider_ktheta.getValue()*0.001/1.8;
               vc.repaint();
               jlab_theta.setText("\u03b8 = "+MaestroA.rounder(vc.theta_rate*180,3)+"\u00ba");

               pp.repaint();
            }
        }
    );
    
    jslider_kphi.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce)
            {
               vc.k_magnitude = 2.0*Math.PI*vc.frequency*1.0E9/(vc.light_velocity*Math.sqrt(vc.epsilon_r));
               vc.phi_rate = jslider_kphi.getValue()*0.001/3.6;
               vc.repaint();
               jlab_phi.setText("\u03c6 = "+MaestroA.rounder(vc.phi_rate*360,3)+"\u00ba");

               pp.repaint();
            }
        }
    );
    
    jslider_Ephi.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce)
            {
               vc.phi_rateE = jslider_Ephi.getValue()*0.001/3.6;
               vc.repaint();
               jlab_rotate.setText("\u03c8 = "+MaestroA.rounder(vc.phi_rateE*360,3)+"\u00ba");

               pp.repaint();
            }
        }
    );
        
    jslider_myfrequency.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce)
            {
                vc.frequency = (jslider_myfrequency.getValue() + 0.001*jslider_myfrequency2.getValue());
                vc.repaint();

                frequency = vc.frequency;
                pp.setmyfrequency(frequency);
                pp.repaint();
                jlab_myfrequency.setText("Frequency = "+MaestroA.rounder(vc.frequency,3)+" [GHz]");
            }
        }
    );
    
    jslider_myfrequency2.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce)
            {

                if(jslider_myfrequency.getValue() > 0){
                    vc.frequency = (jslider_myfrequency.getValue() + 0.001*jslider_myfrequency2.getValue());
                    vc.repaint();
                    frequency = vc.frequency;
                    pp.setmyfrequency(frequency);
                    pp.repaint();
                    jlab_myfrequency.setText("Frequency = "+MaestroA.rounder(vc.frequency,3)+" [GHz]");
                }
                else{
                    vc.frequency = (0.001*jslider_myfrequency2.getValue());
                    vc.repaint();
                    frequency = vc.frequency;
                    pp.setmyfrequency(frequency);
                    pp.repaint();
                    jlab_myfrequency.setText("Frequency = "+MaestroA.rounder(vc.frequency*1000.0,1)+" [MHz]");
                }
            }
        }
    );
    
    jslider_epsilon_r.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce)
            {
                vc.epsilon_r = (jslider_epsilon_r.getValue()*0.01);
                vc.medium_impedance = Math.sqrt(vc.mu_r*vc.mu0/(vc.epsilon_r*vc.epsilon0));
    
                if(vc.enter_E){
                    vc.E_magnitude = (jslider_Emagnitude.getValue()*0.1);
                    vc.H_magnitude = vc.E_magnitude/vc.medium_impedance;
                    jlab_Emag.setText("| E | = "+MaestroA.rounder(vc.E_magnitude,2)+" [V/m]");
                    
                }
                else{
                    vc.H_magnitude = (jslider_Emagnitude.getValue()*2.5E-4);
                    vc.E_magnitude = vc.H_magnitude*vc.medium_impedance;
                    jlab_Emag.setText("| H | = "+MaestroA.rounder(vc.H_magnitude,2)+" [A/m]");
                }
                
                vc.repaint();
                pp.repaint();
                jlab_epsilon3.setText(" = "+MaestroA.rounder(vc.epsilon_r,2));
            }
        }
    );
    
    jslider_Emagnitude.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce){
                if(vc.enter_E){
                    vc.E_magnitude = (jslider_Emagnitude.getValue()*0.1);
                    vc.H_magnitude = vc.E_magnitude/vc.medium_impedance;
                    jlab_Emag.setText("| E | = "+MaestroA.rounder(vc.E_magnitude,2)+" [V/m]");
                    vc.repaint();
                    pp.repaint(); 
                }
                else{
                    vc.H_magnitude = (jslider_Emagnitude.getValue()*2.5E-4);
                    vc.E_magnitude = vc.H_magnitude*vc.medium_impedance;
                    jlab_Emag.setText("| H | = "+MaestroA.rounder(vc.H_magnitude,2)+" [A/m]");
                    vc.repaint();
                    pp.repaint();
                }
            }
        }
    );
    
    jInstructions.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            jInstructions.setVisible(false);
            pp.setVisible(false);
            vc.setVisible(false);
            
            jslider_myfrequency.setVisible(false);
            jlab_myfrequency.setVisible(false);
            jslider_myfrequency2.setVisible(false);
            
            jslider_epsilon_r.setVisible(false);
            jlab_epsilon.setVisible(false);
            jlab_epsilon2.setVisible(false);
            jlab_epsilon3.setVisible(false);
            jlab_theta.setVisible(false);
            jlab_phi.setVisible(false);
            jlab_Emag.setVisible(false);
            jlab_rotate.setVisible(false);
            Field[0].setVisible(false);
            Field[1].setVisible(false);
            
            jslider_ktheta.setVisible(false);
            jslider_kphi.setVisible(false);
            jslider_Emagnitude.setVisible(false);
            jslider_Ephi.setVisible(false);
  
            jlambda.setVisible(false);
            jcontrols.setVisible(false);
            jline1.setVisible(false);
            jline2.setVisible(false);
            p_one.setVisible(false);
            
            jcontrols2.setVisible(false);
            jInstructionspanel.setVisible(true);
            jInst2.setVisible(true);
            jInst3.setVisible(true);
            jInst4.setVisible(true);
            jInst5.setVisible(true);
            jInst6.setVisible(true);
            jclose.setVisible(true);
            pp2.setVisible(true);
            
            if(vc.enter_E){
                    //vc.theta_rate = 0.25;
                    //vc.phi_rate = 0.0;
                    //vc.phi_rateE = 0.0;
                    //vc.epsilon_r = 1.0;
                    //jslider_ktheta.setValue(450);
                    //jslider_kphi.setValue(0);
                    //jslider_Ephi.setValue(0);
                    //jslider_Emagnitude.setValue(100);
                    //jslider_epsilon_r.setValue(0);
                    vc.medium_impedance = Math.sqrt(vc.mu_r*vc.mu0/(vc.epsilon_r*vc.epsilon0));
                    vc.E_magnitude = vc.H_magnitude*vc.medium_impedance;
                    vc.E_magnitude = 10.0; // [V/m]
                    vc.H_magnitude = vc.E_magnitude / vc.medium_impedance;

                    jlab_Emag.setText("| E | = "+MaestroA.rounder(vc.E_magnitude,2)+" [V/m]");

                    vc.repaint();
                    pp.repaint();
            }
            else{
                   //vc.theta_rate = 0.25;
                   //vc.phi_rate = 0.0;
                   //vc.phi_rateE = 0.0;
                   //vc.epsilon_r = 1.0;
                   //jslider_ktheta.setValue(450);
                   //jslider_kphi.setValue(0);
                   //jslider_Ephi.setValue(0);
                   //jslider_Emagnitude.setValue(100);
                   //jslider_epsilon_r.setValue(0);
                   vc.medium_impedance = Math.sqrt(vc.mu_r*vc.mu0/(vc.epsilon_r*vc.epsilon0));
                   vc.E_magnitude = vc.H_magnitude*vc.medium_impedance;
                   vc.H_magnitude = 0.025; // [A/m]
                   vc.E_magnitude = vc.H_magnitude * vc.medium_impedance;

                   jlab_Emag.setText("| H | = "+MaestroA.rounder(vc.H_magnitude,6)+" [A/m]");

                   vc.repaint();
                   pp.repaint();
            }
        }
    });
    
    jclose.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            jInstructions.setVisible(true);
            pp.setVisible(true);
            vc.setVisible(true);
            jslider_myfrequency.setVisible(true);
            jlab_myfrequency.setVisible(true);
            jslider_myfrequency.setVisible(true);
            jlab_myfrequency.setVisible(true);
            jslider_myfrequency2.setVisible(true);
            
            jslider_epsilon_r.setVisible(true);
            jlab_epsilon.setVisible(true);
            jlab_epsilon2.setVisible(true);
            jlab_epsilon3.setVisible(true);
            jlab_theta.setVisible(true);
            jlab_phi.setVisible(true);
            jlab_Emag.setVisible(true);
            jlab_rotate.setVisible(true);
            Field[0].setVisible(true);
            Field[1].setVisible(true);          
            
            jslider_ktheta.setVisible(true);
            jslider_kphi.setVisible(true);
            jslider_Emagnitude.setVisible(true);
            jslider_Ephi.setVisible(true);
            
            jtitle1.setVisible(true);
            jtitle2.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);
            
            p_one.setVisible(true);
            jcontrols2.setVisible(true);
            jInstructionspanel.setVisible(false);
            jInst2.setVisible(false);
            jInst3.setVisible(false);
            jInst4.setVisible(false);
            jInst5.setVisible(false);
            jInst6.setVisible(false);
            jclose.setVisible(false);
            pp2.setVisible(false);
        }
    });
    
    Field[0].addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            vc.enter_E = true;
               
            vc.theta_rate = 0.25;
            vc.phi_rate = 0.0;
            vc.phi_rateE = 0.0;
            vc.epsilon_r = 1.0;
            jslider_ktheta.setValue(450);
            jslider_kphi.setValue(0);
            jslider_Ephi.setValue(0);
            jslider_Emagnitude.setValue(100);
            jslider_epsilon_r.setValue(0);
            vc.medium_impedance = Math.sqrt(vc.mu_r*vc.mu0/(vc.epsilon_r*vc.epsilon0));
            vc.E_magnitude = vc.H_magnitude*vc.medium_impedance;
            vc.E_magnitude = 10.0; // [V/m]
            vc.H_magnitude = vc.E_magnitude / vc.medium_impedance;
            
            jlab_Emag.setText("| E | = "+MaestroA.rounder(vc.E_magnitude,2)+" [V/m]");
            
            vc.repaint();
            pp.repaint();
            
        }
    });
    
    Field[1].addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
           vc.enter_E = false;
           
           vc.theta_rate = 0.25;
           vc.phi_rate = 0.0;
           vc.phi_rateE = 0.0;
           vc.epsilon_r = 1.0;
           jslider_ktheta.setValue(450);
           jslider_kphi.setValue(0);
           jslider_Ephi.setValue(0);
           jslider_Emagnitude.setValue(100);
           jslider_epsilon_r.setValue(0);
           vc.medium_impedance = Math.sqrt(vc.mu_r*vc.mu0/(vc.epsilon_r*vc.epsilon0));
           vc.E_magnitude = vc.H_magnitude*vc.medium_impedance;
           vc.H_magnitude = 0.025; // [A/m]
           vc.E_magnitude = vc.H_magnitude * vc.medium_impedance;
           
           jlab_Emag.setText("| H | = "+MaestroA.rounder(vc.H_magnitude,6)+" [A/m]");
           
           vc.repaint();
           pp.repaint();
           
        }
    });  
  }
  
  public void start(){}
  public void stop(){}
  public void destroy(){}
   
}


