Hi guys well what I want to do is play a video clip when my program starts. My menu has been set up to how I want it to look. I've researched how to do this but I cannot seem to find anything that I want. All I find is how to create a video player where the user can select their own videos. This is not what I want to do. All I want is my program too play a video clip on start up.

Any help or links you can give would be appreciated

My code below:

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;

public class Basicgui extends JFrame {
    
    public Basicgui() {
        
        setTitle("Video Play Simulation");
        setSize(600, 500);
        
        // Creates a menubar for a JFrame
        JMenuBar menuBar = new JMenuBar();
        
        // Add the menubar to the frame
        setJMenuBar(menuBar);
        
        // Define and add two drop down menu to the menubar
        JMenu fileMenu = new JMenu("File");
        JMenu editMenu = new JMenu("Edit");
        JMenu viewMenu = new JMenu("view");
        menuBar.add(fileMenu);
        menuBar.add(editMenu);
        menuBar.add(viewMenu);
        JMenuItem EXITAction = new JMenuItem("EXIT");
        JMenuItem updateAction = new JMenuItem("update Videos");
        JMenuItem playlistAction = new JMenuItem("Create Playlist");
        JMenuItem queryAction = new JMenuItem("view directors");
        JMenuItem videosAction = new JMenuItem("Check Videos");
        fileMenu.add(EXITAction);
        fileMenu.add(videosAction);
        editMenu.add(updateAction);
        editMenu.add(playlistAction);
        viewMenu.add(videosAction);
        viewMenu.add(queryAction);
        
        ////////////// COLOURS ///////////////////
        
        
         menuBar.setBackground(Color.BLACK);
         fileMenu.setForeground(Color.red);
           editMenu.setForeground(Color.red);
             viewMenu.setForeground(Color.red);
             
               EXITAction.setForeground(Color.red);
               updateAction.setForeground(Color.red);
               playlistAction.setForeground(Color.red);
               queryAction.setForeground(Color.red);
               videosAction.setForeground(Color.red);
               
               //////// BACKGROUNDS //////////
               
               EXITAction.setBackground(Color.BLACK);
               updateAction.setBackground(Color.BLACK);
               playlistAction.setBackground(Color.BLACK);
               queryAction.setBackground(Color.BLACK);
               videosAction.setBackground(Color.BLACK);  
    }
    public static void main(String[] args) {
        Basicgui me = new Basicgui();
        me.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        me.setVisible(true);
        me.setBackground(Color.BLACK);  
    }
}

My video code is:

