Results 1 to 5 of 5

Thread: JAVA: Image and Video in JFrame

  1. #1
    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.

  2. #2
    Join Date
    May 2008
    Posts
    2,302

    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.

  3. #3
    Join Date
    Apr 2010
    Posts
    74

    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.
    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.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,394

    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.

  5. #5
    Join Date
    Apr 2008
    Posts
    2,010

    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.

Similar Threads

  1. Segment an image in java
    By Logan 2 in forum Software Development
    Replies: 7
    Last Post: 19-04-2010, 12:15 AM
  2. Insert Music in JFrame From Java
    By D_chapple in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 09:49 AM
  3. Disabling the Close Button on a JFrame in Java
    By technika in forum Software Development
    Replies: 5
    Last Post: 24-02-2010, 09:51 PM
  4. Java program to center a JFrame on screen
    By KALANI84 in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 04:48 PM
  5. How to change JFrame image icon?
    By Juany in forum Software Development
    Replies: 4
    Last Post: 08-02-2010, 03:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •