MP3 player


TUGAS JAVA MP3 DAN TEXTREADER

Tugas yang Mp3 dan text Reader ini cara pembuatannya tidak jauh bereda dengan tugas yang membuat EditorFileText karena langkah pembuatannya hampir mirip,yaitu;
1.  Pertama buka netbeans
2.  Buat Package bernama MP3_Player (sebenarnya untuk penamaan Packagenya sesuai dengan kemauan si pembuat)
3.  Buat project dengan cara mengeklik kanan memilih Form Jframe
4.  Beri nama Jframe From tersebut dengan nama ApilkasiMP3Player atau terserah
5.  Buat tampilan menyerupai project di bawah ini (berbeda juga boleh asal hasilnya lebih baik)
1.  Tambahkan coding berikut pada source projectnya
ini codingnya 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * mp3_music.java
 *
 * Created on Mar 5, 2013, 11:30:52 AM
 */
package coba.mp3_music;

import java.io.File;
import java.net.URL;
import javax.media.Manager;
import javax.media.Player;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

/**
 *
 * @author Putri_DK
 */
public class mp3_music extends javax.swing.JFrame {

    /** Creates new form mp3_music */
    public mp3_music() {
        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() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(153, 153, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("")));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/coba/mp3_music/pu.png"))); // NOI18N

        jButton1.setFont(new java.awt.Font("Tekton Pro Ext", 0, 11));
        jButton1.setForeground(new java.awt.Color(204, 51, 255));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/coba/mp3_music/icon tambah domain.png"))); // NOI18N
        jButton1.setText("ADD PLAY LIST");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Fast 99", 0, 18));
        jLabel2.setForeground(new java.awt.Color(204, 0, 255));
        jLabel2.setText("KUMPULAN FILE MP3");

        jButton2.setFont(new java.awt.Font("Tekton Pro Ext", 0, 11));
        jButton2.setForeground(new java.awt.Color(204, 51, 255));
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/coba/mp3_music/PLAY.png"))); // NOI18N
        jButton2.setText("PLAY LIST");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("Tekton Pro Ext", 0, 11));
        jButton3.setForeground(new java.awt.Color(204, 0, 255));
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/coba/mp3_music/delete-icon.png"))); // NOI18N
        jButton3.setText("DELETE LIST");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jList1.setBackground(new java.awt.Color(204, 153, 255));
        jList1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jList1.setFont(new java.awt.Font("Dancin LET", 0, 14));
        jList1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane1.setViewportView(jList1);

        jLabel3.setFont(new java.awt.Font("Snipple", 0, 36)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(204, 0, 255));
        jLabel3.setText("PUTRI AND MUSIC");

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/coba/mp3_music/logo sekolah copy.jpg"))); // NOI18N

        jLabel5.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        jLabel5.setText("©PUTRI_DK");

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/coba/mp3_music/muslim.png"))); // NOI18N

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/coba/mp3_music/index.png"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4)
                        .addGap(26, 26, 26)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel6))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addContainerGap()
                                        .addComponent(jLabel1))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(54, 54, 54)
                                        .addComponent(jLabel5)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE)
                                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(185, 185, 185)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(jButton3))))
                .addContainerGap(10, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(11, 11, 11)
                                .addComponent(jLabel4)
                                .addGap(41, 41, 41))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(63, 63, 63)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        JFileChooser fc = new JFileChooser();
        JFrame jf = new JFrame();
        int setuju = fc.showOpenDialog(jf.add(fc));
        int posisi = jList1.getModel().getSize();
        if (setuju == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            String text = file.getPath().toString();
            String[] txt = new String[]{text};
            model.add(posisi, text);
        }
        jList1.setModel(model);

    }                                       

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        if (evt.getActionCommand().equalsIgnoreCase("PLAY LIST")) {
            mainkan();
            jButton2.setText("STOP");
        }
        if (evt.getActionCommand().equalsIgnoreCase("STOP")) {
            playerSS.stop();
            jButton2.setText("PLAY LIST");
        }

    }                                       

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        int posisi = jList1.getSelectedIndex();
        model.remove(posisi);
    }                                       
    /**
     * @param args the command line arguments
     */
    public Player playerSS;
    DefaultListModel model = new DefaultListModel();

    void mainkan() {
        String main = jList1.getSelectedValue().toString();
        try {
            playerSS = Manager.createPlayer(new URL("file", null, main));
            playerSS.start();
        } catch (Exception ex) {
        }

    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new mp3_music().setVisible(true);
            }
        });

    }
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration
}

OLEH:
PUTRI KUSRIYANTI
XI TKJ 1
26





You May Also Like

0 comments