The objective is to draw a couple hundred thousand vertical lines to a window, for which reason I need a scroll bar, zooming out is not an option as the space separating each individual line is not even a pixel. I have taken the approach of using paint methods in a class and adding both the class and JScrollPane to a JFrame. Didn't work out which is why I took the approach of using the NetBeans JFrame Form. Basically, how do I implement my graphics method into the panel that has the scroll bar? The problem I'm having is that my values are being printer just fine, but the no window appears at all. If any additional information is required, let me know. Thanks.
public class PedroGUI extends javax.swing.JFrame {
public PedroGUI() {
initComponents();
draw();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
scroll = new javax.swing.JScrollPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
scroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(scroll, javax.swing.GroupLayout.PREFERRED_SIZE, 429, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(123, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(scroll, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(86, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
public void draw() {
Graphics g = scroll.getGraphics();
g.setColor(Color.red);
int bytes, samples, frequency;
try {
FileInputStream fis = new FileInputStream("./pepe.wav");
BufferedInputStream bis = new BufferedInputStream(fis);
byte[] data = new byte[128];
bis.skip(44);
samples = 0;
while ((bytes = bis.read(data)) > 0) {
for (int i = 0; i < bytes; i++) {
frequency = data[i] & 0xFF;
System.out.println(samples + " " + frequency);
g.drawLine(samples, frequency + 300, samples, -frequency + 300);
samples++;
}
}
bis.read(data);
bis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
PedroGUI a = new PedroGUI();
a.draw();
}
});
}
private javax.swing.JScrollPane scroll;
}