All pastes #13487 Raw Edit

Mine

public java v1 · immutable
#13487 ·published 2005-06-06 05:33 UTC
rendered paste body
package juke.mp3.problems;import javax.sound.sampled.*;import javax.swing.*;import javax.swing.filechooser.FileFilter;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;public class Ap_Gui extends JFrame {        Ap_Interface player;    protected JFileChooser chooser;    protected JPanel controlPanel, controlSubPanel;    protected JButton stopBtn, pauseBtn,openBtn, playBtn, resumeBtn;    protected JLabel statusLabel;    protected JScrollPane waveScrollPane;    protected JLabel fileLabel;    private Container container;    private BorderLayout layout;    public File inFileReference;    public String setMode;    AudioPlayer aP; ///////////////////////////////        public Ap_Gui() {        super("Ap_Gui via jsresources, ibm and r.baldwin");        layoutComponents();        disableTransportControls();        aP = new AudioPlayer();                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();        int w = 385;        int h = 85;        setLocation(screenSize.width/2 - w/2, screenSize.height/2 - h/2);        setSize(w, h);        setVisible(true);        setDefaultCloseOperation(                        EXIT_ON_CLOSE);    }public static void main(String[] args)	{        Ap_Gui apd = new Ap_Gui();                  	}//////////////////////////////////////////////////////////////Gui Crap    /**     * init and add most of the components     */    protected void layoutComponents() {        container = getContentPane();        layout = new BorderLayout();                controlSubPanel = new JPanel();        controlSubPanel.setLayout(new FlowLayout());        openBtn = new JButton("Open");        openBtn.addActionListener(                new ActionListener() {                    public void actionPerformed(ActionEvent e) {                      openFile();                    }                }        );                        playBtn = new JButton("Play");        playBtn.addActionListener(                new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        play();///// ??? problem area                    }                }        );        pauseBtn = new JButton("Pause");        pauseBtn.addActionListener(                new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        pause();///// ??? problem area                    }                }        );        resumeBtn = new JButton("Resume");        resumeBtn.addActionListener(                new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        resume();///// ??? problem area                    }                }        );        stopBtn = new JButton("stop");        stopBtn.addActionListener(                new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        stop(); //!?!?! problem area                    }                }        );                statusLabel = new JLabel("haha");                controlSubPanel.add(playBtn);        controlSubPanel.add(pauseBtn);        controlSubPanel.add(stopBtn);        controlSubPanel.add(openBtn);        controlSubPanel.add(resumeBtn);        controlSubPanel.add(statusLabel);        container.add(controlSubPanel);    }    public void enableTransportControls() {        playBtn.setEnabled(true);        pauseBtn.setEnabled(true);        stopBtn.setEnabled(true);    }    public void disableTransportControls() {        playBtn.setEnabled(false);        pauseBtn.setEnabled(false);        stopBtn.setEnabled(false);    }        public File openFile() {        chooser = new JFileChooser();        chooser.setFileSelectionMode( JFileChooser.FILES_ONLY);                int result = chooser.showOpenDialog(this);                if(result == JFileChooser.APPROVE_OPTION) {        JOptionPane.showMessageDialog( null,                    "You pressed selected OKAY, the name is: " + chooser.getSelectedFile().getName() ); }                                        if (result == JFileChooser.CANCEL_OPTION) {            //return;        }                File file = chooser.getSelectedFile() ;        //inFileReference = file;        enableTransportControls();        inFileReference = file; //to above JfileChooser file, did this so it can        //be used in the "control()" method        return file;    }//////////////////////////////////////////////////////////////Gui Crap            public void play()    {        setMode = "Play";        control();    }        protected void pause() {        ///// ??? problem area        setMode = "Pause";        control();    }        protected void resume() {        ///// ??? problem area        setMode = "Resume";        control();    }    protected void stop() {        ///// ??? problem area        setMode = "Stop";        control();      }        public void control()    {        System.out.println("Current mode is: " + setMode);        System.out.println("Did the file reference get passed? : " + inFileReference);        ///////////////////////////////////////////////////////////                if ( setMode == "Play" )            {                statusLabel.setText("Initializing Line/setting datasource, and playing via start() ");                System.out.println("If was executed, mode is: " + setMode);                       try {                        	try			{				                                aP.loadAudioClipLess(inFileReference);                                aP.initLine();			}			catch (LineUnavailableException e)			{				//dump in case of exception, then exit app				e.printStackTrace();				System.exit(1);			}                        catch (UnsupportedAudioFileException e)			{				e.printStackTrace();				System.exit(1);			}			catch (IllegalArgumentException e)			{				e.printStackTrace();				System.exit(1);			}			            aP.startPlayback();                    enableTransportControls();        } catch (Exception ex) {            JOptionPane.showMessageDialog(this, "An error has ocurred while loading the selected file: " + ex, "Error", JOptionPane.ERROR_MESSAGE);            ex.printStackTrace();        }        repaint();            }// end the if        else if ( setMode == "Stop" )            {                statusLabel.setText("Stopped / Line Flushed");                System.out.println("If was executed, mode is: " + setMode);aP.stopPlayback();repaint();            }                else if ( setMode == "Pause" )            {                statusLabel.setText("Paused / regular stop() ");                System.out.println("If was executed, mode is: " + setMode);aP.pausePlayback();repaint();            }                else if ( setMode == "Resume" )            {                statusLabel.setText("Resuming via start() ");                System.out.println("If was executed, mode is: " + setMode);aP.resumePlayback();repaint();            }                                                        ///////////////////////////////////////////////////////////    }    /////End Ap_Gui}/////End Ap_Gui