Dynamically load SWF file with Java - java

I want to load SWF file dynamically in my webpage. But I don't know how to do it. Is it possible to load SWF from back-end? In this website Insert SWF into html page I found a way to load SWF, but it is static. I have a database where I will store the paths of the SWF files and load those files dynamically. Is there any way to dynamically change the source of the swf object [ "EMBED SRC="file.swf" ]?
Any information will be very helpful to me. Thank you.

Though I have no personal experience using Wicket, but here's how I understood it should go. Use the AttributeModifier to change the value of the value attribute of the param tag and the src attribute of the movie tag. You also need to give them the Wicket id's on the HTML template to be able to refer them from the Java code. In general the HTML template would look something like this:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
width="300" height="170"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param wicket:id="swfReference1" name="movie" value="" />
<param name="quality" value="high" />
<param name="bgcolor" value="#000000" />
<param name="allowScriptAccess" value="always" />
<embed wicket:id="swfReference2" src="" quality="high" bgcolor="#000000"
width="300" height="170" align="middle"
play="true"
loop="false"
allowScriptAccess="always"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
...
You could also do it on JavaScript level to be even more dynamic by using for instance jQuery to switch the SWF sources. Here's a working example.
$('param[name=movie]').attr('value', 'https://demo.adobe.com/Home.swf');
$('embed').attr('src', 'https://demo.adobe.com/Home.swf');

Related

Display XML in html with CSS style sheet

I have seen numerous ways to display an XML file in a web page (HTML) but haven't come across one that uses a CSS style sheet.
I have an XML file that already has a CSS style sheet. When the .xml is viewed in a web browser, it displays fine with CSS.
I want to display the same XML file in a webpage (HTML), whats the best way to do that?
Thanks.
If you have a separate styled XML document and you want to display it in an HTML page, you could probably use the <object> tag:
<object height="100%" width="100%" border="0" type="text/xml" data="yourfile.xml">
<!-- alternative content used when the inclusion fails -->
</object>
(Tested in FireFox only). Alternatively, an <iframe> could do a similar job.

No Sign of Applet Running from HTML

I put together a java ChatClient and ChatServer on Max OS X Version 10.7.5 for fun with my kids. We were using Java Version Java(TM) SE Runtime Environment (build 1.7.0_04-b21). It runs great from the Terminal. Also, we'd like to able to run it from Eclipse by passing in parameters.
When I open the HTML in Safari 6.0.2., I get no sign of errors or the applet running. In Safari, I have enable plug-ins, Java, and Javascript. Only the text in the HTML is displayed; the applet does not seem to run or anything.
Once I get this working, I would like to package in a JAR file and sign it so I can create a socket to my server. The applet is a simple guy that asks to connect via socket, then sends and receives text from any other clients including itself.
<Html>
<Head>
<Title>Java Example</Title>
</Head>
<Body>
This is my page<br>
Below you see an applet<br>
<br>
<Applet Code="ChatClient" width=200 Height=100>
<PARAM name="host" value="xxxxx-iMac.local">
<PARAM name="port" value="4445">
</Applet>
after Applet
</Body>
</Html>
In section 13.4, the APPLET tag in HTML is deprecated, and it's successor is the <object> element. You should think about a couple things here -
First, abide by HTML standards. This includes having all of your html tags and attributes in lowercase. <PascalCase>, <camelCase> are not standard for HTML.
Second, switch your applet tag to an object.
Thirdly, wrap all text in a block tag other than <body>. Most popular one is <p> meaning paragraph.
Fourthly, wrap ALL html attribute values in double quotes. example: width=200 should be width="200"
Fifthly, think about doing 2 spaced tabs when doing html. it's much cleaner :)
I could go on, but i could be here forever. Bottom line is, follow standards.
But to answer your question:
In the specification, it looks like it expects the file name. this includes ".class" at the end. Try,
<html>
<head>
<title>Java Applet Example</title>
</head>
<body>
<div id="container">
<applet code="ChatClient.class" width="200" height="100">
<param name="host" value="xxxxx-iMac.local" />
<param name="port" value="4445" />
</applet>
</div>
</body>
</html>

Loading a VIEW from the Welcome Page by clicking in an image in Eclipse Java Desktop Application

