i AM really new at java and i have just created a very simple diesign of something that is static but should play mp3 files, loaded the required jmf as well ...I want when i click on the jtable and then play song starts playing ..its is not happening
here's the code

import java.applet.*;
import java.awt.*;

/**
 *
 * @author  Nipun
 */
public class NewJApplet extends javax.swing.JApplet {

    String song_name;

    /** Initializes the applet NewJApplet */
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {

                public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"Aahun Aahun", "5.44"},
                {"Twist", "5.33"},
                {"Aazma", "5.43"},
                {"Ye Dooriyan", "5.55"}
            },
            new String [] {
                "Song Name", "Time"
            }
        ));
        jTable1.setPreferredSize(new java.awt.Dimension(64, 64));
        jScrollPane1.setViewportView(jTable1);

        getContentPane().setLayout(null);

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

        jLabel1.setFont(new java.awt.Font("Amienne", 1, 48));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("JUKEBOX");
        jLabel1.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(255, 0, 51)));

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton1.setForeground(new java.awt.Color(102, 0, 204));

        jButton2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton2.setForeground(new java.awt.Color(102, 0, 204));

        jButton3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton3.setForeground(new java.awt.Color(102, 0, 204));
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton4.setForeground(new java.awt.Color(102, 0, 204));
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton5.setForeground(new java.awt.Color(102, 0, 204));
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton5MouseClicked(evt);
            }
        });
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jTable2.setForeground(new java.awt.Color(255, 0, 0));
        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"Rihanna-Umbrella96k", "5.53"},
                {"29001", "4.55"},
                {"71112", "3.56"},
                {"Rihanna-Umbrella-56k", "4.55"}
            },
            new String [] {
                "Song Name", "Time"
            }
        ));
        jTable2.setGridColor(new java.awt.Color(255, 255, 255));
        jTable2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable2MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable2);

        jLabel2.setFont(new java.awt.Font("Blue Highway Linocut", 0, 24));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("PLAYLIST");

        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel3.setForeground(new java.awt.Color(255, 204, 51));
        jLabel3.setText("jLabel3");

        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.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 401, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(118, 118, 118)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addGap(100, 100, 100)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jButton5)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton4)
                            .addComponent(jButton3)))
                    .addComponent(jButton2)
                    .addComponent(jButton1)
                    .addComponent(jButton6))
                .addContainerGap())
        );

        getContentPane().add(jPanel1);
        jPanel1.setBounds(0, 0, 400, 360);
    }// </editor-fold>
    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
    }                                        

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
song_name=(String) jTable2.getValueAt(jTable2.getSelectedRow(), 0);
        AudioClip clip = getAudioClip(getCodeBase(), "songs/" + "song_name.MP3");

        clip.play();
        jLabel3.setText("chanegd");  
    }                                        

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

    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        AudioClip clip = getAudioClip(getCodeBase(), "songs/" + "song_name.MP3");
        clip.stop();    // TODO add your handling code here:
    }                                        

    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {                                      
    // TODO add your handling code here:
    }                                     

    private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {                                     
        jLabel3.setText(jTable2.getValueAt(jTable2.getSelectedRow(), 0) + "");
 
    // TODO add your handling code here:
    }                                    
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    // End of variables declaration
}

Recommended Answers

All 8 Replies

i have just created a very simple diesign of something that is static but should play mp3 files.

This is very hard to follow.... I don't see where your simplicity kicks in :)

i just want you to look into this

 private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {                                     
        jLabel3.setText(jTable2.getValueAt(jTable2.getSelectedRow(), 0) + "");




 private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
song_name=(String) jTable2.getValueAt(jTable2.getSelectedRow(), 0);
        AudioClip clip = getAudioClip(getCodeBase(), "songs/" + "song_name.MP3");

        clip.play();
        jLabel3.setText("chanegd");  
    }                    

i mean when when i select something from jtable it should actuall play wen i click that button..

private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {
jLabel3.setText(jTable2.getValueAt(jTable2.getSelectedRow(), 0) + "");




private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
song_name=(String) jTable2.getValueAt(jTable2.getSelectedRow(), 0);
AudioClip clip = getAudioClip(getCodeBase(), "songs/" + "song_name.MP3");

clip.play();
jLabel3.setText("chanegd");
}
song_name=(String) jTable2.getValueAt(jTable2.getSelectedRow(), 0);
AudioClip clip = getAudioClip(getCodeBase(), "songs/" + "song_name.MP3");

you have song_name.MP3 in quotes. take off the quotes...

song_name=(String) jTable2.getValueAt(jTable2.getSelectedRow(), 0);
AudioClip clip = getAudioClip(getCodeBase(), "songs/" + song_name + ".MP3");

..and 1 more thing...I hv tested it ..it only plays songs upto 96 kbps and not above that!!
And pause function is not in the interface so i have to code it myself, i was thinking of making a thread which will go to sleep ...its the right direction????

well i dont think so , i m giving code base and the file name so it should treat it as a file name as string and it must be in commas only..

If song_name is "abcd" and you do .....("songs/" + "song_name.MP3");
you area really saying "songs/song_name.MP3", not "songs/abcd.MP3"

You might want to do something like this:

song_name = "songs/";
song_name += (String).....;
song_name += ".MP3";

System.out.println("Playing song: "+song_name);
AudioClip clip = getAudioClip(getCodeBase(), song_name);

yea and whats with the othe r que i asked about the bitrate issue and pause function..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.