//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 mydistance length
  // These input define k magnitude  [ k = omega * sqrt(mu epsilon) ]
  public JSlider jslider_mydistance;
  public JSlider jslider_WireLength;
  public JSlider jslider_mydistance2;
  public JSlider jslider_epsilon_r;
  
  // Define k-orientation
  public JSlider jslider_radius;
  public JSlider jslider_kphi;
  
  // Define E-vector
  public JSlider jslider_CurrentA;
  public JSlider jslider_CurrentB;
  public JSlider jslider_Ephase;
  public JSlider jslider_Ephi;
  
  //public JSlider jslider_animation;
  
  public JLabel jlab_mydistance;
  public JLabel jlab_WireLength; public JLabel jlab_WireLength2; public JLabel jlab_WireLength3;
  public JLabel jlab_epsilon, jlab_epsilon2, jlab_epsilon3;
  public JLabel jlab_radius;
  public JLabel jlab_phi;
  
  public JLabel jlab_CurrA; public JLabel jlab_CurrA2; public JLabel jlab_CurrA3;
  public JLabel jlab_CurrB; public JLabel jlab_CurrB2; public JLabel jlab_CurrB3;
  public JLabel jlab_rotate;
  
  public JLabel jlambda;
  public JLabel jlambda2;
  //public JLabel jcopyright;
  //public JLabel janimation;
  public JLabel jtitle1;
  public JLabel jtitle2, jtitle2a, jtitle2b;
  
  //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 JCheckBox jLabels;
  
  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 jline3 = new JPanel();
  public JPanel jline4 = 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 distance = 0.5; // [m]
  
  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();
        
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

class PaintPanel extends JPanel{
    PaintPanel(){
        mydistance = 1.50;
        setOpaque(true);
    //    setBorder(BorderFactory.createLineBorder(Color.RED,5));
    }  
      
    private double mydistance;
    public void setmydistance(double mydistance){
        this.mydistance = mydistance;
    }
    
    @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 = 13;
            int deltay = 16;
            int deltayy = 20;
            int y;
            
            y = ystart;
            
            g.setColor(Color.black);
                MaestroG.subscripterBold("Magnetic Induction","","",g,14,xstart+10, y);
                y += deltayy;
                MaestroG.subsupspecial5(" B","1"," = "+MaestroA.rounder(vc.B1,6)+" \u00d7 10","-6"," x"," ^"," [ T ]",g, 13, xstart+10, y);
                
                y += deltayy;
                MaestroG.subsupspecial5(" B","2"," = "+MaestroA.rounder(vc.B2,6)+" \u00d7 10","-6"," x"," ^"," [ T ]",g, 13, xstart+10, y);
                
                y += deltayy+2;
                MaestroG.subscripterBold("Total Magnetic Force on Wires","","",g,14,xstart+10, y);
                
                y += deltayy;
                MaestroG.subsupspecial5(" F","1"," = "+MaestroA.rounder(vc.F1,6)+" \u00d7 10","-6"," y"," ^"," [ N ]",g, 13, xstart+10, y);
                
                y += deltayy;
                MaestroG.subsupspecial5(" F","2"," = "+MaestroA.rounder(vc.F2,6)+" \u00d7 10","-6"," y"," ^"," [ N ]",g, 13, xstart+10, y);
                
                y += deltayy+2;
                MaestroG.subscripterBold("Magnetic Force per Unit Length","","",g,14,xstart+10, y);
                
                y += deltayy;
                MaestroG.subsupspecial5(" F'","1"," = "+MaestroA.rounder(vc.F1prime,6)+" \u00d7 10","-6"," y"," ^"," [ N/m ]",g, 13, xstart+10, y);
                
