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

public class PlaneWaveOutputPanel extends Panel implements ItemListener{
	PlaneWave_State state;
	private static final Color bgcolor = new Color(236,236,236);
	private Font labfont;
	private Font symbolfont;
        private Font titlefont;
	Label titlelabel;	
	public Choice c1;
	PlaneWaveOutputCanvasA pwocA; 
	PlaneWaveOutputCanvasB pwocB; 
	
        public PlaneWaveOutputPanel(PlaneWave_State state){
	    super();
	    setLayout(null);
            this.state = state;
	    setBackground(bgcolor);
	    
            labfont=new Font("SanSerif",Font.PLAIN,state.font11);
            symbolfont=new Font("Serif",Font.PLAIN,state.font11);
            titlefont=new Font("SanSerif",Font.BOLD,state.font16);
	
            titlelabel = new Label("Output Data");
	    //add(titlelabel);
	    titlelabel.setFont(titlefont);
	    
	    c1 = new Choice();
	    c1.addItem("   Fields   ");
	    c1.addItem("   Wave Properties   ");
	    //add(c1);
	    c1.setBounds(120,5,150,30);
	    
	    pwocA = new PlaneWaveOutputCanvasA(state);
	    add(pwocA);
	    pwocA.setBounds(0,0,state.s200+state.s80,state.s200+state.s65);
	    
            pwocB = new PlaneWaveOutputCanvasB(state);
	    add(pwocB);
	    //pwocB.setBounds(0,0,280,270);
	    
	    pwocA.setVisible(true);
	    pwocB.setVisible(false);
	    
            //Listeners
	    c1.addItemListener(this);
	}


public void itemStateChanged(ItemEvent evt){
	ItemSelectable ie = evt.getItemSelectable();
	    if(evt.getSource()==c1){
		if(ie.getSelectedObjects()[0]=="   Wave Properties   "){
		    pwocA.setVisible(true);
		    pwocB.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="   Fields   "){
		    pwocA.setVisible(false);
		    pwocB.setVisible(true);
		}
	    }
    }	
}//PlaneWaveOutputPanel.java

class PlaneWaveOutputCanvasA extends Canvas{
	private static final Font normalfont = new Font("SanSerif",Font.PLAIN,11);
	private static final Font symbolfont = new Font("Serif",Font.PLAIN,13);
	private static final Font subfont    = new Font("SanSerif",Font.PLAIN,10);
	PlaneWave_State state;
	private Image im;
	private Graphics buf;

