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....
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.
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....
Please explain what "not able to retrieve" means?am not able to retrieve .swf or .fla files
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.
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
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.
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.
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.
problem is that file is not loading properly while when i browse..please help me
Please explain what it means to "load properly".file is not loading 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.
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"); }
What is supposed to be displayed?it will not display
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.
ya i tried html files but i didn't get .swf files contains some images it has to be display....
Did they display as you expected?i tried html files
Why do you think java will display swf files?
If you don't understand my answer, don't ignore it, ask a question.
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.
First work on getting something simple like an html file to display.not able to display html file
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.
There are 3 immediate problems that you need to fix first.
1. Multiple JEditorPane instantiations
In your code you have:
The 2nd JEditorPane instantiation is unnecessary, in fact it causes problems for #2 below. Remove it.
2. Lack of stack trace display
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
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:window_pane.setPage(address_tf.getText());
- 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).
chetu7845 (April 28th, 2014)
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
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.
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.
chetu7845 (April 29th, 2014)
Don't browsers require a plugin for swf, etc?
If you don't understand my answer, don't ignore it, ask a question.
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.
What packages and classes do you have for displaying swf files? There are none in standard java to do that.i need to display swf image files
What packages and classes do you have that will get that information from a swf file?properties of the swf image file
If you don't understand my answer, don't ignore it, ask a question.
I found swf package in below link, but not working
JavaSWF9 - Java for SWF library | A.Quarter.To.SevenA.Quarter.To.Seven
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".
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.
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.