import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Graphics;
/**
Simple demonstration of a JFrame for graphing a waveform.
*/
public class MusicGraph extends JFrame {
    private static final int WIDTH = 500;
    private static final int HEIGHT = 500;
    private Sound sound2;

    public MusicGraph() {
    	super("Sound Graph");
        this.setSize(WIDTH, HEIGHT);
    }

    public MusicGraph(Sound s2) {
    	super("Sound Graph");
    	sound2 = s2;
        this.setSize(WIDTH, HEIGHT);
    }

    public void paint(Graphics canvas) {
        canvas.setColor(Color.RED);
        canvas.fillRect(0, 0, 500, 500); // fill the whole canvas with red
        canvas.setColor(Color.BLACK);
        canvas.drawLine(0, 250, 500, 250); // draw the horizontal axis
        canvas.drawString ("Waveform", 150, 120);
        int x1 = 250;
        int y1 = 400; //a default value
        try {
        	y1 = 250 - sound2.getSampleValueAt(50);
        }
        catch(Exception e) {
        	System.out.println(e.getMessage());
        }
        canvas.fillOval(x1, y1, 8, 8);
    }

    /*
    Creates and displays a window of the class MusicGraph
    */
    public static void main (String [] args) {
        MusicGraph gui = new MusicGraph();
        gui.setVisible(true);
    }
}