import java.applet.Applet;
  import java.awt.*;
  import java.awt.event.*;
  import java.lang.String;
  import java.net.URL;
  import java.net.MalformedURLException;
  import java.io.IOException;
  import java.util.Properties;
  import javax.media.*;
  
 	  public class SimplePlayerApplet extends Applet implements ControllerListener {
     
     // media Player
     Player player = null;
     // component in which video is playing
     Component visualComponent = null;
     // controls gain, position, start, stop
     Component controlComponent = null;
     // displays progress during download
     Component progressBar = null;
     boolean firstTime = true;
     long CachingSize = 0L;    
     Panel panel = null;
     int controlPanelHeight = 0; 
     int videoWidth = 0;
     int videoHeight = 0;
 
     /**
  71:     * Read the applet file parameter and create the media 
  72:     * player.
 :     */
 	      public void init() {
     //$ System.out.println("Applet.init() is called");
     setLayout(null);
     setBackground(Color.white);
     panel = new Panel();
     panel.setLayout( null );
     add(panel);
     panel.setBounds(0, 0, 320, 240);
 
     // input file name from html param
     String mediaFile = null;
     // URL for our media file
     MediaLocator mrl = null;
     URL url = null;
 
     // Get the media filename info.
     // The applet tag should contain the path to the
      // source media file, relative to the html page.
     
     if ((mediaFile = getParameter("montage4.avi) == null)
         Fatal("Invalid media file parameter");
 
 	      try {
         url = new URL(getDocumentBase(), mediaFile);
         mediaFile = url.toExternalForm();
     } catch (MalformedURLException mue) {
     }
     
 	      try {
         // Create a media locator from the file name
         if ((mrl = new MediaLocator(mediaFile)) == null)
         Fatal("Can't build URL for " + mediaFile);
 
         /*
 108:	          try {
 109:        JMFSecurity.enablePrivilege.invoke(JMFSecurity.privilegeManager,
 110:                           JMFSecurity.writePropArgs);
 111:        JMFSecurity.enablePrivilege.invoke(JMFSecurity.privilegeManager,
 112:                           JMFSecurity.readPropArgs);
 113:        JMFSecurity.enablePrivilege.invoke(JMFSecurity.privilegeManager,
 114:                           JMFSecurity.connectArgs);
 115:        } catch (Exception e) {}
 16:        */
        
         // Create an instance of a player for this media
 	          try {
         player = Manager.createPlayer(mrl);
         } catch (NoPlayerException e) {
         System.out.println(e);
         Fatal("Could not create player for " + mrl);
         }
 
         // Add ourselves as a listener for a player's events
         player.addControllerListener(this);
 
     } catch (MalformedURLException e) {
         Fatal("Invalid media file URL!");
     } catch (IOException e) {
         Fatal("IO exception creating player for " + mrl);
     }
 
     // This applet assumes that its start() calls 
     // player.start(). This causes the player to become
     // realized. Once realized, the applet will get
     // the visual and control panel components and add
     // them to the Applet. These components are not added
     // during init() because they are long operations that
     // would make us appear unresposive to the user.
     }
 
     /**
 145:     * Start media file playback. This function is called the
 146:     * first time that the Applet runs and every
 147:     * time the user re-enters the page.
 :     */
 
 	      public void start() {
     //$ System.out.println("Applet.start() is called");
         // Call start() to prefetch and start the player.
         if (player != null)
         player.start();
     }
 
     /**
 158:     * Stop media file playback and release resource before
 159:     * leaving the page.
 0:     */
 	      public void stop() {
     //$ System.out.println("Applet.stop() is called");
 	          if (player != null) {
             player.stop();
             player.deallocate();
         }
     }
 
 	      public void destroy() {
     //$ System.out.println("Applet.destroy() is called");
     player.close();
     }
 
 
     /**
 176:     * This controllerUpdate function must be defined in order to
 177:     * implement a ControllerListener interface. This 
 178:     * function will be called whenever there is a media event
      */
 	      public synchronized void controllerUpdate(ControllerEvent event) {
     // If we're getting messages from a dead player, 
     // just leave
     if (player == null)
         return;
     
     // When the player is Realized, get the visual 
     // and control components and add them to the Applet
 	      if (event instanceof RealizeCompleteEvent) {
 	          if (progressBar != null) {
         panel.remove(progressBar);
         progressBar = null;
         }
 
         int width = 320;
         int height = 0;
         if (controlComponent == null)
         if (( controlComponent = 
 	                player.getControlPanelComponent()) != null) {
             
             controlPanelHeight = controlComponent.getPreferredSize().height;
             panel.add(controlComponent);
             height += controlPanelHeight;
         }
         if (visualComponent == null)
         if (( visualComponent =
 	                player.getVisualComponent())!= null) {
             panel.add(visualComponent);
             Dimension videoSize = visualComponent.getPreferredSize();
             videoWidth = videoSize.width;
             videoHeight = videoSize.height;
             width = videoWidth;
             height += videoHeight;
             visualComponent.setBounds(0, 0, videoWidth, videoHeight);
         }
 
         panel.setBounds(0, 0, width, height);
 	          if (controlComponent != null) {
         controlComponent.setBounds(0, videoHeight,
                        width, controlPanelHeight);
         controlComponent.invalidate();
         }
         
      } else if (event instanceof CachingControlEvent) {
         if (player.getState() > Controller.Realizing)
         return;
         // Put a progress bar up when downloading starts, 
         // take it down when downloading ends.
         CachingControlEvent e = (CachingControlEvent) event;
         CachingControl cc = e.getCachingControl();
 
         // Add the bar if not already there ...
 	          if (progressBar == null) {
 	              if ((progressBar = cc.getControlComponent()) != null) {
             panel.add(progressBar);
             panel.setSize(progressBar.getPreferredSize());
             validate();
         }
         }
     } else if (event instanceof EndOfMediaEvent) {
         // We've reached the end of the media; rewind and
         // start over
         player.setMediaTime(new Time(0));
         player.start();
     } else if (event instanceof ControllerErrorEvent) {
         // Tell TypicalPlayerApplet.start() to call it a day
         player = null;
         Fatal(((ControllerErrorEvent)event).getMessage());
         } else if (event instanceof ControllerClosedEvent) {
         panel.removeAll();
     }
     }
 
 	      void Fatal (String s) {
     // Applications will make various choices about what
     // to do here. We print a message
     System.err.println("FATAL ERROR: " + s);
     throw new Error(s); // Invoke the uncaught exception
                 // handler System.exit() is another
                 // choice.
     
     }
 }

but it produces this error:

load: class basicgui/SimplePlayerApplet.class not found.
java.lang.ClassNotFoundException: basicgui.SimplePlayerApplet.class
	at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:211)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:144)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
	at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:662)
	at sun.applet.AppletPanel.createApplet(AppletPanel.java:785)
	at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
	at sun.applet.AppletPanel.run(AppletPanel.java:368)
	at java.lang.Thread.run(Thread.java:662)

so what is my problem with the code?

This article has been dead for over six months. Start a new discussion instead.