thomasfelix

PBO EAS

Jan 11th, 2021
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 37.22 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package jobme.pk;
  7.  
  8. import jaco.mp3.player.MP3Player;
  9. import java.awt.Dimension;
  10. import java.awt.Font;
  11. import java.io.File;
  12. import java.util.List;
  13. import java.util.ArrayList;
  14. import java.nio.file.Paths;
  15. import javax.sound.sampled.AudioSystem;
  16. import javax.sound.sampled.Clip;
  17. import javax.sound.sampled.FloatControl;
  18. import javax.sound.sampled.Line;
  19. import javax.sound.sampled.LineUnavailableException;
  20. import javax.sound.sampled.Mixer;
  21. import javax.swing.ImageIcon;
  22. import javax.swing.JFileChooser;
  23. import javax.swing.JOptionPane;
  24.  
  25. /**
  26.  *
  27.  * @author Majey
  28.  */
  29. public class PlayerFrame extends javax.swing.JFrame {
  30.  
  31.     /**
  32.      * Creates new form PlayerFrame
  33.      */
  34.    
  35.     // Define MP3Player Class From JACO MP3Player Lib
  36.     MP3Player player;
  37.     // Define File For Song
  38.     File songFile;
  39.     // Define Current Directory Like If We Use JFileChooser then where it statys.
  40.     String currentDirectory = "home.user"; // I am using home.user this will call file chooser in user documents.
  41.     // Here I define currentPath of the running app class
  42.     String currentPath;
  43.     // This String Will Be For Image Name or Path
  44.     String imagePath;
  45.     // We need to set app title as string
  46.     String appName = "Final Project PBO";
  47.    
  48.     ArrayList<String> myPlayList = new ArrayList<String> ();
  49.    
  50.     // Now Check If Repeat, Play, and Volume Full Button is Enabled or not
  51.     boolean repeat = false;
  52.     boolean play = false;
  53.     boolean fullvolume = false;
  54.    
  55.     int flag = 0;
  56.     // Here I am making a boolean for windowCollapsed
  57.     boolean windowCollapsed = false;
  58.    
  59.     // Here I need to define mouse x and y for to get mouse position on screen.
  60.     int xMouse, yMouse;
  61.    
  62.     public PlayerFrame() {
  63.         initComponents();
  64.         // Set App Title Here
  65.         appTitle.setText(appName);
  66.        
  67.         // Here I am going to set a default song file. It's not necessary.
  68.         songFile = new File("E:\\New-Data-From-Sony\\Music-Downloads\\GamePlayMusic.mp3");
  69.        
  70.         // Now make a string to get file name
  71.         String fileName = songFile.getName();
  72.         // Here set our song name label with this name
  73.         songNameDisplay.setText(fileName);
  74.        
  75.         // Add our method to player variable
  76.         player = mp3Player();
  77.         // Now add song to player as playlist.
  78.         player.addToPlayList(songFile);
  79.        
  80.         // Here get current path and images path in strings
  81.         currentPath = Paths.get(".").toAbsolutePath().normalize().toString();
  82.         imagePath = "\\src\\jobme\\pk\\images_new";
  83.     }
  84.  
  85.     /**
  86.      * This method is called from within the constructor to initialize the form.
  87.      * WARNING: Do NOT modify this code. The content of this method is always
  88.      * regenerated by the Form Editor.
  89.      */
  90.     @SuppressWarnings("unchecked")
  91.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  92.     private void initComponents() {
  93.  
  94.         mainPanel = new javax.swing.JPanel();
  95.         headerPanel = new javax.swing.JPanel();
  96.         appTitle = new javax.swing.JLabel();
  97.         quitBtn = new javax.swing.JLabel();
  98.         settingsBtn = new javax.swing.JLabel();
  99.         songNameMainPanel = new javax.swing.JPanel();
  100.         songNameSubPanel = new javax.swing.JPanel();
  101.         songNameDisplay = new javax.swing.JLabel();
  102.         controlPanel = new javax.swing.JPanel();
  103.         repeatBtn = new javax.swing.JLabel();
  104.         previousBtn = new javax.swing.JLabel();
  105.         playBtn = new javax.swing.JLabel();
  106.         stopBtn = new javax.swing.JLabel();
  107.         openBtn = new javax.swing.JLabel();
  108.         jLabel7 = new javax.swing.JLabel();
  109.         volumeDownBtn = new javax.swing.JLabel();
  110.         volumeUpBtn = new javax.swing.JLabel();
  111.         volumeFullBtn = new javax.swing.JLabel();
  112.         nextBtn = new javax.swing.JLabel();
  113.  
  114.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  115.         setUndecorated(true);
  116.         setPreferredSize(new java.awt.Dimension(800, 275));
  117.         setResizable(false);
  118.  
  119.         mainPanel.setBackground(new java.awt.Color(16, 49, 62));
  120.  
  121.         headerPanel.setBackground(new java.awt.Color(56, 179, 190));
  122.  
  123.         appTitle.setFont(new java.awt.Font("Oswald Regular", 0, 18)); // NOI18N
  124.         appTitle.setForeground(new java.awt.Color(255, 255, 255));
  125.         appTitle.setText("APP TITLE");
  126.         appTitle.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
  127.             public void mouseDragged(java.awt.event.MouseEvent evt) {
  128.                 appTitleMouseDragged(evt);
  129.             }
  130.         });
  131.         appTitle.addMouseListener(new java.awt.event.MouseAdapter() {
  132.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  133.                 appTitleMouseClicked(evt);
  134.             }
  135.             public void mousePressed(java.awt.event.MouseEvent evt) {
  136.                 appTitleMousePressed(evt);
  137.             }
  138.         });
  139.  
  140.         quitBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  141.         quitBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jobme/pk/images_new/power.png"))); // NOI18N
  142.         quitBtn.addMouseListener(new java.awt.event.MouseAdapter() {
  143.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  144.                 quitBtnMouseClicked(evt);
  145.             }
  146.         });
  147.  
  148.         settingsBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  149.         settingsBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jobme/pk/images_new/list.png"))); // NOI18N
  150.         settingsBtn.addMouseListener(new java.awt.event.MouseAdapter() {
  151.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  152.                 settingsBtnMouseClicked(evt);
  153.             }
  154.         });
  155.  
  156.         javax.swing.GroupLayout headerPanelLayout = new javax.swing.GroupLayout(headerPanel);
  157.         headerPanel.setLayout(headerPanelLayout);
  158.         headerPanelLayout.setHorizontalGroup(
  159.             headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  160.             .addGroup(headerPanelLayout.createSequentialGroup()
  161.                 .addContainerGap()
  162.                 .addComponent(appTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  163.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  164.                 .addComponent(settingsBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  165.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  166.                 .addComponent(quitBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
  167.         );
  168.         headerPanelLayout.setVerticalGroup(
  169.             headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  170.             .addComponent(appTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  171.             .addComponent(quitBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  172.             .addComponent(settingsBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
  173.         );
  174.  
  175.         songNameMainPanel.setBackground(new java.awt.Color(16, 49, 62));
  176.  
  177.         songNameSubPanel.setBackground(new java.awt.Color(16, 49, 62));
  178.         songNameSubPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(56, 179, 190), 1, true));
  179.  
  180.         songNameDisplay.setFont(new java.awt.Font("Aller", 1, 14)); // NOI18N
  181.         songNameDisplay.setForeground(new java.awt.Color(255, 255, 255));
  182.         songNameDisplay.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  183.         songNameDisplay.setText("PLAYING");
  184.  
  185.         javax.swing.GroupLayout songNameSubPanelLayout = new javax.swing.GroupLayout(songNameSubPanel);
  186.         songNameSubPanel.setLayout(songNameSubPanelLayout);
  187.         songNameSubPanelLayout.setHorizontalGroup(
  188.             songNameSubPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  189.             .addGap(0, 0, Short.MAX_VALUE)
  190.             .addGroup(songNameSubPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  191.                 .addGroup(songNameSubPanelLayout.createSequentialGroup()
  192.                     .addContainerGap()
  193.                     .addComponent(songNameDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, 950, Short.MAX_VALUE)
  194.                     .addContainerGap()))
  195.         );
  196.         songNameSubPanelLayout.setVerticalGroup(
  197.             songNameSubPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  198.             .addGap(0, 36, Short.MAX_VALUE)
  199.             .addGroup(songNameSubPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  200.                 .addComponent(songNameDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE))
  201.         );
  202.  
  203.         javax.swing.GroupLayout songNameMainPanelLayout = new javax.swing.GroupLayout(songNameMainPanel);
  204.         songNameMainPanel.setLayout(songNameMainPanelLayout);
  205.         songNameMainPanelLayout.setHorizontalGroup(
  206.             songNameMainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  207.             .addGroup(songNameMainPanelLayout.createSequentialGroup()
  208.                 .addContainerGap()
  209.                 .addComponent(songNameSubPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  210.                 .addContainerGap())
  211.         );
  212.         songNameMainPanelLayout.setVerticalGroup(
  213.             songNameMainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  214.             .addGroup(songNameMainPanelLayout.createSequentialGroup()
  215.                 .addContainerGap()
  216.                 .addComponent(songNameSubPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  217.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  218.         );
  219.  
  220.         controlPanel.setBackground(new java.awt.Color(16, 49, 62));
  221.  
  222.         repeatBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  223.         repeatBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jobme/pk/images_new/repeat.png"))); // NOI18N
  224.         repeatBtn.addMouseListener(new java.awt.event.MouseAdapter() {
  225.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  226.                 repeatBtnMouseClicked(evt);
  227.             }
  228.         });
  229.  
  230.         previousBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  231.         previousBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jobme/pk/images_new/back.png"))); // NOI18N
  232.         previousBtn.addMouseListener(new java.awt.event.MouseAdapter() {
  233.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  234.                 previousBtnMouseClicked(evt);
  235.             }
  236.         });
  237.  
  238.         playBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  239.         playBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jobme/pk/images_new/play-button.png"))); // NOI18N
  240.         playBtn.addMouseListener(new java.awt.event.MouseAdapter() {
  241.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  242.                 playBtnMouseClicked(evt);
  243.             }
  244.         });
  245.  
  246.         stopBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  247.         stopBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jobme/pk/images_new/stop.png"))); // NOI18N
  248.         stopBtn.addMouseListener(new java.awt.event.MouseAdapter() {
  249.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  250.                 stopBtnMouseClicked(evt);
  251.             }
  252.         });
  253.  
  254.         openBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  255.         openBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jobme/pk/images_new/eject.png"))); // NOI18N
  256.         openBtn.addMouseListener(new java.awt.event.MouseAdapter() {
  257.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  258.                 openBtnMouseClicked(evt);
  259.             }
  260.         });
  261.  
  262.         jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  263.  
  264.         volumeDownBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  265.         volumeDownBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jobme/pk/images_new/minus.png"))); // NOI18N
  266.         volumeDownBtn.addMouseListener(new java.awt.event.MouseAdapter() {
  267.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  268.                 volumeDownBtnMouseClicked(evt);
  269.             }
  270.         });
  271.  
  272.         volumeUpBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  273.         volumeUpBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jobme/pk/images_new/plus.png"))); // NOI18N
  274.         volumeUpBtn.addMouseListener(new java.awt.event.MouseAdapter() {
  275.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  276.                 volumeUpBtnMouseClicked(evt);
  277.             }
  278.         });
  279.  
  280.         volumeFullBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  281.         volumeFullBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jobme/pk/images_new/volume-1.png"))); // NOI18N
  282.         volumeFullBtn.addMouseListener(new java.awt.event.MouseAdapter() {
  283.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  284.                 volumeFullBtnMouseClicked(evt);
  285.             }
  286.         });
  287.  
  288.         nextBtn.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  289.         nextBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jobme/pk/images_new/next.png"))); // NOI18N
  290.         nextBtn.addMouseListener(new java.awt.event.MouseAdapter() {
  291.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  292.                 nextBtnMouseClicked(evt);
  293.             }
  294.         });
  295.  
  296.         javax.swing.GroupLayout controlPanelLayout = new javax.swing.GroupLayout(controlPanel);
  297.         controlPanel.setLayout(controlPanelLayout);
  298.         controlPanelLayout.setHorizontalGroup(
  299.             controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  300.             .addGroup(controlPanelLayout.createSequentialGroup()
  301.                 .addContainerGap()
  302.                 .addComponent(repeatBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
  303.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  304.                 .addComponent(previousBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
  305.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  306.                 .addComponent(playBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
  307.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  308.                 .addComponent(nextBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
  309.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  310.                 .addComponent(stopBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
  311.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  312.                 .addComponent(openBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
  313.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  314.                 .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
  315.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  316.                 .addComponent(volumeDownBtn)
  317.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  318.                 .addComponent(volumeUpBtn)
  319.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  320.                 .addComponent(volumeFullBtn)
  321.                 .addContainerGap(268, Short.MAX_VALUE))
  322.         );
  323.         controlPanelLayout.setVerticalGroup(
  324.             controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  325.             .addGroup(controlPanelLayout.createSequentialGroup()
  326.                 .addContainerGap()
  327.                 .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  328.                     .addComponent(repeatBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  329.                     .addComponent(previousBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
  330.                     .addComponent(playBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
  331.                     .addComponent(stopBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
  332.                     .addComponent(openBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
  333.                     .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
  334.                     .addComponent(volumeDownBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
  335.                     .addComponent(volumeUpBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
  336.                     .addComponent(volumeFullBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
  337.                     .addComponent(nextBtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)))
  338.         );
  339.  
  340.         javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
  341.         mainPanel.setLayout(mainPanelLayout);
  342.         mainPanelLayout.setHorizontalGroup(
  343.             mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  344.             .addComponent(headerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  345.             .addComponent(songNameMainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  346.             .addComponent(controlPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  347.         );
  348.         mainPanelLayout.setVerticalGroup(
  349.             mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  350.             .addGroup(mainPanelLayout.createSequentialGroup()
  351.                 .addComponent(headerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  352.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  353.                 .addComponent(songNameMainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  354.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  355.                 .addComponent(controlPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  356.                 .addGap(0, 0, Short.MAX_VALUE))
  357.         );
  358.  
  359.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  360.         getContentPane().setLayout(layout);
  361.         layout.setHorizontalGroup(
  362.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  363.             .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  364.         );
  365.         layout.setVerticalGroup(
  366.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  367.             .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  368.         );
  369.  
  370.         pack();
  371.         setLocationRelativeTo(null);
  372.     }// </editor-fold>//GEN-END:initComponents
  373.  
  374.     private void playBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playBtnMouseClicked
  375.         // TODO add your handling code here:
  376.         if (play == true) {
  377.             play = false;
  378.             player.play();
  379.            
  380.             String image = currentPath + imagePath + "\\pause v2.png";
  381.             playBtn.setIcon(new ImageIcon(image));
  382.         }
  383.        
  384.         else if (play == false) {
  385.             play = true;
  386.             player.pause();
  387.            
  388.             String image = currentPath + imagePath + "\\play-button.png";
  389.             playBtn.setIcon(new ImageIcon(image));
  390.         }
  391.     }//GEN-LAST:event_playBtnMouseClicked
  392.  
  393.     private void stopBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_stopBtnMouseClicked
  394.         // TODO add your handling code here:
  395.         player.stop();
  396.     }//GEN-LAST:event_stopBtnMouseClicked
  397.  
  398.     private void previousBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_previousBtnMouseClicked
  399.         // TODO add your handling code here:
  400.         player.skipBackward();
  401.         // List playList = player.getPlayList();
  402.        
  403.         flag--;
  404.        
  405.         for (int i = 0; i < myPlayList.size(); i++) {
  406.             songNameDisplay.setFont(new Font("Aller", Font.BOLD, 14));
  407.             songNameDisplay.setText("Playing Now... |   " + myPlayList.get(flag - 1));
  408.         }
  409.     }//GEN-LAST:event_previousBtnMouseClicked
  410.  
  411.     private void repeatBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_repeatBtnMouseClicked
  412.         // TODO add your handling code here:
  413.         if (repeat == false) {
  414.             repeat = true;
  415.             player.setRepeat(repeat);
  416.            
  417.             String image = currentPath + imagePath + "\\repeat_enabled.png";
  418.             repeatBtn.setIcon(new ImageIcon(image));
  419.         }
  420.        
  421.         else if (repeat == true) {
  422.             repeat = false;
  423.             player.setRepeat(repeat);
  424.            
  425.             String image = currentPath + imagePath + "\\repeat.png";
  426.             repeatBtn.setIcon(new ImageIcon(image));            
  427.         }
  428.     }//GEN-LAST:event_repeatBtnMouseClicked
  429.  
  430.     private void appTitleMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_appTitleMousePressed
  431.         // TODO add your handling code here:
  432.         xMouse = evt.getX();
  433.         yMouse = evt.getY();
  434.     }//GEN-LAST:event_appTitleMousePressed
  435.  
  436.     private void appTitleMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_appTitleMouseDragged
  437.         // TODO add your handling code here:
  438.         int x = evt.getXOnScreen();
  439.         int y = evt.getYOnScreen();
  440.        
  441.         this.setLocation(x - xMouse, y - yMouse);
  442.     }//GEN-LAST:event_appTitleMouseDragged
  443.  
  444.     private void quitBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_quitBtnMouseClicked
  445.         // TODO add your handling code here:
  446.         this.dispose();
  447.     }//GEN-LAST:event_quitBtnMouseClicked
  448.  
  449.     private void settingsBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_settingsBtnMouseClicked
  450.         // TODO add your handling code here:
  451.         JOptionPane.showMessageDialog(this, "Your settings dialog will be popup here!");
  452.     }//GEN-LAST:event_settingsBtnMouseClicked
  453.  
  454.     private void openBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_openBtnMouseClicked
  455.         // TODO add your handling code here:
  456.         JFileChooser openFileChooser = new JFileChooser(currentDirectory);
  457.         openFileChooser.setFileFilter(new FileTypeFilter(".mp3", "Open MP3 Files Only!"));
  458.         int result = openFileChooser.showOpenDialog(null);
  459.         if (result == JFileChooser.APPROVE_OPTION) {
  460.             songFile = openFileChooser.getSelectedFile();
  461.            
  462.             if (player.getPlayList().size() == 1) {
  463.                 player.addToPlayList(songFile);
  464.                 myPlayList.add(songFile.getName());
  465.                 player.skipForward();
  466.                
  467.                 String image = currentPath + imagePath + "\\pause v2.png";
  468.                 playBtn.setIcon(new ImageIcon(image));
  469.                
  470.                 currentDirectory = songFile.getAbsolutePath();
  471.                 songNameDisplay.setFont(new Font("Aller", Font.BOLD, 14));
  472.                 songNameDisplay.setText("Playing Now... |   " + songFile.getName());
  473.             }
  474.            
  475.             else if (player.getPlayList().size() > 1) {
  476.                 player.addToPlayList(songFile);
  477.                 myPlayList.add(songFile.getName());
  478.                 flag++;
  479.             }
  480.            
  481.             // System.out.println(player.getPlayList());
  482.         }
  483.     }//GEN-LAST:event_openBtnMouseClicked
  484.  
  485.     private void appTitleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_appTitleMouseClicked
  486.         // TODO add your handling code here:
  487.         if (evt.getClickCount() == 2) {
  488.             if (windowCollapsed == false) {
  489.                 windowCollapsed = true;
  490.                 this.setSize(new Dimension(this.getSize().width, 50));
  491.                
  492.                 appTitle.setFont(new Font("Aller", Font.BOLD, 14));
  493.                 appTitle.setText("Playing Now... |  " + songFile.getName());
  494.             }
  495.            
  496.             else if (windowCollapsed == true) {
  497.                 windowCollapsed = false;
  498.                 this.setSize(new Dimension(this.getSize().width, 275));
  499.                
  500.                 appTitle.setFont(new Font("Oswald Regular", 0, 18));
  501.                 appTitle.setText(appName);
  502.             }
  503.         }
  504.     }//GEN-LAST:event_appTitleMouseClicked
  505.  
  506.     private void volumeDownBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_volumeDownBtnMouseClicked
  507.         // TODO add your handling code here:
  508.         volumeDownControl(0.1);
  509.     }//GEN-LAST:event_volumeDownBtnMouseClicked
  510.  
  511.     private void volumeUpBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_volumeUpBtnMouseClicked
  512.         // TODO add your handling code here:
  513.         volumeUpControl(0.1);
  514.     }//GEN-LAST:event_volumeUpBtnMouseClicked
  515.  
  516.     private void volumeFullBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_volumeFullBtnMouseClicked
  517.         // TODO add your handling code here:
  518.         if (fullvolume == true) {
  519.             fullvolume = false;
  520.             volumeControl(1.0);
  521.            
  522.             String image = currentPath + imagePath + "\\volume-1.png";
  523.             volumeFullBtn.setIcon(new ImageIcon(image));
  524.         }
  525.        
  526.         else if (fullvolume == false) {
  527.             fullvolume = true;
  528.             volumeControl(0.0);
  529.            
  530.             String image = currentPath + imagePath + "\\volume-1 mute.png";
  531.             volumeFullBtn.setIcon(new ImageIcon(image));            
  532.         }
  533.     }//GEN-LAST:event_volumeFullBtnMouseClicked
  534.  
  535.     private void nextBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nextBtnMouseClicked
  536.         // TODO add your handling code here:
  537.         player.skipForward();
  538.         // List playList = player.getPlayList();
  539.        
  540.         flag++;
  541.        
  542.         for (int i = 0; i < myPlayList.size(); i++) {
  543.             songNameDisplay.setFont(new Font("Aller", Font.BOLD, 14));
  544.             songNameDisplay.setText("Playing Now... |   " + myPlayList.get(flag - 1));
  545.         }
  546.     }//GEN-LAST:event_nextBtnMouseClicked
  547.  
  548.     /**
  549.      * @param args the command line arguments
  550.      */
  551.     public static void main(String args[]) {
  552.         /* Set the Nimbus look and feel */
  553.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  554.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  555.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  556.          */
  557.         try {
  558.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  559.                 if ("Nimbus".equals(info.getName())) {
  560.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  561.                     break;
  562.                 }
  563.             }
  564.         } catch (ClassNotFoundException ex) {
  565.             java.util.logging.Logger.getLogger(PlayerFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  566.         } catch (InstantiationException ex) {
  567.             java.util.logging.Logger.getLogger(PlayerFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  568.         } catch (IllegalAccessException ex) {
  569.             java.util.logging.Logger.getLogger(PlayerFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  570.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  571.             java.util.logging.Logger.getLogger(PlayerFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  572.         }
  573.         //</editor-fold>
  574.  
  575.         /* Create and display the form */
  576.         java.awt.EventQueue.invokeLater(new Runnable() {
  577.             public void run() {
  578.                 new PlayerFrame().setVisible(true);
  579.             }
  580.         });
  581.     }
  582.  
  583.     // Variables declaration - do not modify//GEN-BEGIN:variables
  584.     private javax.swing.JLabel appTitle;
  585.     private javax.swing.JPanel controlPanel;
  586.     private javax.swing.JPanel headerPanel;
  587.     private javax.swing.JLabel jLabel7;
  588.     private javax.swing.JPanel mainPanel;
  589.     private javax.swing.JLabel nextBtn;
  590.     private javax.swing.JLabel openBtn;
  591.     private javax.swing.JLabel playBtn;
  592.     private javax.swing.JLabel previousBtn;
  593.     private javax.swing.JLabel quitBtn;
  594.     private javax.swing.JLabel repeatBtn;
  595.     private javax.swing.JLabel settingsBtn;
  596.     private javax.swing.JLabel songNameDisplay;
  597.     private javax.swing.JPanel songNameMainPanel;
  598.     private javax.swing.JPanel songNameSubPanel;
  599.     private javax.swing.JLabel stopBtn;
  600.     private javax.swing.JLabel volumeDownBtn;
  601.     private javax.swing.JLabel volumeFullBtn;
  602.     private javax.swing.JLabel volumeUpBtn;
  603.     // End of variables declaration//GEN-END:variables
  604.    
  605.     // I am going to create a custom MP3Player Method
  606.     private MP3Player mp3Player() {
  607.         MP3Player mp3Player = new MP3Player();
  608.         return mp3Player;
  609.     }
  610.    
  611.     // Let's Set Volume Down Method It's not necessary to remeber this code.
  612.     private void volumeDownControl(Double valueToPlusMinus) {
  613.         // Get Mixer Information From AudioSystem
  614.         Mixer.Info[] mixers = AudioSystem.getMixerInfo();
  615.         // Now use a for loop to list all mixers
  616.         for (Mixer.Info mixerInfo : mixers) {
  617.             // Get Mixer
  618.             Mixer mixer = AudioSystem.getMixer(mixerInfo);
  619.             // Now Get Target Line
  620.             Line.Info[] lineInfos = mixer.getTargetLineInfo();
  621.             // Here again use for loop to list lines
  622.             for (Line.Info lineInfo : lineInfos) {
  623.                 // Make a null line
  624.                 Line line = null;
  625.                 // Make a boolean as opened
  626.                 boolean opened = true;
  627.                 // Now use try exception for opening a line
  628.                 try {
  629.                     line = mixer.getLine(lineInfo);
  630.                     opened = line.isOpen() || line instanceof Clip;
  631.                     // Now Check If Line Is not Opened
  632.                     if (!opened){
  633.                         // Open Line
  634.                         line.open();
  635.                     }
  636.                     // Make a float control
  637.                     FloatControl volControl = (FloatControl) line.getControl(FloatControl.Type.VOLUME);
  638.                     // Get Current Volume Now
  639.                     float currentVolume = volControl.getValue();
  640.                     // Make a temp double variable and store valuePlusMinus
  641.                     Double volumeToCut = valueToPlusMinus;
  642.                     // Make a float and calculate the addition or subtraction in volume
  643.                     float changedCalc = (float) ((float)currentVolume-(double)volumeToCut);
  644.                     // Now Set This Changed Value Into Volume Line.
  645.                     volControl.setValue(changedCalc);
  646.                    
  647.                 }
  648.                
  649.                 catch (LineUnavailableException lineException) {
  650.                 }
  651.                
  652.                 catch (IllegalArgumentException illException) {
  653.                 }
  654.                
  655.                 finally {
  656.                     // Close Line If it opened
  657.                     if (line != null && !opened) {
  658.                         line.close();
  659.                     }
  660.                 }
  661.             }
  662.         }
  663.     }
  664.    
  665.     // Let's Set Volume Up Method It's not necessary to remeber this code.
  666.     private void volumeUpControl(Double valueToPlusMinus){
  667.         // Get Mixer Information From AudioSystem
  668.         Mixer.Info[] mixers = AudioSystem.getMixerInfo();
  669.         // Now use a for loop to list all mixers
  670.         for (Mixer.Info mixerInfo : mixers) {
  671.             // Get Mixer
  672.             Mixer mixer = AudioSystem.getMixer(mixerInfo);
  673.             // Now Get Target Line
  674.             Line.Info[] lineInfos = mixer.getTargetLineInfo();
  675.             // Here again use for loop to list lines
  676.             for (Line.Info lineInfo : lineInfos) {
  677.                 // Make a null line
  678.                 Line line = null;
  679.                 // Make a boolean as opened
  680.                 boolean opened = true;
  681.                 // Now use try exception for opening a line
  682.                 try {
  683.                     line = mixer.getLine(lineInfo);
  684.                     opened = line.isOpen() || line instanceof Clip;
  685.                     // Now Check If Line Is not Opened
  686.                     if (!opened) {
  687.                         // Open Line
  688.                         line.open();
  689.                     }
  690.                     // Make a float control
  691.                     FloatControl volControl = (FloatControl) line.getControl(FloatControl.Type.VOLUME);
  692.                     // Get Current Volume Now
  693.                     float currentVolume = volControl.getValue();
  694.                     // Make a temp double variable and store valuePlusMinus
  695.                     Double volumeToCut = valueToPlusMinus;
  696.                     // Make a float and calculate the addition or subtraction in volume
  697.                     float changedCalc = (float) ((float)currentVolume+(double)volumeToCut);
  698.                     // Now Set This Changed Value Into Volume Line.
  699.                     volControl.setValue(changedCalc);
  700.                    
  701.                 }
  702.                
  703.                 catch (LineUnavailableException lineException) {
  704.                 }
  705.                
  706.                 catch (IllegalArgumentException illException) {
  707.                 }
  708.                
  709.                 finally {
  710.                     // Close Line If it opened
  711.                     if (line != null && !opened) {
  712.                         line.close();
  713.                     }
  714.                 }
  715.             }
  716.         }
  717.     }
  718.    
  719.     // Let's Set Volume Method It's not necessary to remeber this code.
  720.     private void volumeControl(Double valueToPlusMinus) {
  721.         // Get Mixer Information From AudioSystem
  722.         Mixer.Info[] mixers = AudioSystem.getMixerInfo();
  723.         // Now use a for loop to list all mixers
  724.         for (Mixer.Info mixerInfo : mixers) {
  725.             // Get Mixer
  726.             Mixer mixer = AudioSystem.getMixer(mixerInfo);
  727.             // Now Get Target Line
  728.             Line.Info[] lineInfos = mixer.getTargetLineInfo();
  729.             // Here again use for loop to list lines
  730.             for (Line.Info lineInfo : lineInfos) {
  731.                 // Make a null line
  732.                 Line line = null;
  733.                 // Make a boolean as opened
  734.                 boolean opened = true;
  735.                 // Now use try exception for opening a line
  736.                 try {
  737.                     line = mixer.getLine(lineInfo);
  738.                     opened = line.isOpen() || line instanceof Clip;
  739.                     // Now Check If Line Is not Opened
  740.                     if (!opened) {
  741.                         // Open Line
  742.                         line.open();
  743.                     }
  744.                     // Make a float control
  745.                     FloatControl volControl = (FloatControl) line.getControl(FloatControl.Type.VOLUME);
  746.                     // Get Current Volume Now
  747.                     float currentVolume = volControl.getValue();
  748.                     // Make a temp double variable and store valuePlusMinus
  749.                     Double volumeToCut = valueToPlusMinus;
  750.                     // Make a float and calculate the addition or subtraction in volume
  751.                     float changedCalc = (float) ((double)volumeToCut);
  752.                     // Now Set This Changed Value Into Volume Line.
  753.                     volControl.setValue(changedCalc);
  754.                    
  755.                 }
  756.                
  757.                 catch (LineUnavailableException lineException) {
  758.                 }
  759.                
  760.                 catch (IllegalArgumentException illException) {
  761.                 }
  762.                
  763.                 finally {
  764.                     // Close Line If it opened
  765.                     if (line != null && !opened) {
  766.                         line.close();
  767.                     }
  768.                 }
  769.             }
  770.         }
  771.     }
  772. }
  773.  
Advertisement
Add Comment
Please, Sign In to add comment