You are on page 1of 3

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package equalizer;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.border.LineBorder;
/**
*
* @author RusheeswarReddy
*/
public class Equalizer extends JPanel {
int[][] bar;
static int barNumber;
static Integer[] numberOfBars=new Integer[5];
static Integer[] numberOfBarsModified=new Integer[5];
int y;
int i;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Equalizer e1=new Equalizer();
e1.run();
}
public void run()
{
JFrame frame=new JFrame("Graphic Equalizer");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Draw1[] d=new Draw1[40];
JPanel panel=new JPanel();
frame.setSize(525,300);
// frame.setLayout(new FlowLayout(FlowLayout.CENTER,20,10));
for(i=0;i<5;i++) { d[i]=new Draw1(); System.out.println("first for"); th
is.add(d[i]); }
Draw1 d1=new Draw1();
//Draw1 d2=new Draw1();
//Draw1 d3=new Draw1();
//Draw1 d4=new Draw1();
//Draw1 d5=new Draw1();
panel.add(d1);
d1.setPreferredSize(new Dimension(525,300));
// panel.setBorder(new LineBorder(Color.black));
frame.add(panel);
// panel.setVisible(true);
// frame.add(d1);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
for(;;) {
Equalizer.numberOfBars[0]=1;
Equalizer.numberOfBars[1]=2;
Equalizer.numberOfBars[2]=3;
Equalizer.numberOfBars[3]=4;
Equalizer.numberOfBars[4]=5;
try {
Scanner file=new Scanner(new File("arduinoDatabase.txt"));
if(file.hasNextInt())
{
barNumber=file.nextInt()-1;
Equalizer.numberOfBars[barNumber]=file.nextInt();
}
file.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(Equalizer.class.getName()).log(Level.SEVERE, null,
ex);
}
// frame.setUndecorated(true);
frame.setVisible(true); y=0;
for(i=0;i<5;i++) Equalizer.numberOfBarsModified[i]=-5;
for(i=0;i<17;i++,y++)
{
System.out.println("second for");
int j;
d1.repaint();
try {
Thread.sleep(5);
} catch (InterruptedException ex) {
Logger.getLogger(Equalizer.class.getName()).log(Level.SEVERE, nu
ll, ex);
}
for(j=0;j<5;j++) if(Equalizer.numberOfBarsModified[j]!=Equalizer.num
berOfBars[j]){ Equalizer.numberOfBarsModified[j]++; }
}
}
}
class Draw1 extends JPanel{

@Override
public void paintComponent(Graphics g)
{
System.out.println("paint");
g=(Graphics2D)g;
g.setColor(Color.BLUE);
g.fillRect(10,250-(15*(numberOfBarsModified[0]+5)), 50, 10);
g.setColor(Color.GREEN);
g.fillRect(10+102,250-(15*(numberOfBarsModified[1]+5)), 50, 10);
g.setColor(Color.yellow);
g.fillRect(10+(102*2),250-(15*(numberOfBarsModified[2]+5)), 50, 10);
g.setColor(Color.orange);
g.fillRect(10+(102*3),250-(15*(numberOfBarsModified[3]+5)), 50, 10);
g.setColor(Color.red);
g.fillRect(10+(102*4),250-(15*(numberOfBarsModified[4]+5)), 50, 10);
if(i==16) super.paintComponent(g);
//g.translate(55, 0);
}

}
}