Anda di halaman 1dari 15

Laporan Pemograman MP3 (Pemutar Musik)

A.
1.
2.
3.

Cara membuat :
Buat Project Aplikasi
Baru Buka Program Netbeans IDE yang sudah terinstall di PC/Laptop.
Klik File --> New Project

Perlu di ketahui program yang akan saya buat adalah aplikasi java
biasa yang menggunakan GUI ( Graphic User Interface)
4. Pilih kategori Java, dan project Java Aplication
5. Lalu klik Next >

Nama project yang saya buat adalah Musik


6. Uncheck Create Main Class. Karena pada saat membuat program nanti
kita akakn menggunakan class JFrame sebagai main class.
7. Klik Finish

8. Setelah membuat project baru, selanjutnya adalah mendesain MP3


Player yang akan saya buat.

9. Klik kanan pada package < default package> New jFrame Form
10.
Isi nama clas dengan MP3.
11.
Lalu klik Finish

12.

Kemudian buat sebuah tampilan sebagai berikut :

B. Kegunaan Setiap Panel di Aplikasi MP3:


1. Open : Berguna untuk membuka folder music dan memasukkannya
di panel list music .

2. Panel list berguna untuk menyimpan music yang telah kita pilih di
folder open

3. Panel Play sekaligus stop, berguna untuk memutar music dan


memberhentikan pemutaran music

4. Sedangkan panel hapus berguna untuk menghapus music di Play


List

Source kode, agar program bias berjalan :


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.

*/
import java.awt.TrayIcon;
import java.io.File;
import java.net.URL;
import javax.media.Manager;
import javax.media.Player;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.DefaultListModel;
/**
*
* @author
*/
public class Mp3 extends javax.swing.JFrame {
DefaultListModel model = new DefaultListModel();
/**
* Creates new form
*/
public Player playerSS;
public String text;
public Mp3() {
initComponents();
}
void mainkan(){
String main=jList1.getSelectedValue().toString();

try{
playerSS = Manager.createPlayer(new URL("file",null,main));
playerSS.start();

}catch(Exception ex){}
}
/**
* 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() {

jLabel1 = new javax.swing.JLabel();


jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

getContentPane().setLayout(new
org.netbeans.lib.awtextra.AbsoluteLayout());

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N


jLabel1.setText("MP3 Player");
getContentPane().add(jLabel1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(110, 10, -1, -1));

jButton1.setBackground(new java.awt.Color(0, 0, 0));


jButton1.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
jButton1.setForeground(new java.awt.Color(255, 255, 255));
jButton1.setText("Open");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(20, 220, 80, 50));

jScrollPane1.setViewportView(jList1);

getContentPane().add(jScrollPane1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(30, 50, 266, -1));

jButton2.setBackground(new java.awt.Color(0, 0, 0));

jButton2.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N


jButton2.setForeground(new java.awt.Color(255, 255, 255));
jButton2.setText("Play");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(120, 220, 80, 50));

jButton3.setBackground(new java.awt.Color(0, 0, 0));


jButton3.setFont(new java.awt.Font("Arial Black", 1, 12)); // NOI18N
jButton3.setForeground(new java.awt.Color(255, 255, 255));
jButton3.setText("Hapus");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
getContentPane().add(jButton3, new
org.netbeans.lib.awtextra.AbsoluteConstraints(220, 220, 80, 50));

jLabel2.setIcon(new
javax.swing.ImageIcon("C:\\Users\\Alusu\\Downloads\\Video\\wpid-abstractbackground-with-triangles_23-2147512044-1170x1170.jpg")); // NOI18N

getContentPane().add(jLabel2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 320, 290));

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

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


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();
text = file.getPath().toString();

String[] txt = new String[]{text};


model.add(posisi, text);
}
jList1.setModel(model);
// TODO add your handling code here:
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


if(evt.getActionCommand().equalsIgnoreCase("Play")){
mainkan();

jButton2.setText("Stop");
}
if(evt.getActionCommand().equalsIgnoreCase("Stop")){
playerSS.stop();
jButton2.setText("Play");
}

// TODO add your handling code here:


}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {


int posisi=jList1.getSelectedIndex();
model.remove(posisi);
playerSS.stop();
// TODO add your handling code here:
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/

//<editor-fold defaultstate="collapsed" desc=" Look and feel setting


code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
*
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Mp3.class.getName()).log(java.util.logging
.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Mp3.class.getName()).log(java.util.logging
.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Mp3.class.getName()).log(java.util.logging
.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {


java.util.logging.Logger.getLogger(Mp3.class.getName()).log(java.util.logging
.Level.SEVERE, null, ex);
}
//</editor-fold>

/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {


new Mp3().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.JList jList1;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration