 package DFT;
 
 import java.awt.Color;
 import java.awt.Graphics;
 
 public class Graph extends javax.swing.JPanel
 {
   private static final long serialVersionUID = 1L;
   private float[] dft;
   
   public Graph()
   {
     this.dft = new float[0];
   }
   
   public void update(float[] dft) {
     this.dft = dft;
     repaint();
   }
   
   public void paintComponent(Graphics g)
   {
     g.setColor(new Color(250, 250, 250));
     g.fillRect(0, 0, getWidth(), getHeight());
     
 
 
     float space = (getWidth() - 30) / this.dft.length;
     
 
     float max = 0.0F;float indexMax = 0.0F;float tmp = 0.0F;
     for (int i = 0; i < this.dft.length; i++) {
       max = Math.max(max, this.dft[i]);
       if (max != tmp) {
         indexMax = i;
         tmp = max;
       }
     }
     float heightScale = (getHeight() - 50) / max;
     
     g.setColor(Color.RED);
     
     g.drawLine(18, getHeight() - 20, getWidth() - 10, getHeight() - 20);
     g.drawLine(getWidth() - 10, getHeight() - 20, getWidth() - 15, getHeight() - 15);
     g.drawLine(getWidth() - 10, getHeight() - 20, getWidth() - 15, getHeight() - 25);
     g.drawString("N", getWidth() - 10, getHeight() - 5);
     
     g.drawLine(18, getHeight() - 20, 18, 20);
     g.drawLine(18, 20, 13, 25);
     g.drawLine(18, 20, 23, 25);
     g.drawString("mag", 2, 15);
     //g.drawString((int)max, (int)(indexMax * space) + 25, getHeight() - (int)(max * heightScale) - 20);
     
 
 
     g.translate(20, -20);
     g.setColor(Color.BLACK);
     for (int i = 0; i < this.dft.length; i++) g.fillRect((int)(i * space), getHeight() - (int)(this.dft[i] * heightScale), 1, (int)(this.dft[i] * heightScale));
     g.translate(-20, 20);
   }
 }





