Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 25 of 25

Thread: How to display .swf files in java code JEditorPane using eclips platform

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation How to display .swf files in java code JEditorPane using eclips platform

    Here attached my java code am trying to display .swf or .fla files from this code but am not able to retrieve .swf or .fla files some one help me....
    Attached Files Attached Files


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    am not able to retrieve .swf or .fla files
    Please explain what "not able to retrieve" means?

    Post the code with the problems here on the forum. Be sure to wrap the code with code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    I want to display .swf or .fla files in window_pane or jpanel when i click on browse i can able to select .swf and .fla files but when i select it and open it will not display in panel please help me...i had attached my code also...

    Thanking you

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    What classes and packages are you trying to use to display those types of files?

    Post your code here in line (not as attachment) if you have questions about it.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    import javax.swing.*;
    import java.io.*;
    import java.net.MalformedURLException;
    import java.awt.*;
    import java.awt.event.*;
     
    public class DisplaySWF extends JFrame 
    {
    	public JPanel  window_panel;//address_panel,
    	public JLabel address_label;
    	public JTextField address_tf;
    	public JEditorPane window_pane,tree_pane,attr_pane;
    	public JScrollPane window_scroll,tree_scroll,attr_scroll;
    	TextArea t1,t2;
    	JPanel pane;
    	public JButton address_b, browse;
    	public JLabel l,m;
    	private Go go = new Go();
    	JFrame f ;
    	public DisplaySWF() throws IOException
    	{
     
    	f= new JFrame("Web browser");
    	f.setSize(1000,700);
     
    	pane=new JPanel();
    	pane.setVisible(true);
    	pane.setLayout(null);
    	f.setContentPane(pane);
     
     
    	address_label = new JLabel(" address: ", SwingConstants.CENTER);
    	address_label.setBounds(10, 10, 70, 30);
    	pane.add(address_label);
     
    	address_tf = new JTextField("",25);
    	address_tf.setBounds(80,10,250,30);
    	pane.add(address_tf);
     
    	browse = new JButton("Browse");
    	browse.setBounds(340, 10, 140, 30);
    	browse.addActionListener(go);
    	pane.add(browse);
     
    	window_pane=new JEditorPane();
    	window_pane.setBounds(10, 50, 600, 600);
    	pane.add(window_pane);
     
     
     
    	l=new JLabel("DOM Structure");
    	l.setBounds(650,30,100,10);
    	pane.add(l);
    	t1=new TextArea();
    	t1.setBounds(650,50,300,250);
    	pane.add(t1);
     
    	m=new JLabel("Attribute");
    	m.setBounds(650,350,100,10);
    	pane.add(m);
    	t2=new TextArea();
    	t2.setBounds(650,380,300,280);
    	pane.add(t2);
     
    	f.setVisible(true);
    	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
     
    	window_pane = new JEditorPane("http://www.yahoo.com")
    	{
            public boolean getScrollableTracksViewportWidth() 
            {
            	return true;
        	}
    	};
     
     
    }
    public class Go implements ActionListener
    {
    		public void actionPerformed(ActionEvent ae)
    		{
    			JFileChooser fc = new JFileChooser();
    			int result = fc.showOpenDialog(null);
    			if (result == JFileChooser.APPROVE_OPTION)
    			{
    				File file = fc.getSelectedFile();
    				String sname = file.getAbsolutePath(); 
    				address_tf.setText(sname);
    				String ext=getFileExtension(sname);
     
     
    				try 
    				{
    					if(ext.equals("swf"))
    					{
    						window_pane.setPage(address_tf.getText());
    						System.out.println("hi");
    					}
    				} 
    				catch (MalformedURLException e) 
    				{     // new URL() failed
    					window_pane.setText("MalformedURLException: " + e);
    				}
    				catch (IOException e)
    				{               // openConnection() failed
    					window_pane.setText("IOException: " + e);
    				}
    			}
    		}
    }
       public String getFileExtension(String filename)
        {
    	if (filename == null)
    	{
                return null;
    	}
    	int lastUnixPos = filename.lastIndexOf('/');
    	int lastWindowsPos = filename.lastIndexOf('\\');
    	int indexOfLastSeparator = Math.max(lastUnixPos, lastWindowsPos);
    	int extensionPos = filename.lastIndexOf('.');
    	int lastSeparator = indexOfLastSeparator;
    	int indexOfExtension = lastSeparator > extensionPos ? -1 : extensionPos;
    	int index = indexOfExtension;
    	if (index == -1) 
    	{
    		return "";
    	} 
    	else
    	{
    		return filename.substring(index + 1);
    	}
    }
     
    public static void main(String args[]) throws IOException
    {
      DisplaySWF wb = new DisplaySWF();
    }
    }

    --- Update ---

    please find the code above....
    Last edited by chetu7845; April 28th, 2014 at 08:48 AM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Does it say anything in the API doc for the classes you are using about displaying SWF files?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    problem is that file is not loading properly while when i browse..please help me

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    file is not loading properly
    Please explain what it means to "load properly".

    Why do you think the code you have posted is capable of displaying swf files?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    ya,when i click on browse i can able to select the .swf file but when i select and click on open it will not display, when debug and check it has problem in below line
    if(ext.equals("swf"))
    					{
    						window_pane.setPage(address_tf.getText());
    						System.out.println("hi");
    					}

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    it will not display
    What is supposed to be displayed?

    Have you tried the code with a simple html file to see if it is displayed?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    ya i tried html files but i didn't get .swf files contains some images it has to be display....

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    i tried html files
    Did they display as you expected?

    Why do you think java will display swf files?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    Am not able to display html file also...swf files am using for the purpose of to find properties of the image i mean height,width and pixel. this is my college project as my professor expect i have to show please help me.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    not able to display html file
    First work on getting something simple like an html file to display.
    Make sure you get the full text of any error messages by calling the printStackTrace() method in the catch blocks.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    There are 3 immediate problems that you need to fix first.

    1. Multiple JEditorPane instantiations

    In your code you have:
    Quote Originally Posted by chetu7845 View Post
    ...
    window_pane=new JEditorPane();
    window_pane.setBounds(10, 50, 600, 600);
    pane.add(window_pane);
    ...
    window_pane = new JEditorPane("http://www.yahoo.com")
    {
        public boolean getScrollableTracksViewportWidth() 
        {
            return true;
        }
    };
    ...
    The 2nd JEditorPane instantiation is unnecessary, in fact it causes problems for #2 below. Remove it.

    2. Lack of stack trace display
    Quote Originally Posted by chetu7845 View Post
    ...
    public void actionPerformed(ActionEvent ae)
    {
        JFileChooser fc = new JFileChooser();
        int result = fc.showOpenDialog(null);
        if (result == JFileChooser.APPROVE_OPTION)
        {
            File file = fc.getSelectedFile();
            ...				
            try 
            {
                if(ext.equals("swf"))
                {
                    window_pane.setPage(address_tf.getText());
                    System.out.println("hi");
                }
            } 
            catch (MalformedURLException e) 
            {     // new URL() failed
                window_pane.setText("MalformedURLException: " + e);
            }
            catch (IOException e)
            {               // openConnection() failed
                window_pane.setText("IOException: " + e);
            }
        }
    }
    ...
    Make it a habit during development to always print out the stack trace to standard error via e.printStackTrace(), or log the exception stack trace into a file. Because of #1 above, the exception that is thrown in the code above is not set into window_pane. Consequently, the code fails silently.

    3. JEditorPane.setPage() requires a URL

    The exception mentioned in #2 is a MalformedURLException. This is thrown by
    window_pane.setPage(address_tf.getText());
    Make the Java API docs your friend. In this case the relevant doc page is JEditorPane (Java Platform SE 7 ). You'd see that there are 2 versions of the setPage() method:
    • setPage(String url)
    • setPage(URL page)

    Either way you need to provide it a URL, in String form or a URL object, and not a file path. Since you already have obtained a File object earlier via File file = fc.getSelectedFile(), you can simply set the page using
    window_pane.setPage(file.toURI().toURL());

    After you have fixed the above, as Norm suggested, try to display a simple HTML file first. This implies you need to either modify or temporarily remove
    if (ext.equals("swf"))

    Btw note that you can set up JFileChooser to filter and display just the types of files that are of interest. See How to Use File Choosers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components).

  16. The Following User Says Thank You to jashburn For This Useful Post:

    chetu7845 (April 28th, 2014)

  17. #16
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    Thank you so much for your help...now i can able to retrieve html files but when i choose swf files it will display in byte codes....what to do help me ???

    --- Update ---

    [QUOTE=jashburn;146529]ou so much for ypur help...now i can able to see html files but when i choose swf it will show in byte code format it will not show swf file images...please help me...

    Thank you

  18. #17
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    You should first become familiar with the capabilities of the Components you are using (usually by reading the API docs). Presuming 'swf'/'fla' are referring to a Adobe flash media - at this time JEditorPane does not have this capability, which from glancing at all the posts above seems to be what you are trying to do.

  19. #18
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    Quote Originally Posted by chetu7845 View Post
    when i choose swf it will show in byte code format it will not show swf file images
    Please elaborate on how you'd like it to work. E.g., do you want to display the swf file as if it was in a browser? I see on the GUI there are sections for DOM Structure and Attribute. How will they be used?

    copeg is right that JEditorPane does not support swf. JEditorPane (Java Platform SE 7 ) lists the supported content types. Therefore the solution (if exists) depends on the answers to the questions above.

  20. The Following User Says Thank You to jashburn For This Useful Post:

    chetu7845 (April 29th, 2014)

  21. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    Don't browsers require a plugin for swf, etc?
    If you don't understand my answer, don't ignore it, ask a question.

  22. #20
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    Quote Originally Posted by jashburn View Post
    Please elaborate on how you'd like it to work. E.g., do you want to display the swf file as if it was in a browser?.
    Demo.jpg

    The above output is am getting now...actually i need to display swf image files in that window_pane and in DOM structure pane and Attribute pane Suppose i need to display properties of the swf image file means pixel,height and width.
    Last edited by chetu7845; April 29th, 2014 at 02:34 AM.

  23. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    i need to display swf image files
    What packages and classes do you have for displaying swf files? There are none in standard java to do that.
    properties of the swf image file
    What packages and classes do you have that will get that information from a swf file?
    If you don't understand my answer, don't ignore it, ask a question.

  24. #22
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    Quote Originally Posted by Norm View Post
    What packages and classes do you have for displaying swf files? There are none in standard java to do that.
    I found swf package in below link, but not working
    JavaSWF9 - Java for SWF library | A.Quarter.To.SevenA.Quarter.To.Seven

  25. #23
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    Quote Originally Posted by chetu7845 View Post
    actually i need to display swf image files in that window_pane and in DOM structure pane and Attribute pane Suppose i need to display properties of the swf image file means pixel,height and width.
    Please reconfirm that it is SWF files that you need to deal with, and not SVG files. Also, please elaborate on the aim of this college project - what your prof expects you to learn from this project. I'm asking because I'm struggling to see what you might want to put into the DOM structure pane, but if it is SVG that you need to deal with, then it makes complete sense.

    If you're 100% sure that you need to work with SWF, then Transform SWF For Java might be of help. It is a library that can read/write SWF files. Since you mentioned "image", I'm assuming you'll need to extract image(s) from the file, in which case do an Internet search using the search term "extract frame|image site:flagstonesoftware.com". E.g., one of the results from my search is Flagstone Software - View topic - Extract a frame to Java BufferedImage. You can also widen your search using the search term "java flagstone transform swf extract".

  26. #24
    Junior Member
    Join Date
    Apr 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default how to display .swf files in editor pane?

    i need to display my .swf files in editor pane in which in my window pane consistes of dom struture and attribute ,editorpane in url bar when we browse a .swf file .then we need to display a swf or fla on the editor pane and in dom structure it displays the subtree of the image (which we can edit in the flash cs3) and in in attribute label we need to display the properties of perticular label like x,y,width,hieght, either we need to display the fla files (which is editable ),actually we need the properties of either fla or swf files for segmentation purpose please sir/madam get me a solution
    Last edited by chetu7845; April 29th, 2014 at 12:27 PM.

  27. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to display .swf files in java code JEditorPane using eclips platform

    Those requirements are NOT part of standard java. You will need to use packages from other sources to do it.
    Several links have been provided to other sites that might be useful for you.


    New thread merged with old.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Extract Files from SWF (Flash) file
    By taps in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: March 6th, 2014, 06:54 AM
  2. Replies: 8
    Last Post: October 3rd, 2012, 11:48 AM
  3. JDIC init Exception while running Flash files (.swf) through Java Swings
    By kushima@gmail.com in forum AWT / Java Swing
    Replies: 1
    Last Post: March 1st, 2012, 05:40 AM
  4. Replies: 15
    Last Post: September 2nd, 2011, 05:05 PM

Tags for this Thread