	public PlaneWaveOutputCanvasA(PlaneWave_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawGraph(buf);
	    }
	    else{
		drawGraph(buf);
	    }
	    g.drawImage(im,0,0,null);
	}
	
	//Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}

	public void drawGraph(Graphics g){
	    int x, y, dx, dxx, dy, dyy;
	    double v_normalized;
	    FontMetrics fm;
	    double temp, temp2;
	    int fonto = state.font11;
            int fonto_delta = state.s12;
            int fontonew = state.s13;
	    
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            x = state.s20;
	    y = state.s50;
	    dx = state.s90;
	    dxx = state.s15;
	    
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = fm.getHeight()-1;
	    dyy = dy + state.s3;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    
            g.setColor(Color.black);
	    
            int startx = state.s12;
            int x_expA = state.s75;
            
            double tempT, tempPrint;
            tempT = state.tempo;
            if(tempT == 0.0){
                MaestroG.subsup("t = ","","0.0",""," [ s ]",g,fontonew,state.s10,state.s15);
            }
            else if(tempT >= 1.0E-20 && tempT < 1.0E-19){
                tempPrint = MaestroA.rounder(tempT/1.0E-20,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-20"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-19 && tempT < 1.0E-18){
                tempPrint = MaestroA.rounder(tempT/1.0E-19,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-19"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-18 && tempT < 1.0E-17){
                tempPrint = MaestroA.rounder(tempT/1.0E-18,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-18"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-17 && tempT < 1.0E-16){
                tempPrint = MaestroA.rounder(tempT/1.0E-17,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-17"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-16 && tempT < 1.0E-15){
                tempPrint = MaestroA.rounder(tempT/1.0E-16,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-16"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-15 && tempT < 1.0E-14){
                tempPrint = MaestroA.rounder(tempT/1.0E-15,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-15"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-14 && tempT < 1.0E-13){
                tempPrint = MaestroA.rounder(tempT/1.0E-14,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-14"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-13 && tempT < 1.0E-12){
                tempPrint = MaestroA.rounder(tempT/1.0E-13,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-13"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-12 && tempT < 1.0E-11){
                tempPrint = MaestroA.rounder(tempT/1.0E-12,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-12"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-11 && tempT < 1.0E-10){
                tempPrint = MaestroA.rounder(tempT/1.0E-11,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-11"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-10 && tempT < 1.0E-9){
                tempPrint = MaestroA.rounder(tempT/1.0E-10,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-10"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-9 && tempT < 1.0E-8){
                tempPrint = MaestroA.rounder(tempT/1.0E-9,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-9"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-8 && tempT < 1.0E-7){
                tempPrint = MaestroA.rounder(tempT/1.0E-8,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-8"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-7 && tempT < 1.0E-6){
                tempPrint = MaestroA.rounder(tempT/1.0E-7,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-7"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-6 && tempT < 1.0E-5){
                tempPrint = MaestroA.rounder(tempT/1.0E-6,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-6"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-5 && tempT < 1.0E-4){
                tempPrint = MaestroA.rounder(tempT/1.0E-5,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-5"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-4 && tempT < 1.0E-3){
                tempPrint = MaestroA.rounder(tempT/1.0E-4,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-4"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-3 && tempT < 1.0E-2){
                tempPrint = MaestroA.rounder(tempT/1.0E-3,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-3"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-2 && tempT < 1.0E-1){
                tempPrint = MaestroA.rounder(tempT/1.0E-2,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-2"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0E-1 && tempT < 1.0){
                tempPrint = MaestroA.rounder(tempT/1.0E-1,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("",""," [ x 10","-1"," s ]",g,fontonew,x_expA,state.s15);
            }
            else if(tempT >= 1.0){
                tempPrint = MaestroA.rounder(tempT,3);
                MaestroG.subsup("t = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s15);
                MaestroG.subsup("","","",""," [ s ]",g,fontonew,x_expA,state.s15);
            }
            
            g.setColor(Color.red.darker());
            int x_expB = state.s160;
            
            tempT = state.kineticE;
            if(tempT == 0.0){
                MaestroG.subsup("Kinetic Energy = ","","0.0",""," [ J ]",g,fontonew,state.s10,state.s35);
            }
            else if(tempT >= 1.0E-30 && tempT < 1.0E-29){
                tempPrint = MaestroA.rounder(tempT/1.0E-30,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-30"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-29 && tempT < 1.0E-28){
                tempPrint = MaestroA.rounder(tempT/1.0E-29,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-29"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-28 && tempT < 1.0E-27){
                tempPrint = MaestroA.rounder(tempT/1.0E-28,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-28"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-27 && tempT < 1.0E-26){
                tempPrint = MaestroA.rounder(tempT/1.0E-27,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-27"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-26 && tempT < 1.0E-25){
                tempPrint = MaestroA.rounder(tempT/1.0E-26,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-26"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-25 && tempT < 1.0E-24){
                tempPrint = MaestroA.rounder(tempT/1.0E-25,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-25"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-24 && tempT < 1.0E-23){
                tempPrint = MaestroA.rounder(tempT/1.0E-24,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-24"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-23 && tempT < 1.0E-22){
                tempPrint = MaestroA.rounder(tempT/1.0E-23,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-23"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-22 && tempT < 1.0E-21){
                tempPrint = MaestroA.rounder(tempT/1.0E-22,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-22"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-21 && tempT < 1.0E-20){
                tempPrint = MaestroA.rounder(tempT/1.0E-21,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-21"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-20 && tempT < 1.0E-19){
                tempPrint = MaestroA.rounder(tempT/1.0E-20,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-20"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-19 && tempT < 1.0E-18){
                tempPrint = MaestroA.rounder(tempT/1.0E-19,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-19"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-18 && tempT < 1.0E-17){
                tempPrint = MaestroA.rounder(tempT/1.0E-18,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-18"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-17 && tempT < 1.0E-16){
                tempPrint = MaestroA.rounder(tempT/1.0E-17,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-17"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-16 && tempT < 1.0E-15){
                tempPrint = MaestroA.rounder(tempT/1.0E-16,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-16"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-15 && tempT < 1.0E-14){
                tempPrint = MaestroA.rounder(tempT/1.0E-15,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-15"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-14 && tempT < 1.0E-13){
                tempPrint = MaestroA.rounder(tempT/1.0E-14,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-14"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-13 && tempT < 1.0E-12){
                tempPrint = MaestroA.rounder(tempT/1.0E-13,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","[ x 10","-13"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-12 && tempT < 1.0E-11){
                tempPrint = MaestroA.rounder(tempT/1.0E-12,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-12"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-11 && tempT < 1.0E-10){
                tempPrint = MaestroA.rounder(tempT/1.0E-11,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-11"," J ]",g,fontonew,x_expB,state.s35);
            }
            else if(tempT >= 1.0E-10 && tempT < 1.0E-9){
                tempPrint = MaestroA.rounder(tempT/1.0E-10,3);
                MaestroG.subsup("Kinetic Energy = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s35);
                MaestroG.subsup("","","  [ x 10","-10"," J ]",g,fontonew,x_expB,state.s35);
            }
            
            //MaestroG.subscripter("kinetic Energy = "+state.kineticE,"","",g,fontonew,state.s10,state.s35);
            
            int x_expC = state.s105;
            double tempV;
            tempV = state.velocity;
            if(tempV == 0.0){
                MaestroG.subsup("| u(t) | = ","","0.0",""," [ s ]",g,fontonew,state.s10,state.s55);
            }
            else if(tempV >= 0.0 && tempV < 10.0){
                tempPrint = MaestroA.rounder(tempV,3);
                MaestroG.subsup("| u(t) | = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s55);
                MaestroG.subsup("","","",""," [ m/s ]",g,fontonew,x_expC,state.s55);
            }
            else if(tempV >= 10.0 && tempV < 1.0E2){
                tempPrint = MaestroA.rounder(tempV/1.0E1,3);
                MaestroG.subsup("| u(t) | = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s55);
                MaestroG.subsup("","","  [ x 10","1"," m/s ]",g,fontonew,x_expC,state.s55);
            }
            else if(tempV >= 1.0E2 && tempV < 1.0E3){
                tempPrint = MaestroA.rounder(tempV/1.0E2,3);
                MaestroG.subsup("| u(t) | = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s55);
                MaestroG.subsup("","","  [ x 10","2"," m/s ]",g,fontonew,x_expC,state.s55);
            }
            else if(tempV >= 1.0E3 && tempV < 1.0E4){
                tempPrint = MaestroA.rounder(tempV/1.0E3,3);
                MaestroG.subsup("| u(t) | = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s55);
                MaestroG.subsup("","","  [ x 10","3"," m/s ]",g,fontonew,x_expC,state.s55);
            }
            else if(tempV >= 1.0E4 && tempV < 1.0E5){
                tempPrint = MaestroA.rounder(tempV/1.0E4,3);
                MaestroG.subsup("| u(t) | = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s55);
                MaestroG.subsup("","","  [ x 10","4"," m/s ]",g,fontonew,x_expC,state.s55);
            }
            else if(tempV >= 1.0E5 && tempV < 1.0E6){
                tempPrint = MaestroA.rounder(tempV/1.0E5,3);
                MaestroG.subsup("| u(t) | = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s55);
                MaestroG.subsup("","","  [ x 10","5"," m/s ]",g,fontonew,x_expC,state.s55);
            }
            else if(tempV >= 1.0E6 && tempV < 1.0E7){
                tempPrint = MaestroA.rounder(tempV/1.0E6,3);
                MaestroG.subsup("| u(t) | = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s55);
                MaestroG.subsup("","","  [ x 10","6"," m/s ]",g,fontonew,x_expC,state.s55);
            }
            else if(tempV >= 1.0E7 && tempV < 1.0E8){
                tempPrint = MaestroA.rounder(tempV/1.0E7,3);
                MaestroG.subsup("| u(t) | = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s55);
                MaestroG.subsup("","","  [ x 10","7"," m/s ]",g,fontonew,x_expC,state.s55);
            }
            else if(tempV >= 1.0E8 && tempV < 3.0E8){
                tempPrint = MaestroA.rounder(tempV/1.0E8,3);
                MaestroG.subsup("| u(t) | = ","",""+tempPrint,"","",g,fontonew,state.s10,state.s55);
                MaestroG.subsup("","","  [ x 10","8"," m/s ]",g,fontonew,x_expC,state.s55);
            }
            //MaestroG.subscripter("|v(x,y)| = "+state.velocity,"","",g,fontonew,state.s10,state.s55);
            
            g.setColor(Color.blue.darker());
            MaestroG.subsup("x = ","",""+MaestroA.rounder(state.xpos,6)+" m","","",g,fontonew,state.s20,state.s80);
            MaestroG.subsup("y = ","",""+MaestroA.rounder(state.ypos,6)+" m","","",g,fontonew,state.s160,state.s80);
        }            
}

class PlaneWaveOutputCanvasB extends Canvas{
	private static final Font normalfont = new Font("SanSerif",Font.PLAIN,12);
	private static final Font subfont    = new Font("SanSerif",Font.PLAIN,10);
	PlaneWave_State state;
	
        private Image im;
	private Graphics buf;

        public PlaneWaveOutputCanvasB(PlaneWave_State state){
	    super();
	    this.state = state;
	}
	
        public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawGraph(buf);
	    }
	    else{
		drawGraph(buf);
	    }
	    g.drawImage(im,0,0,null);
	}
	
	//Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}

	public void drawGraph(Graphics g){
	    int x, y, dx, dxx, dy, dyy, xinit2, xshift1, xshift2, xshift3, fonto;
	    double v_normalized, SA, SB, PA, PB, Pdiff;
	    String unita;
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            g.clearRect(0,0,getSize().width,getSize().height);
	    
            int startx = 12;
            g.setColor(Color.gray);
            MaestroG.subscripterBold("Output","","",g,14,startx+1,startx+6);
            g.setColor(Color.red.darker());
            MaestroG.subscripterBold("Output","","",g,14,startx,startx+5);
            
            
        }
}
