Pergunta

I have made a simple game, it is a state based game meaning I have many different states (screens) such as the start-up screen, menu screen and the actual game, my menu screen is boring at the moment and I want a portion of it to be a video without any controls so it looks like its an animation built into the game, I looked into JMF and found that you only need the following code for it to work(note that I have removed the controls which were in the original code I had found so it is just the video left):

EIDT: The code is shown with comments explaining the error messaged:

    package javagame;

import java.awt.BorderLayout;
import java.awt.Component;
import java.net.URL;

import javax.swing.JFrame;

public class mediaPlayer extends JFrame
    {
        public mediaPlayer()
        {
            setLayout(new BorderLayout());


            URL mediaURL = //Whatever

            Player mediaPlayer = Manager.createRealizedPlayer(mediaURL);
            //Player cannot be resolved as a variable
            //mediaPlayer cannot be resolved as a variable
            //Manager cannot be resolved



            Component video = mediaPlayer.getVisualComponent();
            //The method getVisualComponent() is undefined for thetype mediaplayer
            add(video,BorderLayout.CENTER);

        }
    }

I had made a new class called mediaPlayer and put the above code in it, it extends JFrame but I am getting errors under things like player, mediaplayer and manager saying things like make methods for this, make class for this, make variable for this, I thought that this would work without errors as it extends JFrame and all of the methods, class's and variables required are already made, am I wrong about this?

Foi útil?

Solução

..am I wrong about this?

Yes, you are. The only methods that are automatically included in a frame are those defined for it.

The methods you are talking about, are part of the JMF. Those classes need to be imported at the top of the code. Something like:

import javax.media.*;

Outras dicas

Make sure you download Java Media Framework. Add the jar to a folder called lib in your project. Right click on the jar and add it to the build path. Then your import should work.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top