Ask your own question, for FREE!
Computer Science 19 Online
OpenStudy (anonymous):

Java: If anybody can teach me how to run a video in a JFrame, let me know :D

OpenStudy (jagatuba):

Here is an example that you can play around with. This is straight from the horse's mouth (Oracle): import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; import java.awt.Color; import java.awt.Font; import java.io.File; import javax.swing.*; import javax.media.*; class Play extends JFrame { private static final long serialVersionUID = 1L; private static JPanel playVideoPanel; private static JLabel displayLabel1; private static Timer timer; private static Player player; private static JPanel videoPanel; public void playGUI(){ JFrame frame= new JFrame(); playVideoPanel = new JPanel(); playVideoPanel.setBounds(0, 0, 1024, 768); playVideoPanel.setLayout(null); // Label to show the Text displayLabel1 = new JLabel( "Playing The Video"); displayLabel1.setBounds( 50, 150, 800, 50);///, displayLabel1.setFont( new Font("Serif", Font.BOLD, 36 )); // Adding video clip to the JPanel screen videoPanel=new JPanel(); try{ player = Manager.createRealizedPlayer(new MediaLocator( new File("C://DELTA.mpg").toURL() ) ); videoPanel.add(player.getVisualComponent()); videoPanel.setBounds( 30, 215, 500, 400 ); final Control controls[]=player.getControls(); player.start(); add(player.getControlPanelComponent()); }catch(Exception ee){} playVideoPanel.add(displayLabel1); frame.add(playVideoPanel); frame.add(videoPanel); //setSize(1024, 768); timer = new Timer(10000, new AutoTimer()); timer.start(); frame.setUndecorated(true); frame.setSize(1024, 768); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setVisible(true); } // this will display the main screen after playing the video class AutoTimer implements ActionListener { public void actionPerformed(ActionEvent e) { } } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { Play play= new Play(); play.playGUI(); } }); } }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!