document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import javax.swing.JFileChooser;
  2. import javax.swing.JFrame;
  3. import javax.swing.JButton;
  4. import javax.swing.filechooser.FileFilter;
  5. import javax.swing.JOptionPane;
  6. import javax.swing.JTextArea;
  7. import javax.swing.JPanel;
  8. import javax.swing.SwingConstants;
  9. import javax.swing.SwingUtilities;
  10.  
  11. import java.awt.*;
  12.  
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ActionEvent;
  15.  
  16. import java.io.File;
  17. import javax.swing.JLabel;
  18.  
  19. import javazoom.jl.converter.Converter;
  20.  
  21. public class MainClass extends JFrame implements ActionListener
  22. {
  23.     JButton mainButton=new JButton ("Click Here To Select MP3 Files To Convert");
  24.     JTextArea myLabel=new JTextArea("\\n\\tAll converted file has name like original \\n\\tfile with added .wav at the end and located in the same \\n\\tdirectory with original mp3 file."
  25.             + "\\n\\n\\tYou can convert multiple files in a time.");
  26.     JLabel informPanel=new JLabel("STATUS : No File To Convert",SwingConstants.CENTER);
  27.     JPanel testingPanel=new JPanel();
  28.     JFileChooser jfc;
  29.  
  30.     SwingWorker worker;
  31.  
  32.     File selectedFile;
  33.  
  34.     public MainClass()
  35.     {
  36.         super("Free Java MP3 To Wav Converter");
  37.         setLayout(new BorderLayout());
  38.  
  39.         mainButton.addActionListener(this);
  40.         myLabel.setEditable(false);
  41.         myLabel.setSize(300, 400);
  42.         testingPanel.add(informPanel);
  43.         add(testingPanel,BorderLayout.SOUTH);
  44.         add(myLabel,BorderLayout.CENTER);
  45.         add(mainButton,BorderLayout.NORTH);
  46.  
  47.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  48.         setResizable(false);
  49.         setSize(500,200);
  50.         setLocationRelativeTo(null);
  51.         setVisible(true);
  52.     }
  53.  
  54.     void updateJlabel(final String jlabelText)
  55.     {
  56.         Runnable doSetProgressBarValue = new Runnable() {
  57.             public void run() {
  58.                 informPanel.setText(jlabelText);
  59.             }
  60.         };
  61.         SwingUtilities.invokeLater(doSetProgressBarValue);
  62.     }
  63.  
  64.     public void actionPerformed(ActionEvent e)
  65.     {
  66.         if(e.getSource()==mainButton)
  67.         {
  68.             mainButton.setEnabled(false);
  69.             jfc=new JFileChooser();
  70.             jfc.setMultiSelectionEnabled(true);
  71.             jfc.setFileFilter(new TypeOfFile());
  72.             jfc.setDialogTitle("Select File To Convert");
  73.             int a=jfc.showDialog(this, "Convert");
  74.             if(a==JFileChooser.APPROVE_OPTION)
  75.             {
  76.                 worker=new SwingWorker()
  77.                 {
  78.                     public Object construct()
  79.                     {
  80.                         return doWork();
  81.                     }
  82.                     public void finished()
  83.                     {
  84.                         mainButton.setEnabled(true);
  85.                         updateJlabel("STATUS : No File To Convert");
  86.                         //JOptionPane.showMessageDialog(null, "", "ERROR", JOptionPane.ERROR_MESSAGE);
  87.                     }
  88.                 };
  89.                 worker.start();
  90.             }
  91.             else
  92.             {
  93.                 mainButton.setEnabled(true);
  94.             }
  95.         }
  96.     }
  97.  
  98.     Object doWork()
  99.     {
  100.         File [] groupOfFiles=jfc.getSelectedFiles();
  101.         int numberOfFiles=groupOfFiles.length;
  102.         for(int i=0;i<numberOfFiles;i++)
  103.         {
  104.             mainButton.enable(false);
  105.             selectedFile=groupOfFiles[i];
  106.             if(selectedFile.getName().toLowerCase().endsWith(".mp3"))
  107.             {
  108.                 try
  109.                 {
  110.                     updateJlabel("Please Wait : "+selectedFile.getName()+" still in converting...");
  111.                     Converter myConverter = new Converter();
  112.                     myConverter.convert(selectedFile.getPath(), selectedFile.getPath()+".wav");
  113.                 }
  114.                 catch(Exception error)
  115.                 {
  116.                     //updateJlabel("Converting Process Fail For : "+selectedFile.getName());
  117.                     JOptionPane.showMessageDialog(null, "Converting Process Fail", "ERROR", JOptionPane.ERROR_MESSAGE);
  118.                 }
  119.             }
  120.             else
  121.             {
  122.                 //updateJlabel(selectedFile.getName()+" not a MP3 File");
  123.                 JOptionPane.showMessageDialog(null, selectedFile.getName()+" not a MP3 File", "ERROR", JOptionPane.ERROR_MESSAGE);
  124.             }
  125.         }
  126.         return new Object();
  127.     }
  128.  
  129.     //Class TypeOfFile
  130.     class TypeOfFile extends FileFilter
  131.     {
  132.         //Type of file that should be display in JFileChooser will be set here
  133.         //We choose to display only directory and mp3 file
  134.         public boolean accept(File f)
  135.         {
  136.             return f.getName().toLowerCase().endsWith(".mp3")||f.isDirectory();
  137.         }
  138.  
  139.         //Set description for the type of file that should be display
  140.         public String getDescription()
  141.         {
  142.             return ".mp3 files";
  143.         }
  144.     }
  145.  
  146.     public static void main(String[]args)
  147.     {
  148.         MainClass myObject=new MainClass();
  149.     }
  150. }
  151.  
  152. //I will put this complete source codes in my blog
');