Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Broken JPanel?

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Location
    State College
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Broken JPanel?

    Hello everyone, I'm fairly rusty with java and I've been ripping my hair out with this one. I'm working on a group project and I'm having trouble getting the code to work. This code is being adapted from a previous version to work in a template that can be used in the netbeans design view. It worked fine in the previous version but doesn't now. It compiles and runs almost without a hitch. The only problem is that the black JPanel (samplingPanel) should display a samplingGraph that traces audio that is recorded or loaded. However, I get an error in SamplingGraph on the line:

    int frames_per_pixel = audioBytes.length / format.getFrameSize()/w;

    I've looked into it and found that w and h are being set to 0, but I have no idea why. I've gone through every line of code and just can't find the problem.

    package audioencoding;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /*
     * EncoderInterface.java
     *
     * Created on Mar 6, 2011, 8:31:05 AM
     */
     
    import java.awt.BasicStroke;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.font.FontRenderContext;
    import java.awt.font.LineBreakMeasurer;
    import java.awt.font.TextAttribute;
    import java.awt.font.TextLayout;
    import java.awt.geom.Line2D;
    import javax.swing.JPanel;
    import javax.swing.JFileChooser;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.text.AttributedCharacterIterator;
    import java.text.AttributedString;
    import java.util.Vector;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.SourceDataLine;
    import javax.sound.sampled.TargetDataLine;
    import sun.audio.*;
     
     
    public class EncoderInterface extends javax.swing.JFrame {
     
        //AUDIO files for play
        InputStream in = null;
        AudioStream as = null;
     
        final int bufSize = 16384;
     
        Capture capture = new Capture();
        Playback playback = new Playback();
     
        AudioInputStream audioInputStream;
        SamplingGraph samplingGraph;
     
        String fileName = "untitled";
        String errStr;
        double duration, seconds;
        File file;
        Vector lines = new Vector();
     
        /** Creates new form EncoderInterface */
        public EncoderInterface() {
            initComponents();
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            RecordButton = new javax.swing.JButton();
            LoadButton = new javax.swing.JButton();
            EncodeButton = new javax.swing.JButton();
            DecodeButton = new javax.swing.JButton();
            OutputPlayButton = new javax.swing.JButton();
            InputPlayButton = new javax.swing.JButton();
            samplingPanel = new javax.swing.JPanel();
            OutputPanel = new javax.swing.JPanel();
            samplingPanel.add(samplingGraph = new SamplingGraph());
            jSeparator1 = new javax.swing.JSeparator();
            jSeparator2 = new javax.swing.JSeparator();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Audio Encoding");
     
            RecordButton.setText("Record");
            RecordButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    RecordButtonActionPerformed(evt);
                }
            });
     
            LoadButton.setText("Load");
            LoadButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    LoadButtonActionPerformed(evt);
                }
            });
     
            EncodeButton.setText("Encode");
            EncodeButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    EncodeButtonActionPerformed(evt);
                }
            });
     
            DecodeButton.setText("Decode");
            DecodeButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    DecodeButtonActionPerformed(evt);
                }
            });
     
            OutputPlayButton.setText("Play");
            OutputPlayButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    OutputPlayButtonActionPerformed(evt);
                }
            });
     
            InputPlayButton.setText("Play");
            InputPlayButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    InputPlayButtonActionPerformed(evt);
                }
            });
     
            samplingPanel.setBackground(new java.awt.Color(0, 0, 0));
            samplingPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
            samplingPanel.add(samplingGraph = new SamplingGraph());
     
            javax.swing.GroupLayout samplingPanelLayout = new javax.swing.GroupLayout(samplingPanel);
            samplingPanel.setLayout(samplingPanelLayout);
            samplingPanelLayout.setHorizontalGroup(
                samplingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 431, Short.MAX_VALUE)
            );
            samplingPanelLayout.setVerticalGroup(
                samplingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 97, Short.MAX_VALUE)
            );
     
            OutputPanel.setBackground(new java.awt.Color(255, 255, 255));
            OutputPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
     
            javax.swing.GroupLayout OutputPanelLayout = new javax.swing.GroupLayout(OutputPanel);
            OutputPanel.setLayout(OutputPanelLayout);
            OutputPanelLayout.setHorizontalGroup(
                OutputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 431, Short.MAX_VALUE)
            );
            OutputPanelLayout.setVerticalGroup(
                OutputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
     
            jSeparator1.setAlignmentX(0);
            jSeparator1.setAlignmentY(0);
     
            jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
            jSeparator2.setAlignmentX(0.0F);
            jSeparator2.setAlignmentY(0.0F);
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(33, 33, 33)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(DecodeButton)
                                .addComponent(EncodeButton)))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(32, 32, 32)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(LoadButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(RecordButton, javax.swing.GroupLayout.Alignment.TRAILING))))
                    .addGap(21, 21, 21)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(OutputPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(samplingPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(170, 170, 170)
                            .addComponent(InputPlayButton, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(172, 172, 172)
                            .addComponent(OutputPlayButton, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap())
                .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 574, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(16, 16, 16)
                                    .addComponent(samplingPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(36, 36, 36)
                                    .addComponent(RecordButton)
                                    .addGap(18, 18, 18)
                                    .addComponent(LoadButton)))
                            .addGap(18, 18, 18)
                            .addComponent(InputPlayButton)
                            .addGap(18, 18, 18)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(18, 18, 18)
                                    .addComponent(OutputPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(40, 40, 40)
                                    .addComponent(EncodeButton)
                                    .addGap(18, 18, 18)
                                    .addComponent(DecodeButton)))
                            .addGap(18, 18, 18)
                            .addComponent(OutputPlayButton))
                        .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 349, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap())
            );
     
            pack();
        }// </editor-fold>
     
        private void LoadButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
     
                if (LoadButton.getText().startsWith("Load")) {
                    try {
                        //File file = new File(System.getProperty("user.dir"));
                        JFileChooser fc = new JFileChooser(file);
                        fc.setFileFilter(new javax.swing.filechooser.FileFilter () {
                            public boolean accept(File f) {
                                if (f.isDirectory()) {
                                    return true;
                            }
                            String name = f.getName();
                            if (name.endsWith(".au") || name.endsWith(".wav") || name.endsWith(".aiff") || name.endsWith(".aif")) {
                                return true;
                            }
                            return false;
                        }
                            public String getDescription() {
                                return ".au, .wav, .aif";
                        }
                    });
     
                    if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                        createAudioInputStream(fc.getSelectedFile(), true);
                    }
     
                } catch (SecurityException ex) {
                    //JavaSound.showInfoDialog();
                    ex.printStackTrace();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }                                          
     
        private void InputPlayButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
     
               if (InputPlayButton.getText().startsWith("Play")) {
                    playback.start();
                    samplingGraph.start();
                    RecordButton.setEnabled(false);
                    OutputPlayButton.setEnabled(false);
                    LoadButton.setEnabled(false);
                    EncodeButton.setEnabled(false);
                    DecodeButton.setEnabled(false);
                    InputPlayButton.setText("Stop");
                } else {
                    playback.stop();
                    samplingGraph.stop();
                    RecordButton.setEnabled(true);
                    OutputPlayButton.setEnabled(true);
                    LoadButton.setEnabled(true);
                    EncodeButton.setEnabled(true);
                    DecodeButton.setEnabled(true);
                    InputPlayButton.setText("Play");
                }
        }                                               
     
        private void OutputPlayButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                 
            // TODO add your handling code here:
        }                                                
     
        private void RecordButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
                if (RecordButton.getText().startsWith("Record")) {
                    file = null;
                    capture.start();
                    fileName = "untitled";
                    samplingGraph.start();
                    LoadButton.setEnabled(false);
                    InputPlayButton.setEnabled(false);
                    OutputPlayButton.setEnabled(false);
                    EncodeButton.setEnabled(false);
                    DecodeButton.setEnabled(false);
                    RecordButton.setText("Stop");
                } else {
                    lines.removeAllElements();
                    capture.stop();
                    samplingGraph.stop();
                    LoadButton.setEnabled(true);
                    InputPlayButton.setEnabled(true);
                    OutputPlayButton.setEnabled(true);
                    EncodeButton.setEnabled(true);
                    DecodeButton.setEnabled(true);
                    RecordButton.setText("Record");
                }
        }                                            
     
        private void EncodeButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void DecodeButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        public void open() { }
     
     
        public void close() {
           if (playback.thread != null) {
                InputPlayButton.doClick(0);
            }
           if (capture.thread != null) {
                RecordButton.doClick(0);
            }
        }
     
        public void createAudioInputStream(File file, boolean updateComponents) {
            if (file != null && file.isFile()) {
                try {
                    this.file = file;
                    errStr = null;
                    audioInputStream = AudioSystem.getAudioInputStream(file);
                    InputPlayButton.setEnabled(true);
                    fileName = file.getName();
                    long milliseconds = (long)((audioInputStream.getFrameLength() * 1000) / audioInputStream.getFormat().getFrameRate());
                    duration = milliseconds / 1000.0;
                    if (updateComponents) {
                        samplingGraph.createWaveForm(null);
                    }
                } catch (Exception ex) {
                    reportStatus(ex.toString());
                }
            } else {
                reportStatus("Audio file required.");
            }
        }
     
     
        private void reportStatus(String msg) {
            if ((errStr = msg) != null) {
                System.out.println(errStr);
                samplingGraph.repaint();
            }
        }
     
        class Capture implements Runnable {
     
            TargetDataLine line;
            Thread thread;
     
            public void start() {
                errStr = null;
                thread = new Thread(this);
                thread.setName("Capture");
                thread.start();
            }
     
            public void stop() {
                thread = null;
            }
     
            private void shutDown(String message) {
                if ((errStr = message) != null && thread != null) {
                    thread = null;
                    samplingGraph.stop();
                    LoadButton.setEnabled(true);
                    InputPlayButton.setEnabled(true);
                    RecordButton.setText("Record");
                    System.err.println(errStr);
                    samplingGraph.repaint();
                }
            }
     
            public void run() {
     
                duration = 0;
                audioInputStream = null;
     
                // define the required attributes for our line,
                // and make sure a compatible line is supported.
     
                AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 44100, true);
                DataLine.Info info = new DataLine.Info(TargetDataLine.class,
                    format);
     
                if (!AudioSystem.isLineSupported(info)) {
                    shutDown("Line matching " + info + " not supported.");
                    return;
                }
     
                // get and open the target data line for capture.
     
                try {
                    line = (TargetDataLine) AudioSystem.getLine(info);
                    line.open(format, line.getBufferSize());
                } catch (LineUnavailableException ex) {
                    shutDown("Unable to open the line: " + ex);
                    return;
                } catch (SecurityException ex) {
                    shutDown(ex.toString());
                    return;
                } catch (Exception ex) {
                    shutDown(ex.toString());
                    return;
                }
     
                // play back the captured audio data
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                int frameSizeInBytes = format.getFrameSize();
                int bufferLengthInFrames = line.getBufferSize() / 8;
                int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
                byte[] data = new byte[bufferLengthInBytes];
                int numBytesRead;
     
                line.start();
     
                while (thread != null) {
                    if((numBytesRead = line.read(data, 0, bufferLengthInBytes)) == -1) {
                        break;
                    }
                    out.write(data, 0, numBytesRead);
                }
     
                // we reached the end of the stream.  stop and close the line.
                line.stop();
                line.close();
                line = null;
     
                // stop and close the output stream
                try {
                    out.flush();
                    out.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
     
                // load bytes into the audio input stream for playback
     
                byte audioBytes[] = out.toByteArray();
                ByteArrayInputStream bais = new ByteArrayInputStream(audioBytes);
                audioInputStream = new AudioInputStream(bais, format, audioBytes.length / frameSizeInBytes);
     
                long milliseconds = (long)((audioInputStream.getFrameLength() * 1000) / format.getFrameRate());
                duration = milliseconds / 1000.0;
     
                try {
                    audioInputStream.reset();
                } catch (Exception ex) {
                    ex.printStackTrace();
                    return;
                }
     
                samplingGraph.createWaveForm(audioBytes);
            }
        } // End class Capture
     
        public class Playback implements Runnable {
     
            SourceDataLine line;
            Thread thread;
     
            public void start() {
                errStr = null;
                thread = new Thread(this);
                thread.setName("Playback");
                thread.start();
            }
     
            public void stop() {
                thread = null;
            }
     
            private void shutDown(String message) {
                if ((errStr = message) != null) {
                    System.err.println(errStr);
                    samplingGraph.repaint();
                }
                if (thread != null) {
                    thread = null;
                    samplingGraph.stop();
                    RecordButton.setEnabled(true);
                    OutputPlayButton.setEnabled(true);
                    LoadButton.setEnabled(true);
                    EncodeButton.setEnabled(true);
                    DecodeButton.setEnabled(true);
                    InputPlayButton.setText("Play");
                }
            }
     
            public void run() {
     
                // reload the file if loaded by file
                if (file != null) {
                    createAudioInputStream(file, false);
                    audioInputStream.mark(9999999);
                }
     
                // make sure we have something to play
                if (audioInputStream == null) {
                    shutDown("No loaded audio to play back");
                    return;
                }
     
                // get an AudioInputStream of the desired format for playback
                AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 44100, true);
                AudioInputStream playbackInputStream = AudioSystem.getAudioInputStream(format, audioInputStream);
     
                if (playbackInputStream == null) {
                    shutDown("Unable to convert stream of format " + audioInputStream + " to format " + format);
                    return;
                }
     
                // define the required attributes for our line,
                // and make sure a compatible line is supported.
     
                DataLine.Info info = new DataLine.Info(SourceDataLine.class,
                    format);
                if (!AudioSystem.isLineSupported(info)) {
                    shutDown("Line matching " + info + " not supported.");
                    return;
                }
     
                // get and open the source data line for playback.
     
                try {
                    line = (SourceDataLine) AudioSystem.getLine(info);
                    line.open(format, bufSize);
                } catch (LineUnavailableException ex) {
                    shutDown("Unable to open the line: " + ex);
                    return;
                }
     
                // play back the captured audio data
     
                int frameSizeInBytes = format.getFrameSize();
                int bufferLengthInFrames = line.getBufferSize() / 8;
                int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
                byte[] data = new byte[bufferLengthInBytes];
                int numBytesRead = 0;
     
                // start the source data line
                line.start();
     
                while (thread != null) {
                    try {
                        if ((numBytesRead = playbackInputStream.read(data)) == -1) {
                            break;
                        }
                        int numBytesRemaining = numBytesRead;
                        while (numBytesRemaining > 0 ) {
                            numBytesRemaining -= line.write(data, 0, numBytesRemaining);
                        }
                    } catch (Exception e) {
                        shutDown("Error during playback: " + e);
                        break;
                    }
                }
                // we reached the end of the stream.  let the data play out, then
                // stop and close the line.
                if (thread != null) {
                    line.drain();
                }
                line.stop();
                line.close();
                line = null;
                shutDown(null);
            }
        } // End class Playback
     
        class SamplingGraph extends JPanel implements Runnable {
     
            private Thread thread;
            private Font font10 = new Font("serif", Font.PLAIN, 10);
            private Font font12 = new Font("serif", Font.PLAIN, 12);
            Color jfcBlue = new Color(204, 204, 255);
            Color pink = new Color(255, 175, 175);
     
     
            public SamplingGraph() {
                setBackground(new Color(20, 20, 20));
            }
     
     
            public void createWaveForm(byte[] audioBytes) {
     
                lines.removeAllElements();  // clear the old vector
     
                AudioFormat format = audioInputStream.getFormat();
                if (audioBytes == null) {
                    try {
                        audioBytes = new byte[
                            (int) (audioInputStream.getFrameLength()
                            * format.getFrameSize())];
                        audioInputStream.read(audioBytes);
                    } catch (Exception ex) {
                        reportStatus(ex.toString());
                        return;
                    }
                }
     
                Dimension d = getSize();
                int w = d.width;
                int h = d.height-15;
                int[] audioData = null;
                if (format.getSampleSizeInBits() == 16) {
                     int nlengthInSamples = audioBytes.length / 2;
                     audioData = new int[nlengthInSamples];
                     if (format.isBigEndian()) {
                        for (int i = 0; i < nlengthInSamples; i++) {
                             /* First byte is MSB (high order) */
                             int MSB = (int) audioBytes[2*i];
                             /* Second byte is LSB (low order) */
                             int LSB = (int) audioBytes[2*i+1];
                             audioData[i] = MSB << 8 | (255 & LSB);
                         }
                     } else {
                         for (int i = 0; i < nlengthInSamples; i++) {
                             /* First byte is LSB (low order) */
                             int LSB = (int) audioBytes[2*i];
                             /* Second byte is MSB (high order) */
                             int MSB = (int) audioBytes[2*i+1];
                             audioData[i] = MSB << 8 | (255 & LSB);
                         }
                     }
                 } else if (format.getSampleSizeInBits() == 8) {
                     int nlengthInSamples = audioBytes.length;
                     audioData = new int[nlengthInSamples];
                     if (format.getEncoding().toString().startsWith("PCM_SIGN")) {
                         for (int i = 0; i < audioBytes.length; i++) {
                             audioData[i] = audioBytes[i];
                         }
                     } else {
                         for (int i = 0; i < audioBytes.length; i++) {
                             audioData[i] = audioBytes[i] - 128;
                         }
                     }
                }
     
                int frames_per_pixel = audioBytes.length / format.getFrameSize()/w;
                byte my_byte = 0;
                double y_last = 0;
                int numChannels = format.getChannels();
                for (double x = 0; x < w && audioData != null; x++) {
                    int idx = (int) (frames_per_pixel * numChannels * x);
                    if (format.getSampleSizeInBits() == 8) {
                         my_byte = (byte) audioData[idx];
                    } else {
                         my_byte = (byte) (128 * audioData[idx] / 32768 );
                    }
                    double y_new = (double) (h * (128 - my_byte) / 256);
                    lines.add(new Line2D.Double(x, y_last, x, y_new));
                    y_last = y_new;
                }
     
                repaint();
            }
     
     
            public void paint(Graphics g) {
     
                Dimension d = getSize();
                int w = d.width;
                int h = d.height;
                int INFOPAD = 15;
     
                Graphics2D g2 = (Graphics2D) g;
                g2.setBackground(getBackground());
                g2.clearRect(0, 0, w, h);
                g2.setColor(Color.white);
                g2.fillRect(0, h-INFOPAD, w, INFOPAD);
     
                if (errStr != null) {
                    g2.setColor(jfcBlue);
                    g2.setFont(new Font("serif", Font.BOLD, 18));
                    g2.drawString("ERROR", 5, 20);
                    AttributedString as = new AttributedString(errStr);
                    as.addAttribute(TextAttribute.FONT, font12, 0, errStr.length());
                    AttributedCharacterIterator aci = as.getIterator();
                    FontRenderContext frc = g2.getFontRenderContext();
                    LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
                    float x = 5, y = 25;
                    lbm.setPosition(0);
                    while (lbm.getPosition() < errStr.length()) {
                        TextLayout tl = lbm.nextLayout(w-x-5);
                        if (!tl.isLeftToRight()) {
                            x = w - tl.getAdvance();
                        }
                        tl.draw(g2, x, y += tl.getAscent());
                        y += tl.getDescent() + tl.getLeading();
                    }
                } else if (capture.thread != null) {
                    g2.setColor(Color.black);
                    g2.setFont(font12);
                    g2.drawString("Length: " + String.valueOf(seconds), 3, h-4);
                } else {
                    g2.setColor(Color.black);
                    g2.setFont(font12);
                    g2.drawString("File: " + fileName + "  Length: " + String.valueOf(duration) + "  Position: " + String.valueOf(seconds), 3, h-4);
     
                    if (audioInputStream != null) {
                        // .. render sampling graph ..
                        g2.setColor(jfcBlue);
                        for (int i = 1; i < lines.size(); i++) {
                            g2.draw((Line2D) lines.get(i));
                        }
     
                        // .. draw current position ..
                        if (seconds != 0) {
                            double loc = seconds/duration*w;
                            g2.setColor(pink);
                            g2.setStroke(new BasicStroke(3));
                            g2.draw(new Line2D.Double(loc, 0, loc, h-INFOPAD-2));
                        }
                    }
                }
            }
     
            public void start() {
                thread = new Thread(this);
                thread.setName("SamplingGraph");
                thread.start();
                seconds = 0;
            }
     
            public void stop() {
                if (thread != null) {
                    thread.interrupt();
                }
                thread = null;
            }
     
            public void run() {
                seconds = 0;
                while (thread != null) {
                    if ((playback.line != null) && (playback.line.isOpen()) ) {
     
                        long milliseconds = (long)(playback.line.getMicrosecondPosition() / 1000);
                        seconds =  milliseconds / 1000.0;
                    } else if ( (capture.line != null) && (capture.line.isActive()) ) {
     
                        long milliseconds = (long)(capture.line.getMicrosecondPosition() / 1000);
                        seconds =  milliseconds / 1000.0;
                    }
     
                    try { thread.sleep(100); } catch (Exception e) { break; }
     
                    repaint();
     
                    while ((capture.line != null && !capture.line.isActive()) ||
                           (playback.line != null && !playback.line.isOpen()))
                    {
                        try { thread.sleep(10); } catch (Exception e) { break; }
                    }
                }
                seconds = 0;
                repaint();
            }
        } // End class SamplingGraph
     
        public static void main(String s[]) {
            EncoderInterface capturePlayback = new EncoderInterface();
            capturePlayback.open();
            capturePlayback.setVisible(true);
        }
     
        /**
        * @param args the command line arguments
        */
     
     
     
        // Variables declaration - do not modify
        private javax.swing.JButton DecodeButton;
        private javax.swing.JButton EncodeButton;
        private javax.swing.JButton InputPlayButton;
        private javax.swing.JButton LoadButton;
        public javax.swing.JPanel OutputPanel;
        private javax.swing.JButton OutputPlayButton;
        private javax.swing.JButton RecordButton;
        private javax.swing.JSeparator jSeparator1;
        private javax.swing.JSeparator jSeparator2;
        public javax.swing.JPanel samplingPanel;
        // End of variables declaration
     
    }

    *Playback, Capture, SamplingGraph, createAudioInputStream, reportStatus, and all of the button action handlers have not changed since the previous version.

    Thanks for any help!


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Broken JPanel?

    Ahhh. So you expect someone here to wade through those eleventy gazillion lines of code for you. Don't hold your breath.

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Location
    State College
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Broken JPanel?

    Quote Originally Posted by Junky View Post
    Ahhh. So you expect someone here to wade through those eleventy gazillion lines of code for you. Don't hold your breath.
    Not really, most of the functions can be ignored since I already know that they aren't the problem. The only thing that's really been altered or added is initComponents and main.

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Broken JPanel?

    Then your problem must be in there. Start debugging.

  5. #5
    Junior Member
    Join Date
    Mar 2011
    Location
    State College
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Broken JPanel?

    I have... I've been debugging all week. That's why I'm asking for help.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Broken JPanel?

    What Junky is trying to tell you is that you'd be much more likely to receive help if you posted an SSCCE that demonstrated the problem. You said it yourself- most of the functions can be ignored, and you know they aren't the problem. So why include them in your example at all?

    There are hundreds of posts here, and we simply don't have time to spend an hour wading through code, when in the same time, we could help 10 different people who posted SSCCEs and provided more information. And half the time, you'll figure the problem out yourself in the process of boiling your code down to the bare essentials.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Mar 2011
    Location
    State College
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Broken JPanel?

    Unfortunately, if it still needs to be runnable and able to produce the samplingGraph, this is the best I can do in terms of trimming it down. The record button has to be able to be pushed for a start and stop for the horizontal line to show up on the JPanel.

    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.font.FontRenderContext;
    import java.awt.font.LineBreakMeasurer;
    import java.awt.font.TextAttribute;
    import java.awt.font.TextLayout;
    import java.awt.geom.Line2D;
    import javax.swing.JPanel;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.text.AttributedCharacterIterator;
    import java.text.AttributedString;
    import java.util.Vector;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.TargetDataLine;
    import sun.audio.*;
     
     
    public class EncoderInterface extends javax.swing.JFrame {
     
        //AUDIO files for play
        InputStream in = null;
        AudioStream as = null;
     
        final int bufSize = 16384;
     
        Capture capture = new Capture();
     
        AudioInputStream audioInputStream;
        SamplingGraph samplingGraph;
     
        String fileName = "untitled";
        String errStr;
        double duration, seconds;
        File file;
        Vector lines = new Vector();
     
        /** Creates new form EncoderInterface */
        public EncoderInterface() {
            initComponents();
        }
     
        private void initComponents() {
     
            RecordButton = new javax.swing.JButton();
            samplingPanel = new javax.swing.JPanel();
            samplingPanel.add(samplingGraph = new SamplingGraph());
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Audio Encoding");
     
            RecordButton.setText("Record");
            RecordButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    RecordButtonActionPerformed(evt);
                }
            });
     
            samplingPanel.setBackground(new java.awt.Color(0, 0, 0));
            samplingPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
            samplingPanel.add(samplingGraph = new SamplingGraph());
     
            javax.swing.GroupLayout samplingPanelLayout = new javax.swing.GroupLayout(samplingPanel);
            samplingPanel.setLayout(samplingPanelLayout);
            samplingPanelLayout.setHorizontalGroup(
                samplingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 431, Short.MAX_VALUE)
            );
            samplingPanelLayout.setVerticalGroup(
                samplingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 97, Short.MAX_VALUE)
            );
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(32, 32, 32)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(RecordButton, javax.swing.GroupLayout.Alignment.TRAILING))))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(samplingPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(16, 16, 16)
                                    .addComponent(samplingPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(36, 36, 36)
                                    .addComponent(RecordButton)))))
                    .addContainerGap())
            );
     
            pack();
        }// </editor-fold>
     
        private void RecordButtonActionPerformed(java.awt.event.ActionEvent evt) {
                if (RecordButton.getText().startsWith("Record")) {
                    file = null;
                    capture.start();
                    fileName = "untitled";
                    samplingGraph.start();
                    RecordButton.setText("Stop");
                } else {
                    lines.removeAllElements();
                    capture.stop();
                    samplingGraph.stop();
                    RecordButton.setText("Record");
                }
        }
     
        public void open() { }
     
     
        public void close() {
           if (capture.thread != null) {
                RecordButton.doClick(0);
            }
        }
     
        public void createAudioInputStream(File file, boolean updateComponents) {
            if (file != null && file.isFile()) {
                try {
                    this.file = file;
                    errStr = null;
                    audioInputStream = AudioSystem.getAudioInputStream(file);
                    fileName = file.getName();
                    long milliseconds = (long)((audioInputStream.getFrameLength() * 1000) / audioInputStream.getFormat().getFrameRate());
                    duration = milliseconds / 1000.0;
                    if (updateComponents) {
                        samplingGraph.createWaveForm(null);
                    }
                } catch (Exception ex) {
                    reportStatus(ex.toString());
                }
            } else {
                reportStatus("Audio file required.");
            }
        }
     
     
        private void reportStatus(String msg) {
            if ((errStr = msg) != null) {
                System.out.println(errStr);
                samplingGraph.repaint();
            }
        }
     
        class Capture implements Runnable {
     
            TargetDataLine line;
            Thread thread;
     
            public void start() {
                errStr = null;
                thread = new Thread(this);
                thread.setName("Capture");
                thread.start();
            }
     
            public void stop() {
                thread = null;
            }
     
            private void shutDown(String message) {
                if ((errStr = message) != null && thread != null) {
                    thread = null;
                    samplingGraph.stop();
                    RecordButton.setText("Record");
                    System.err.println(errStr);
                    samplingGraph.repaint();
                }
            }
     
            public void run() {
     
                duration = 0;
                audioInputStream = null;
     
                // define the required attributes for our line,
                // and make sure a compatible line is supported.
     
                AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 44100, true);
                DataLine.Info info = new DataLine.Info(TargetDataLine.class,
                    format);
     
                if (!AudioSystem.isLineSupported(info)) {
                    shutDown("Line matching " + info + " not supported.");
                    return;
                }
     
                // get and open the target data line for capture.
     
                try {
                    line = (TargetDataLine) AudioSystem.getLine(info);
                    line.open(format, line.getBufferSize());
                } catch (LineUnavailableException ex) {
                    shutDown("Unable to open the line: " + ex);
                    return;
                } catch (SecurityException ex) {
                    shutDown(ex.toString());
                    return;
                } catch (Exception ex) {
                    shutDown(ex.toString());
                    return;
                }
     
                // play back the captured audio data
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                int frameSizeInBytes = format.getFrameSize();
                int bufferLengthInFrames = line.getBufferSize() / 8;
                int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
                byte[] data = new byte[bufferLengthInBytes];
                int numBytesRead;
     
                line.start();
     
                while (thread != null) {
                    if((numBytesRead = line.read(data, 0, bufferLengthInBytes)) == -1) {
                        break;
                    }
                    out.write(data, 0, numBytesRead);
                }
     
                // we reached the end of the stream.  stop and close the line.
                line.stop();
                line.close();
                line = null;
     
                // stop and close the output stream
                try {
                    out.flush();
                    out.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
     
                // load bytes into the audio input stream for playback
     
                byte audioBytes[] = out.toByteArray();
                ByteArrayInputStream bais = new ByteArrayInputStream(audioBytes);
                audioInputStream = new AudioInputStream(bais, format, audioBytes.length / frameSizeInBytes);
     
                long milliseconds = (long)((audioInputStream.getFrameLength() * 1000) / format.getFrameRate());
                duration = milliseconds / 1000.0;
     
                try {
                    audioInputStream.reset();
                } catch (Exception ex) {
                    ex.printStackTrace();
                    return;
                }
     
                samplingGraph.createWaveForm(audioBytes);
            }
        } // End class Capture
     
        class SamplingGraph extends JPanel implements Runnable {
     
            private Thread thread;
            private Font font10 = new Font("serif", Font.PLAIN, 10);
            private Font font12 = new Font("serif", Font.PLAIN, 12);
            Color jfcBlue = new Color(204, 204, 255);
            Color pink = new Color(255, 175, 175);
     
     
            public SamplingGraph() {
                setBackground(new Color(20, 20, 20));
            }
     
     
            public void createWaveForm(byte[] audioBytes) {
     
                lines.removeAllElements();  // clear the old vector
     
                AudioFormat format = audioInputStream.getFormat();
                if (audioBytes == null) {
                    try {
                        audioBytes = new byte[
                            (int) (audioInputStream.getFrameLength()
                            * format.getFrameSize())];
                        audioInputStream.read(audioBytes);
                    } catch (Exception ex) {
                        reportStatus(ex.toString());
                        return;
                    }
                }
     
                Dimension d = getSize();
                int w = d.width;
                int h = d.height-15;
                int[] audioData = null;
                if (format.getSampleSizeInBits() == 16) {
                     int nlengthInSamples = audioBytes.length / 2;
                     audioData = new int[nlengthInSamples];
                     if (format.isBigEndian()) {
                        for (int i = 0; i < nlengthInSamples; i++) {
                             /* First byte is MSB (high order) */
                             int MSB = (int) audioBytes[2*i];
                             /* Second byte is LSB (low order) */
                             int LSB = (int) audioBytes[2*i+1];
                             audioData[i] = MSB << 8 | (255 & LSB);
                         }
                     } else {
                         for (int i = 0; i < nlengthInSamples; i++) {
                             /* First byte is LSB (low order) */
                             int LSB = (int) audioBytes[2*i];
                             /* Second byte is MSB (high order) */
                             int MSB = (int) audioBytes[2*i+1];
                             audioData[i] = MSB << 8 | (255 & LSB);
                         }
                     }
                 } else if (format.getSampleSizeInBits() == 8) {
                     int nlengthInSamples = audioBytes.length;
                     audioData = new int[nlengthInSamples];
                     if (format.getEncoding().toString().startsWith("PCM_SIGN")) {
                         for (int i = 0; i < audioBytes.length; i++) {
                             audioData[i] = audioBytes[i];
                         }
                     } else {
                         for (int i = 0; i < audioBytes.length; i++) {
                             audioData[i] = audioBytes[i] - 128;
                         }
                     }
                }
     
                int frames_per_pixel = audioBytes.length / format.getFrameSize()/w;
                byte my_byte = 0;
                double y_last = 0;
                int numChannels = format.getChannels();
                for (double x = 0; x < w && audioData != null; x++) {
                    int idx = (int) (frames_per_pixel * numChannels * x);
                    if (format.getSampleSizeInBits() == 8) {
                         my_byte = (byte) audioData[idx];
                    } else {
                         my_byte = (byte) (128 * audioData[idx] / 32768 );
                    }
                    double y_new = (double) (h * (128 - my_byte) / 256);
                    lines.add(new Line2D.Double(x, y_last, x, y_new));
                    y_last = y_new;
                }
     
                repaint();
            }
     
     
            public void paint(Graphics g) {
     
                Dimension d = getSize();
                int w = d.width;
                int h = d.height;
                int INFOPAD = 15;
     
                Graphics2D g2 = (Graphics2D) g;
                g2.setBackground(getBackground());
                g2.clearRect(0, 0, w, h);
                g2.setColor(Color.white);
                g2.fillRect(0, h-INFOPAD, w, INFOPAD);
     
                if (errStr != null) {
                    g2.setColor(jfcBlue);
                    g2.setFont(new Font("serif", Font.BOLD, 18));
                    g2.drawString("ERROR", 5, 20);
                    AttributedString as = new AttributedString(errStr);
                    as.addAttribute(TextAttribute.FONT, font12, 0, errStr.length());
                    AttributedCharacterIterator aci = as.getIterator();
                    FontRenderContext frc = g2.getFontRenderContext();
                    LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
                    float x = 5, y = 25;
                    lbm.setPosition(0);
                    while (lbm.getPosition() < errStr.length()) {
                        TextLayout tl = lbm.nextLayout(w-x-5);
                        if (!tl.isLeftToRight()) {
                            x = w - tl.getAdvance();
                        }
                        tl.draw(g2, x, y += tl.getAscent());
                        y += tl.getDescent() + tl.getLeading();
                    }
                } else if (capture.thread != null) {
                    g2.setColor(Color.black);
                    g2.setFont(font12);
                    g2.drawString("Length: " + String.valueOf(seconds), 3, h-4);
                } else {
                    g2.setColor(Color.black);
                    g2.setFont(font12);
                    g2.drawString("File: " + fileName + "  Length: " + String.valueOf(duration) + "  Position: " + String.valueOf(seconds), 3, h-4);
     
                    if (audioInputStream != null) {
                        // .. render sampling graph ..
                        g2.setColor(jfcBlue);
                        for (int i = 1; i < lines.size(); i++) {
                            g2.draw((Line2D) lines.get(i));
                        }
     
                        // .. draw current position ..
                        if (seconds != 0) {
                            double loc = seconds/duration*w;
                            g2.setColor(pink);
                            g2.setStroke(new BasicStroke(3));
                            g2.draw(new Line2D.Double(loc, 0, loc, h-INFOPAD-2));
                        }
                    }
                }
            }
     
            public void start() {
                thread = new Thread(this);
                thread.setName("SamplingGraph");
                thread.start();
                seconds = 0;
            }
     
            public void stop() {
                if (thread != null) {
                    thread.interrupt();
                }
                thread = null;
            }
     
            public void run() {
                seconds = 0;
                while (thread != null) {
                     if ( (capture.line != null) && (capture.line.isActive()) ) {
     
                        long milliseconds = (long)(capture.line.getMicrosecondPosition() / 1000);
                        seconds =  milliseconds / 1000.0;
                    }
     
                    try { thread.sleep(100); } catch (Exception e) { break; }
     
                    repaint();
     
                    while ((capture.line != null && !capture.line.isActive()))
                    {
                        try { thread.sleep(10); } catch (Exception e) { break; }
                    }
                }
                seconds = 0;
                repaint();
            }
        } // End class SamplingGraph
     
        public static void main(String s[]) {
            EncoderInterface capturePlayback = new EncoderInterface();
            capturePlayback.open();
            capturePlayback.setVisible(true);
        }
     
        private javax.swing.JButton RecordButton;
        public javax.swing.JPanel samplingPanel;
    }

    If all you want to see are declarations, I can chop that up tonight.

Similar Threads

  1. How to use the same variable in various JPanel?
    By danielpereira in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 19th, 2010, 12:08 PM
  2. JButton on JPanel
    By JavaLearner in forum AWT / Java Swing
    Replies: 4
    Last Post: March 26th, 2010, 07:46 AM
  3. JPanel in JFrame
    By maele in forum AWT / Java Swing
    Replies: 2
    Last Post: March 8th, 2010, 04:12 AM
  4. How to copy image from one jpanel to another jpanel
    By ramanavarayuri1986 in forum AWT / Java Swing
    Replies: 0
    Last Post: February 15th, 2010, 02:36 AM
  5. Creating and displaying a JPanel inside another JPanel
    By JayDuck in forum AWT / Java Swing
    Replies: 1
    Last Post: April 7th, 2009, 08:02 AM