Sorry the question is so specific, didn't want to bait anyone who was browsing around into a vague topic. This is a music transcription app. I am trying to plot a frequency graph on a window after reading the information from a .wav file. My main issue is getting a scrollbar to appear, which that worked when paintComponent dealt with any other graphics. I believe the reason is because I have a BufferedInputStream that will not allow the build to end, even though I am asking that it .close().
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (mapHistory != null) {
Graphics g2d = (Graphics2D)g.create();
g2d.setColor(Color.red);
int samples, frequency, bytes;
byte[] data;
try {
FileInputStream fis = new FileInputStream("./pepe.wav");
BufferedInputStream bis = new BufferedInputStream(fis);
data = new byte[128];
bis.skip(44);
samples = 0;
while ((bytes = bis.read(data)) > 0) {
for (int i = 0; i < bytes/1000; i++) {
frequency = data[i] & 0xFF;
samples++;
System.out.println(samples + " " + frequency);
g2d.drawLine(samples+15, frequency + 120, samples+15, -frequency + 120);
}
}
bis.read(data);
bis.close();
} catch (Exception e) {
e.printStackTrace();
}
g2d.dispose();
}
}
I'm not including any other code at the moment as I am confident that it all works (as it did with a different graphic). This graphic is slightly more complicated (the samples bit exceeds 90 million) as even though I am cutting the information by a factor of 1000 and very kindly asking that it please STOP AND CLOSE the printing of the information repeats itself once my cursor touches the window. The build just never stops, any ideas? Let me know if I wasn't specific enough or need to include more of my project, although I believe only here is where the problem is. Thanks!