Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



JAVA: Image and Video in JFrame

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 30-08-2010
Member
 
Join Date: Apr 2010
Posts: 74
JAVA: Image and Video in JFrame
  

I want to put a background picture of my JFrame, and I have also tried to do lot of changes in my coding but then also I am not getting an appropriate results. So I thought that you guys may provide some needful help. Please tell me how can I insert the background images in JFrame. Also I am interested in inserting videos in JFrame. In short, I want to know about the Image and Video in JFrame. I am expecting some quicker help from your side.

Reply With Quote
  #2  
Old 30-08-2010
Member
 
Join Date: May 2008
Posts: 2,290
Re: JAVA: Image and Video in JFrame

Since, you have mentioned that you have tried to do lot of changes in your coding, I am sure that you are having sample of it. It would be easy for us to explain you according to your coding. So I would like to tell you that you should provide some sample of your coding while posting the query, due to which we can feel easy to respond. I hope that you will post your sample of coding soon to get the proper solutions.
Reply With Quote
  #3  
Old 30-08-2010
Member
 
Join Date: Apr 2010
Posts: 74
Re: JAVA: Image and Video in JFrame

Quote:
Since, you have mentioned that you have tried to do lot of changes in your coding, I am sure that you are having sample of it. It would be easy for us to explain you according to your coding.
I am sorry, for not providing the coding. I have the following code, but I want the image covers only the halves of my JFrame .. what should I change it to fit as I want?

Code:
import java.awt.Dimension; 
import java.awt.Graphics; 
import java.awt.Image; 

Import javax.swing.ImageIcon; 
import javax.swing.JFrame; 
import javax.swing.JPanel; 

(public class ImageTest 

public static void main (String [] args) ( 
ImagePanel panel = new ImagePanel (new ImageIcon ("images / background.png"). GetImage ()); 

JFrame frame = new JFrame (); 
frame.getContentPane (). add (panel); 
frame.pack (); 
frame.setVisible (true); 
) 
) 

ImagePanel class extends JPanel ( 

private Image img; 

Public ImagePanel (String img) ( 
this (new ImageIcon (img). getImage ()); 
) 

Public ImagePanel (Image img) ( 
this.img = img; 
Dimension size = new Dimension (img.getWidth (null), img.getHeight (null)); 
setPreferredSize (size); 
setMinimumSize (size); 
setMaximumSize (size); 
setSize (size); 
setLayout (null); 
) 

public void paintComponent (Graphics g) ( 
g.drawImage (img, 0, 0, null); 
) 

)
Please help me as soon as possible.
Reply With Quote
  #4  
Old 30-08-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: JAVA: Image and Video in JFrame

Is that you change this:
Code:
 public void paintComponent (Graphics g) ( 
 g.drawImage (img, 0, 0, null); 
 )
Also I would like to recommend you to check the settings for the Graphics2D class. Because many times settings in the Graphics2D causes the problem.
Reply With Quote
  #5  
Old 30-08-2010
Member
 
Join Date: Apr 2008
Posts: 2,000
Re: JAVA: Image and Video in JFrame

Here is the code to play an AVI in a JFrame:
Code:
 java.awt.BorderLayout;
 import java.awt.Dimension;
 import java.io.File;

 import javax.swing.JFrame;

 org.pulsar.media.AVFormatContext import;
 import org.pulsar.media.MediaManager;
 import org.pulsar.media.player.IVideoRenderer;
 import org.pulsar.media.player.Java2DRenderer;
 import org.pulsar.media.player.MediaPlayer;
 import org.pulsar.media.protocol.FileProtocol;

 public class PlayMovieFile (

 public static void main ( String [] args) (
 / / Requires pulsar_media.dll library
 Media Manager. InstallNativeLibrary (true);

 / / Enable file protocol
 Media Manager. GetInstance (). Register Protocol (FileProtocol. URL_PREFIX,
 FileProtocol. FACTORY);

 / / Create frame Swing
 JFrame frame = new JFrame ();
 frame. setSize (new Dimension (480, 300));
 . Frame setLayout (new BorderLayout ());
 frame. setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE);

 / / Add Java2D-based video renderer to Swing frame
 final IVideoRenderer renderer = new Java2DRenderer ();
 frame. add (renderer. getVisualComponent ());

 / / Show frame
 frame. setVisible (true);

 / / Open movie file & find stream info (resolution, audio channels ,...)
 Context = AVFormatContext AVFormatContext format. OpenFile (FileProtocol
 . ComputeUrl (new File ("samples / elephantstrial.avi")));
 Context format. findStreamInfo ();

 / / Create media player
 Final Media Player player = new MediaPlayer (renderer);
 player. open (format Context);
 )
 )
That looks a whole lot from it simpler than JMF has with me and works perfectly under Ubuntu 8.04.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "JAVA: Image and Video in JFrame"
Thread Thread Starter Forum Replies Last Post
Segment an image in java Logan 2 Software Development 7 19-04-2010 12:15 AM
Insert Music in JFrame From Java D_chapple Software Development 5 05-03-2010 09:49 AM
Disabling the Close Button on a JFrame in Java technika Software Development 5 24-02-2010 09:51 PM
Java program to center a JFrame on screen KALANI84 Software Development 5 13-02-2010 04:48 PM
How to change JFrame image icon? Juany Software Development 4 08-02-2010 03:39 PM


All times are GMT +5.5. The time now is 06:20 PM.