                y += deltayy;
                MaestroG.subsupspecial5(" F'","2"," = "+MaestroA.rounder(vc.F2prime,6)+" \u00d7 10","-6"," y"," ^"," [ N/m ]",g, 13, xstart+10, y);
            
        }
    
        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 mydistance;
    public void setmydistance(double mydistance){
        this.mydistance = mydistance;
    }
    
    @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 = 75;
            ytext = ystart;
        
            // INPUT
            g.setColor(Color.red);
            //g.setFont(state.ttfFont.deriveFont(Font.BOLD,15f));
            g.setFont(new Font("SanSerif",Font.BOLD,17));

            g.drawString("Assumption", xcolumn2,ytext);
            g.setColor(Color.black);
            //g.setFont(state.ttfFont.deriveFont(14f));
            g.setFont(new Font("SanSerif",Font.PLAIN,16));

            ytext += deltaY;
            s = "\u2022 Non-magnetic medium with permeability  "+STR.ITAL+"\u03bc = \u03bc"+STR.ENDITAL+STR.SUB+"0"+STR.ENDSUB;
            nextX = STR.displayString(s,g,xcolumn1,ytext);
            ytext += deltaY + 10;
            
            // 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 Currents flowing in the parallel wires";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "\u2022 Distance between the wires";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "\u2022 Length of the wires";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            
            ytext += deltaY + 10;

            // 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 Magnetic induction B at each wire location due to current flow in the neighboring wire";
            nextX = STR.displayString(s,g,xcolumn3,ytext);
            ytext += deltaY;
            s = "\u2022 Total force and force per unit length induced on the wires by the current flow";
            nextX = STR.displayString(s,g,xcolumn3,ytext);
            ytext += deltaY;
            s = "\u2022 3D diagram of the vectors and of the wires configuration";
            nextX = STR.displayString(s,g,xcolumn3,ytext);
                        
            g.setColor(Color.blue.darker());
            ytext += 2*deltaY;
            s = "This application illustrate the effect of magnetic force due to current flow in parallel conducting wires.";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += 3*deltaY/2;
            s = "\u2022 If the currents flow in the same direction, the wires attract each other with equal force.";
            nextX = STR.displayString(s,g,xcolumn2,ytext);
            ytext += deltaY;
            s = "\u2022 If the currents flow in opposite directions, the wires repel each other with equal force.";
            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_mydistance.setValue((int)(vc.distance));
           vc.repaint();
           
           distance = vc.distance;
           pp.setmydistance(distance);
           pp.repaint();
           
  }
  
  private void guiInit(){
    setLayout(null);
    vc = new VectorCanvas(); 
    add(vc);
    
    Dimension dim = getSize();
    pp = new PaintPanel();
    //pp.setBounds(12,425,299,140);
    pp.setBounds(12,380,299,190);
    pp.setBackground(Color.white);
    add(pp);
    
    jclose = new JButton("Close");
    jclose.setBounds(600,560,70,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;
        
    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 5.4");
    jtitle1.setFont(new Font("Helvetica",Font.PLAIN,14));
    jtitle1.setBounds(25,20,80,15);
    jtitle1.setForeground(Color.black);
    add(jtitle1);
    
    jtitle2 = new JLabel("Current Loop");
    jtitle2.setFont(new Font("Helvetica",Font.BOLD,16));
    jtitle2.setBounds(140,20,250,25);
    jtitle2.setForeground(Color.red.darker());
    //add(jtitle2);
    
    jtitle2a = new JLabel("Magnetic Force Between");
    jtitle2a.setFont(new Font("Helvetica",Font.BOLD,13));
    jtitle2a.setBounds(140,14,250,15);
    jtitle2a.setForeground(Color.red.darker());
    add(jtitle2a);
    
    jtitle2b = new JLabel("Two Parallel Conductors");
    jtitle2b.setFont(new Font("Helvetica",Font.BOLD,13));
    jtitle2b.setBounds(140,27,250,20);
    jtitle2b.setForeground(Color.red.darker());
    add(jtitle2b);
    
    jslider_mydistance = new JSlider(0,1000,500);
    //jslider_mydistance.setBounds(29,80,265,55);
    jslider_mydistance.setBounds(30,80,270,50);
    add(jslider_mydistance);
    jslider_mydistance.setMajorTickSpacing(500);
    jslider_mydistance.setMinorTickSpacing(100);
    jslider_mydistance.setPaintTicks(true);
    jslider_mydistance.setPaintLabels(true);
    jslider_mydistance.setBackground(Color.white);
    
    //Compiler says the assignment below is "unsafe".  Why?
    //Straight out of "Swing A Beginner's Guide"...
    // obsolete?
    Hashtable table = new Hashtable();
    table.put(new Integer(0), new JLabel("0.0"));
    table.put(new Integer(500), new JLabel("0.5"));
    table.put(new Integer(1000), new JLabel("1.0"));
    jslider_mydistance.setLabelTable(table);
    
    jslider_mydistance2 = new JSlider(0,1998,999);
    jslider_mydistance2.setBounds(30,130,270,20);
    //add(jslider_mydistance2);
    jslider_mydistance2.setMajorTickSpacing(500);
    jslider_mydistance2.setMinorTickSpacing(100);
    jslider_mydistance2.setPaintTicks(false);
    jslider_mydistance2.setPaintLabels(false);
    jslider_mydistance2.setBackground(Color.white);
    
    // thin panel to make horizontal lines
    jline1.setBounds(20,135,285,1);
    jline1.setOpaque(true);
    jline1.setBackground(Color.gray);
    add(jline1);
    
    //  This is used for the current
    jslider_CurrentA = new JSlider(0,2000,1100);
    jslider_CurrentA.setBounds(30,160,270,50);
    add(jslider_CurrentA);
    jslider_CurrentA.setMajorTickSpacing(500);
    jslider_CurrentA.setMinorTickSpacing(100);
    jslider_CurrentA.setPaintTicks(true);
    jslider_CurrentA.setPaintLabels(true);
    jslider_CurrentA.setBackground(Color.white);
    
    Hashtable table3 = new Hashtable();
    table3.put(new Integer(0), new JLabel("-10.0"));
    table3.put(new Integer(1000), new JLabel("0.0"));
    table3.put(new Integer(2000), new JLabel("10.0"));
    jslider_CurrentA.setLabelTable(table3);
    
    //  This is used for the current
    jslider_CurrentB = new JSlider(0,2000,1100);
    jslider_CurrentB.setBounds(30,240,270,50);
    add(jslider_CurrentB);
    jslider_CurrentB.setMajorTickSpacing(500);
    jslider_CurrentB.setMinorTickSpacing(100);
    jslider_CurrentB.setPaintTicks(true);
    jslider_CurrentB.setPaintLabels(true);
    jslider_CurrentB.setBackground(Color.white);
    
    Hashtable table5 = new Hashtable();
    table5.put(new Integer(0), new JLabel("-10.0"));
    table5.put(new Integer(1000), new JLabel("0.0"));
    table5.put(new Integer(2000), new JLabel("10.0"));
    jslider_CurrentB.setLabelTable(table5);
        
    jslider_epsilon_r = new JSlider(1000,10000,1100);
    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_WireLength = new JSlider(0,1000,500);
    jslider_WireLength.setBounds(30,320,270,50);
    add(jslider_WireLength);
    jslider_WireLength.setMajorTickSpacing(500);
    jslider_WireLength.setMinorTickSpacing(100);
    jslider_WireLength.setPaintTicks(true);
    jslider_WireLength.setPaintLabels(true);
    jslider_WireLength.setBackground(Color.white);
    
    Hashtable table7 = new Hashtable();
    table7.put(new Integer(0), new JLabel("0.0"));
    table7.put(new Integer(500), new JLabel("0.5"));
    table7.put(new Integer(1000), new JLabel("1.0"));
    jslider_WireLength.setLabelTable(table7);
    
    jslider_radius = new JSlider(10,100,50);
    jslider_radius.setBounds(30,240,270,50);
    //add(jslider_radius);
    jslider_radius.setMajorTickSpacing(50);
    jslider_radius.setMinorTickSpacing(10);
    jslider_radius.setPaintTicks(true);
    jslider_radius.setPaintLabels(true);
    jslider_radius.setBackground(Color.white);
    
    Hashtable table2 = new Hashtable();
    table2.put(new Integer(10), new JLabel("0.01"));
    table2.put(new Integer(50), new JLabel("0.05"));
    table2.put(new Integer(100), new JLabel("0.1"));
    jslider_radius.setLabelTable(table2);
    
    jslider_kphi = new JSlider(0,3600,0);
    jslider_kphi.setBounds(30,320,270,50);
    add(jslider_kphi);
    jslider_kphi.setMajorTickSpacing(1800);
    jslider_kphi.setMinorTickSpacing(450);
    jslider_kphi.setPaintTicks(true);
    jslider_kphi.setPaintLabels(true);
    jslider_kphi.setBackground(Color.white);
    
    Hashtable table4 = new Hashtable();
    table4.put(new Integer(0), new JLabel("0.0"));
    table4.put(new Integer(1800), new JLabel("180"));
    table4.put(new Integer(3600), new JLabel("360"));
    jslider_kphi.setLabelTable(table4);
    
    jslider_Ephi = new JSlider(0,3600,0);
    jslider_Ephi.setBounds(170,280,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");
    //jInstructions.setPreferredSize(new Dimension(70,25));
    jInstructions.setBounds(50,575,110,25);
    add(jInstructions);
    
    //--------------------------------------------------------------------------
    
    jline2.setBounds(20,215,285,1);
    jline2.setOpaque(true);
    jline2.setBackground(Color.gray);
    add(jline2);
    
    jline3.setBounds(20,295,285,1);
    jline3.setOpaque(true);
    jline3.setBackground(Color.gray);
    add(jline3);
    
    jline4.setBounds(20,375,285,1);
    jline4.setOpaque(true);
    jline4.setBackground(Color.gray);
    add(jline4);
    
    //--------------------------------------------------------------------------
    
    jLabels = new JCheckBox("Show Labels on Graph");
    //add(jLabels);
    jLabels.setSelected(true);
    jLabels.setBounds(40,378,200,22);
    jLabels.setBackground(Color.white);
    //jLabels.addItemListener(this);
    
    Field[0] = new JRadioButton("B\u2081", false);
    Field[0].setContentAreaFilled(false);
    Field[0].setFont(new Font("Serif",Font.BOLD,18));
    //Field[0].addItemListener(this);
    field_power.add(Field[0]);
    add(Field[0]);
    
    Field[1] = new JRadioButton("B\u2082", true);
    Field[1].setContentAreaFilled(false);
    Field[1].setFont(new Font("Serif",Font.BOLD,18));
    //Field[1].addItemListener(this);
    field_power.add(Field[1]);
    add(Field[1]);
    
    Field[0].setBounds(180,575,70,30);
    Field[1].setBounds(240,575,70,30);
    
    //-------------------------------------------------------------------------
    
    jlab_mydistance = new JLabel("Distance   d = 0.5 [m]");
    jlab_mydistance.setFont(new Font("Serif",Font.BOLD,16));
    jlab_mydistance.setBounds(40,53,200,30);
    jlab_mydistance.setForeground(Color.red.darker());
    add(jlab_mydistance);
    
    jlab_epsilon = new JLabel("\u03b5");
    jlab_epsilon.setFont(new Font("Serif",Font.BOLD,20));
    jlab_epsilon.setBounds(40,110,10,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_radius = new JLabel("Loop Radius  a = 0.05 [m]");
    jlab_radius.setFont(new Font("Serif",Font.BOLD,16));
    jlab_radius.setBounds(40,213,200,30);
    jlab_radius.setForeground(Color.red.darker());
    //add(jlab_radius);
    
    jlab_WireLength = new JLabel("Wire Length");
    jlab_WireLength.setFont(new Font("Serif",Font.BOLD,16));
    jlab_WireLength.setBounds(40,293,260,30);
    jlab_WireLength.setForeground(Color.red.darker());
    add(jlab_WireLength);
    
    jlab_WireLength2 = new JLabel("l");
    jlab_WireLength2.setFont(new Font("Serif",Font.BOLD | Font.ITALIC,20));
    jlab_WireLength2.setBounds(140,293,260,30);
    jlab_WireLength2.setForeground(Color.red.darker());
    add(jlab_WireLength2);
    
    jlab_WireLength3 = new JLabel(" = 0.5 [m]");
    jlab_WireLength3.setFont(new Font("Serif",Font.BOLD,16));
    jlab_WireLength3.setBounds(150,293,260,30);
    jlab_WireLength3.setForeground(Color.red.darker());
    add(jlab_WireLength3);
    
    jlab_phi = new JLabel("Angle of integration \u03c6 = 0.0\u00ba");
    jlab_phi.setFont(new Font("Serif",Font.BOLD,16));
    jlab_phi.setBounds(40,293,260,30);
    jlab_phi.setForeground(Color.red.darker());
    //add(jlab_phi);
    
    jlab_CurrA = new JLabel("Current  I");
    jlab_CurrA.setFont(new Font("Serif",Font.BOLD,16));
    jlab_CurrA.setBounds(40,133,200,30);
    jlab_CurrA.setForeground(Color.red.darker());
    add(jlab_CurrA);
    
    jlab_CurrA2 = new JLabel("1");
    jlab_CurrA2.setFont(new Font("Serif",Font.BOLD,16));
    jlab_CurrA2.setBounds(111,138,200,30);
    jlab_CurrA2.setForeground(Color.red.darker());
    add(jlab_CurrA2);
    
    jlab_CurrA3 = new JLabel(" = 1.0 [A]");
    jlab_CurrA3.setFont(new Font("Serif",Font.BOLD,16));
    jlab_CurrA3.setBounds(121,133,200,30);
    jlab_CurrA3.setForeground(Color.red.darker());
    add(jlab_CurrA3);
    
    jlab_CurrB = new JLabel("Current  I");
    jlab_CurrB.setFont(new Font("Serif",Font.BOLD,16));
    jlab_CurrB.setBounds(40,213,200,30);
    jlab_CurrB.setForeground(Color.red.darker());
    add(jlab_CurrB);
    
    jlab_CurrB2 = new JLabel("2");
    jlab_CurrB2.setFont(new Font("Serif",Font.BOLD,16));
    jlab_CurrB2.setBounds(111,218,200,30);
    jlab_CurrB2.setForeground(Color.red.darker());
    add(jlab_CurrB2);
    
    jlab_CurrB3 = new JLabel(" = 1.0 [A]");
    jlab_CurrB3.setFont(new Font("Serif",Font.BOLD,16));
    jlab_CurrB3.setBounds(121,213,200,30);
    jlab_CurrB3.setForeground(Color.red.darker());
    add(jlab_CurrB3);
    
    jlab_rotate = new JLabel("\u03c8 = 0.0\u00ba");
    jlab_rotate.setFont(new Font("Serif",Font.BOLD,16));
    jlab_rotate.setBounds(1,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_mydistance.setVisible(false);
    jslider_WireLength.setVisible(false);
    jlab_mydistance.setVisible(false);
    jslider_mydistance2.setVisible(false);

    jslider_epsilon_r.setVisible(false);
    jlab_epsilon.setVisible(false);
    jlab_epsilon2.setVisible(false);
    jlab_epsilon3.setVisible(false);
    jlab_radius.setVisible(false);
    jlab_phi.setVisible(false);
    jlab_WireLength.setVisible(false);
    jlab_CurrA.setVisible(false);
    jlab_CurrB.setVisible(false);
    jlab_rotate.setVisible(false);
    jLabels.setVisible(false);
    Field[0].setVisible(false);
    Field[1].setVisible(false);
    jslider_radius.setVisible(false);
    jslider_kphi.setVisible(false);
    jslider_CurrentA.setVisible(false);
    jslider_CurrentB.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_radius.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce)
            {
               vc.radius_loop = jslider_radius.getValue()*0.001;
               vc.repaint();
               jlab_radius.setText("Loop Radius  a = "+MaestroA.rounder(vc.radius_loop,3)+" [m]");

               pp.repaint();
            }
        }
    );
    
    jslider_kphi.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce)
            {
               vc.phi_rate = jslider_kphi.getValue()*0.001/3.6;
               vc.repaint();
               jlab_phi.setText("Angle of integration \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_mydistance.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce)
            {
                if(jslider_mydistance.getValue() == 0){
                    vc.distance = 0.001;
                }
                else{
                    vc.distance = ((jslider_mydistance.getValue())*0.001);
                }
                vc.repaint();
                distance = vc.distance;
                pp.setmydistance(distance);
                pp.repaint();
                jlab_mydistance.setText("Distance   d = "+MaestroA.rounder(vc.distance,3)+" [m]");
            }
        }
    );
    
    jslider_WireLength.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce)
            {
                if(jslider_WireLength.getValue() == 0){
                    vc.WireLength = 0.001;
                }
                else{
                    vc.WireLength = ((jslider_WireLength.getValue())*0.001);
                }
                vc.repaint();
                pp.repaint();
                jlab_WireLength3.setText(" = "+MaestroA.rounder(vc.WireLength,3)+" [m]");
            }
        }
    );
    
    jslider_mydistance2.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce)
            {

                //if(jslider_mydistance.getValue() = 5){
                    vc.distance = (jslider_mydistance.getValue()*0.1 - 0.5 + 0.001*(jslider_mydistance2.getValue()-999));
                    vc.repaint();
                    distance = vc.distance;
                    pp.setmydistance(distance);
                    pp.repaint();
                    jlab_mydistance.setText("z-axis location = "+MaestroA.rounder(vc.distance,3)+" [m]");
                
                //}
                //else{
                  //  vc.distance = (0.001*(jslider_mydistance2.getValue()-999));
                  //  vc.repaint();
                  //  distance = vc.distance;
                  //  pp.setmydistance(distance);
                  //  pp.repaint();
                  //  jlab_mydistance.setText("z-axis location = "+MaestroA.rounder(vc.distance*1000.0,1)+" [m]");
                //}
            }
        }
    );
    
    jslider_epsilon_r.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce)
            {
                vc.Current = (jslider_CurrentA.getValue()*0.01);
                jlab_CurrA.setText("Loop Current   I = "+MaestroA.rounder(vc.Current,3)+" [A]");
                    
                vc.repaint();
                pp.repaint();
                jlab_epsilon3.setText(" = "+MaestroA.rounder(vc.epsilon_r,2));
            }
        }
    );
    
    jslider_CurrentA.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce){
                
                    vc.Current1 = (jslider_CurrentA.getValue()*0.01 - 10.0);
                    jlab_CurrA3.setText(" = "+MaestroA.rounder(vc.Current1,3)+" [A]");
                    vc.repaint();
                    pp.repaint(); 
                
            }
        }
    );
    
    jslider_CurrentB.addChangeListener(
        new ChangeListener(){
            public void stateChanged(ChangeEvent ce){
                
                    vc.Current2 = (jslider_CurrentB.getValue()*0.01 - 10.0);
                    jlab_CurrB3.setText(" = "+MaestroA.rounder(vc.Current2,3)+" [A]");
                    vc.repaint();
                    pp.repaint(); 
                
            }
        }
    );
    
    jInstructions.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            jInstructions.setVisible(false);
            pp.setVisible(false);
            vc.setVisible(false);
            
            jslider_mydistance.setVisible(false);
            jlab_mydistance.setVisible(false);
            jslider_WireLength.setVisible(false);
            jlab_WireLength.setVisible(false);
            jslider_mydistance2.setVisible(false);
            
            jslider_epsilon_r.setVisible(false);
            jlab_epsilon.setVisible(false);
            jlab_epsilon2.setVisible(false);
            jlab_epsilon3.setVisible(false);
            jlab_radius.setVisible(false);
            //jlab_phi.setVisible(false);
            jlab_CurrA.setVisible(false);
            jlab_CurrB.setVisible(false);
            jlab_rotate.setVisible(false);
            jLabels.setVisible(false);
            Field[0].setVisible(false);
            Field[1].setVisible(false);
            
            jslider_radius.setVisible(false);
            //jslider_kphi.setVisible(false);
            jslider_CurrentA.setVisible(false);
            jslider_CurrentB.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){
                    //jlab_CurrA.setText("Loop Current   I = "+MaestroA.rounder(vc.Current,3)+" [A]");
                    vc.repaint();
                    pp.repaint();
            }
            else{
                    vc.repaint();
                    pp.repaint();
            }
        }
    });
    
    jclose.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            jInstructions.setVisible(true);
            pp.setVisible(true);
            vc.setVisible(true);
            jslider_mydistance.setVisible(true);
            jlab_mydistance.setVisible(true);
            jslider_WireLength.setVisible(true);
            jlab_WireLength.setVisible(true);
            jslider_mydistance2.setVisible(true);
            
            jslider_epsilon_r.setVisible(true);
            jlab_epsilon.setVisible(true);
            jlab_epsilon2.setVisible(true);
            jlab_epsilon3.setVisible(true);
            jlab_radius.setVisible(true);
            //jlab_phi.setVisible(true);
            jlab_CurrA.setVisible(true);
            jlab_CurrB.setVisible(true);
            jlab_rotate.setVisible(true);
            jLabels.setVisible(true);
            Field[0].setVisible(true);
            Field[1].setVisible(true);          
            
            jslider_radius.setVisible(true);
            //jslider_kphi.setVisible(true);
            jslider_CurrentA.setVisible(true);
            jslider_CurrentB.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);
        }
    });
    
    jLabels.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            if(vc.ShowLabels){
                vc.ShowLabels = false;
            }
            else{
                vc.ShowLabels = true;
            }
            
            vc.repaint();
            pp.repaint();
        }
    });
    
    Field[0].addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
            vc.enter_E = true;
            vc.repaint();
            pp.repaint();
        }
    });
    
    Field[1].addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
           vc.enter_E = false;
           vc.repaint();
           pp.repaint();
        }
    });  
  }
  
  public void start(){}
  public void stop(){}
  public void destroy(){}
   
}