In the Welcome Page of my Java Eclipse application I keep different images. For this I use the code in the .xhtml file which is as follows:
<div class="icon">
<img src="../icons/account.png" width="64" height="64" />
</div>
Now, I need to load a particular VIEW by clicking on the image of the Welcome Page. Each VIEW has a different Id which is defined in the MANIFEST.MF.
Can anybody help me with the code after <img src="../icons/account.png" width="64" height="64" /> in the XHTML file. I have tried the code that we use for Website application but it did not work.
The best you can do is to invoke an action from a link in the page. this section in the help shows you how to do that.

Java Applets and html page - embedding multiple applets

I have just started to write applets and so have never embedded in a webpage before. I have 2 applets that on there own run fine however when I try to run the 2 applets in the same page only one is visible. This seems very strange I have tried using the opening and closing foo bar tags for each applet.
These applets have no connection to each other however I also found that the html tags were also ignored after the applet which threw the page design out as well, this has totally baffled me.
The code encasing the applets is
<div class="wholeframe">
<div class="lframe3">
<!-- content for left frame to go here -->
<h2>Basic Java Swing Applet</h2>
<br />
<applet code="org.my.form1.MyApplet" archive="java/form1gui/FormApplet1.jar"
height="60" width="250"/>
</div>
<div class="rframe">
<h2>Basic Java Swing Applet</h2>
<applet code="org.me.hello.MyApplet" archive="java/hello/HelloApplet.jar"
width="350" height="150" />
<!-- right frame div end -->
</div> <!-- whole frame to box 2 frames -->
I would be grateful if someone could advise where I have gone wrong as this should be simple to do and I am sure it is but I cannot seem to work out the issue.
The first thing I'd recommend is validating that 'HTML' with the W3C mark-up validation service. The reason I put the HTML in commas is because whatever that mess is pretending to be, it is not (valid) HTML.
(grumbles) Programmers tend to think that whatever rubbish they put in HTML should work. The real world is somewhat removed from this fantasy land.
Other recommendations:
Post a link to the applet, broken or otherwise. If we are feeling motivated, we can visit it, look at the (entire) HTML, download the Jars or classes, and test solutions.
Ensure the Java Console is opened automatically when loading applets. Without the console information, you are debugging this with 'one arm tied behind your back'.
While debugging, reduce the web page to the minimum. No headers, divs, code, CSS etc. Include that stuff once it is working.
To embed more than one applet in a single web page, put each applet in its own subfolder within the folder that contains the HTML document. Use the APPLET tag's CODEBASE attribute to specify the folder that contains the applet.
For example, to embed the applets 'Aplt1' and 'Aplt2' in the web page defined by the file TestAplt.html, you can set up the following files and subfolders in a folder named Test:
Test/TestAplt.html
Test/Aplt1/<Class files for Aplt1>
Test/Aplt2/<Class files for Aplt2>
For files in this structure, put the following APPLET tags in the file TestAplt.html:
<applet codebase="Aplt1/" code=Aplt1 width=16 height=400 align="left">
<param name=ParamAplt1 value="Aplt1.djr">
</applet>
<applet codebase="Aplt2/" code=Aplt2 width=32 height=400 align="right">
<param name=ParamAplt2 value="Aplt2.djr">
</applet>
Please use this link Multiple applets in a page

Two Applets in same page

I am trying to put two applets which share same code base but initialized with different paramaters in same web page.
process goes like this:
applet.jar->create two applet tags, with different parameters, same jar in a page->deploy to server->access the page.
HTML looks like this:
<HTML>
<HEAD>
<TITLE>Java applet example - Passing applet parameters to Java applets</TITLE>
</HEAD>
<BODY>
<APPLET CODE="Applet.class" WIDTH="400" HEIGHT="50">
<PARAM NAME="PURPOSE" VALUE="VIEW">
</APPLET>
<APPLET CODE="Applet.class" WIDTH="400" HEIGHT="50">
<PARAM NAME="PURPOSE" VALUE="MODIFY">
</APPLET>
</BODY>
</HTML>
there is a panel in both applets which display messages...
Now, the problem is messages from one applet are displaying in other one!
This kind of behaviour (and worse) is often caused by mutable statics (sometimes dressed up as singletons). For many reasons, don't use mutable statics.
I think that if you add MAYSCRIPT to the APPLET tag, this will make your applet isolated with the other.
<APPLET CODE="Applet.class" WIDTH="400" HEIGHT="50" MAYSCRIPT>
<PARAM NAME="PURPOSE" VALUE="MODIFY">
</APPLET>
Ok, it's not clean but if you can't change the codebase that's an easy way to fix this thing.

Categories