Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Music player problem

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Music player problem

    Hi I made a small music player. But when I select the file the windows does not turn up but the music plays in the background and I get these exceptions

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at Musique.openFile(Musique.java:72)
    at Musique.init(Musique.java:37)
    at TaskPanel.actionPerformed(TaskPanel.java:43)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6134)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3265)
    at java.awt.Component.processEvent(Component.java:589 9)
    at java.awt.Container.processEvent(Container.java:202 3)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4501)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2081)
    at java.awt.Component.dispatchEvent(Component.java:43 31)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4299)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3963)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3893)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2067)
    at java.awt.Window.dispatchEventImpl(Window.java:2458 )
    at java.awt.Component.dispatchEvent(Component.java:43 31)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:284)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

    import java.io.*;
    import java.io.FileInputStream.*;
    import java.awt.*;
    import javax.swing.JInternalFrame;
    import javax.swing.UIManager.*;
    import javax.swing.event.InternalFrameEvent;
    import javax.media.*;
    import com.sun.media.ui.*;
    import java.net.*;
    import javax.swing.event.InternalFrameAdapter;
     
    class Musique implements ControllerListener
    { String filename;
        FileDialog fd;
        public void init()
        { core c = new core();
            if (fd == null) 
                            {
                                fd = new FileDialog(c,"Open File",
    						       FileDialog.LOAD);
                            	fd.setDirectory("/movies");
                            }
                            fd.show();
                                if (fd.getFile() != null) {
                                String filename = fd.getDirectory() + fd.getFile();
                                openFile("file:" + filename);
    		    }
     
     
        }           
    public void openFile(String filename) {
        //writepadstart w = new writepadstart();
     
    	String mediaFile = filename;
    	Player player = null;
    	// URL for our media file
    	URL url = null;
    	try {
    	    // Create an url from the file name and the url to the
    	    // document containing this applet.
    	    if ((url = new URL(mediaFile)) == null) {
    		Fatal("Can't build URL for " + mediaFile);
    		return;
    	    }
     
    	    // Create an instance of a player for this media
    	    try {
    		player = Manager.createPlayer(url);
    	    } catch (NoPlayerException e) {
    		Fatal("Error: " + e);
    	    }
    	} catch (MalformedURLException e) {
    	    Fatal("Error:" + e);
    	} catch (IOException e) {
    	    Fatal("Error:" + e);
    	}
    	if (player != null) {
                core c = new core();
    	    this.filename = filename;
    	    JMFrame1 jmframe = new JMFrame1(player, filename);
    	    c.cont.add(jmframe);
                jmframe.moveToFront();
                jmframe.setClosable(true);
                jmframe.setMaximizable(true);
                jmframe.setIconifiable(true);
                jmframe.setResizable(true);
                jmframe.show();
     
    	}
        }
     
        static void Fatal(String s) {
    	MessageBox mb = new MessageBox("JMF Error", s);
        }    
     
        public void controllerUpdate(ControllerEvent arg0) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
    }
     
     
    class JMFrame1 extends JInternalFrame implements ControllerListener {
        Player mplayer;
        Component visual = null;
        Component control = null;
        int videoWidth = 0;
        int videoHeight = 0;
        int controlHeight = 30;
        int insetWidth = 10;
        int insetHeight = 30;
        boolean firstTime = true;
     
        JMFrame1(Player player, String title) {
     
    	getContentPane().setLayout( new BorderLayout() );
    	setSize(320, 10);
    	setLocation(50, 50);
    	setVisible(true);
    	mplayer = player;
    	mplayer.addControllerListener((ControllerListener) this);
    	mplayer.realize();
    	addInternalFrameListener( new InternalFrameAdapter() {
                @Override
    	    public void internalFrameClosing(InternalFrameEvent ife) {
    		mplayer.close();
    	    }
    	} );
        }
     
     
     
     
     
     
     
     
     
        public void controllerUpdate(ControllerEvent ce) {
    	if (ce instanceof RealizeCompleteEvent) {
    	    mplayer.prefetch();
    	} else if (ce instanceof PrefetchCompleteEvent) {
    	    if (visual != null)
    		return;
     
    	    if ((visual = mplayer.getVisualComponent()) != null) {
    		Dimension size = visual.getPreferredSize();
    		videoWidth = size.width;
    		videoHeight = size.height;
    		getContentPane().add("Center", visual);
    	    } else
    		videoWidth = 320;
    	    if ((control = mplayer.getControlPanelComponent()) != null) {
    		controlHeight = control.getPreferredSize().height;
    		getContentPane().add("South", control);
    	    }
    	    setSize(videoWidth + insetWidth,
    		    videoHeight + controlHeight + insetHeight);
    	    validate();
    	    mplayer.start();
    	} else if (ce instanceof EndOfMediaEvent) {
    	    mplayer.setMediaTime(new Time(0));
    	    mplayer.start();
    	}
        }
    }


  2. #2
    Member
    Join Date
    Feb 2010
    Location
    Dehradun, India
    Posts
    37
    Thanks
    1
    Thanked 7 Times in 6 Posts

    Default Re: Music player problem

    Hi What is core in there?

    I am unable to resolve it.

    Is it some extra class have designed.

    Then send its code.

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Music player problem

    /* Codename 'Puma' (I like cats and dogs)
     * Build Core 2 Build 1
     * Build 1 Date: 26/01/2010
     * 
     * A Java Based Desktop Environment For Windows, Macintosh and Linux.
     * Created by Abhinav Sunil Hardikar.
     * 
     * About me:
     * I am 17 year old guy in the 11 grade. Studying Java from a book I have successfully 
     * made Core 1 Build 1 to 8. Just search for "Java Based desktop environment" on google
     * and select the ubuntuforums link for more information.
     * 
     * [LOG]
     * Scrapped Core 1 Build 8 architecture
     * New Core architecture design implemented.
     * 
     */
     
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.UIManager.LookAndFeelInfo;
    import java.io.*;
    import java.io.FileInputStream.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.JInternalFrame;
    import javax.swing.UIManager.*;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    import javax.swing.event.InternalFrameEvent;
    import javax.swing.event.InternalFrameListener;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.table.DefaultTableModel;
    import javax.media.*;
    import com.sun.media.ui.*;
    import javax.media.protocol.*;
    import javax.media.protocol.DataSource;
    import java.util.Vector;
    import java.net.*;
    import javax.swing.event.InternalFrameAdapter;
     
     
    class core extends JFrame
    {
        // DECLARATIONS
     
            JMenu menu;
            JMenuBar menubar;
            JMenuItem menuitem;
            JDesktopPane dpane;
            Container cont;
            JLabel wallpaper;
        // END OF DECLARATIONS
        public void init()
        {      
            // INITIALIZATIONS
             Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, new Boolean(true));
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            TaskPanel tsk = new TaskPanel();
            menu = new JMenu("File");
            menubar = new JMenuBar();
            dpane = new JDesktopPane();
            cont = getContentPane();
            ImageIcon im = new ImageIcon("c:\\wallpaper\\puma3.jpg");
            Image img = im.getImage();
            Image wall = img.getScaledInstance(screenSize.width, screenSize.height,  java.awt.Image.SCALE_SMOOTH);  
            ImageIcon newWall = new ImageIcon(wall); 
            wallpaper = new JLabel(newWall, JLabel.CENTER);
            //wallpaper.moveToBack();
     
            //END OF INITIALIZATIONS
     
     
            //dpane.add(n.jmframe);
            //cont.add(n);
            menubar.add(menu);
            menu.add(new JMenuItem("Menu"));
            cont.add(menubar, BorderLayout.NORTH);
            tsk.content();
            cont.add(tsk, BorderLayout.SOUTH);
     
            wallpaper.setSize(getSize());
            cont.add(wallpaper);
     
            cont.add(dpane);
            /*JMFrame1 n = new JMFrame1();
            n.init();*/
        }
    }
    class Puma
    {
        public static void main(String args[])
        {   
            try
            {   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
                /*for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
                         {
                             if ("Nimbus".equals(info.getName())) 
                             {
                                       UIManager.setLookAndFeel(info.getClassName());
     
                                       break;
                             }
                         }*/
     
     
     
     
                core c = new core();
     
                c.setTitle("Puma");
                c.setSize(screenSize);
                c.setExtendedState(JFrame.MAXIMIZED_BOTH);
                c.addWindowListener(new WindowAdapter() {@Override
                        public void windowClosing(WindowEvent e) {System.exit(0);}});
                c.setUndecorated(true);
                c.init();
                c.show();
            }
     
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
    }

  4. #4
    Member
    Join Date
    Feb 2010
    Location
    Dehradun, India
    Posts
    37
    Thanks
    1
    Thanked 7 Times in 6 Posts

    Default Re: Music player problem

    Hi, There is one more error appearing saying that

    TaskPanel can not be resolved.

  5. #5
    Junior Member
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Music player problem

    sorry forgot to ive you the TaskPanel class code
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.io.*;
    import java.io.FileInputStream.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.JInternalFrame;
    import javax.swing.UIManager.*;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    import javax.swing.event.InternalFrameEvent;
    import javax.swing.event.InternalFrameListener;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.table.DefaultTableModel;
    import javax.media.*;
    import com.sun.media.ui.*;
    import javax.media.protocol.*;
    import javax.media.protocol.DataSource;
    import java.util.Vector;
    import java.net.*;
    import javax.swing.event.InternalFrameAdapter;
     
     
    public class TaskPanel extends JToolBar implements ActionListener
    {   
        JButton m;
        public void content() throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException
        {
            UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
            m = new JButton("Musique");
          //m.setSize(10, 10);
          m.addActionListener(this);
            add(m);
     
     
        }
        public void actionPerformed(ActionEvent event)
            {try{
     
            if(event.getSource() == m)
            {
            Musique n = new Musique();
            n.init();
     
            core c = new core();
     
            }
        }
             catch(Exception e)
             {
                e.printStackTrace();
             }
        }
    }

  6. #6
    Member
    Join Date
    Feb 2010
    Location
    Dehradun, India
    Posts
    37
    Thanks
    1
    Thanked 7 Times in 6 Posts

    Default Re: Music player problem

    Hi Now I am getting one more error on this particular line

    UIManager.setLookAndFeel("com.seaglasslookandfeel. SeaGlassLookAndFeel");

    The error is:
    java.lang.ClassNotFoundException: com.seaglasslookandfeel.SeaGlassLookAndFeel

  7. #7
    Junior Member
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Music player problem

     UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
                /*for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
                         {
                             if ("Nimbus".equals(info.getName())) 
                             {
                                       UIManager.setLookAndFeel(info.getClassName());
     
                                       break;
                             }
                         }*/

    If you can see this part of the program just chage it to

    // UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
                for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
                         {
                             if ("Nimbus".equals(info.getName())) 
                             {
                                       UIManager.setLookAndFeel(info.getClassName());
     
                                       break;
                             }
                         }

    It will work
    Sorry for troubling you so much

Similar Threads

  1. [ASK] JMF Class Player
    By bocahTuaNakalzz in forum Java SE APIs
    Replies: 2
    Last Post: December 8th, 2009, 03:40 AM
  2. MP3 Player: ID3 Tag Image Retrieval Problem for the Applet from internet
    By JavaJames in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 20th, 2009, 07:11 AM