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>
Related
I'm pretty new to HTML and trying to figure the following error:
I'm using netbeans (7.4) and I am trying to make a Web project with Servlets. When I use the defaults that we are instructed to use (yes it's a homework assignment, but my issue is ancillary to the actual assignment, so I don't think I'm trying to cheat here), Java 5 EE, it creates index.jsp. If I write HTML in that .jsp file, such as
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head> <title>Foo</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="http://localhost:8084/MyProject/MyClass" method=GET>
How many Foos and Bars?
<select name="Foo">
<option value="1">1</option>
<option value="2">2</option>
</select>
<select name="Bar">
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
</body>
</html>
it works perfectly fine. However, we are told to use .html files instead of .jsp files, and when I copy this file over (from a .jsp to a .html), without the following line (which causes it's own error if included)
<%#page contentType="text/html" pageEncoding="UTF-8"%>
then Netbeans tells me:
"Text not allowed in element 'form' in this context"
So how do I get text in-between some of my form-fields, when it is an HTML document, not a .jsp?
Put your text inside <p> tags. Browsers are awfully forgiving (this HTML file works fine in Firefox), but free-floating text should be captured inside appropriate container elements (generally, <p>, <div>, or the HTML5 semantic elements).
I'm trying to embed svg images in the HTML, they don't appear to be working with the or tag. Does anyone know how to do this?
Swing support only a subset of HTML/CSS/JavaScript.
JavaFX has better support as shown here.
like this:
</head>
<body>
<object width="700" height="200" data="fileName.svg"></object>
</body>
</html>
I have very little experience with HTML and applets. I have tried several of the things I found online, but am unable to make my Java applet run in a web browser (it functions in eclipse).
I have put the HTML file in the same folder as all of my Java class files for the applet. I am currently using Safari, but would like the applet to work in most any popular browser.
How can I display a java applet on a webpage using HTML/JavaScript? Can anyone offer any tips/advice?
Below is my attempted HTML code.
Attempt 1:
<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>
<Body>
<br>
<br>
<embed code="PendulumApplet.class"
width="200" height="200"
type="application/x-java-applet;version=1.5.0"
pluginspage="http://java.sun.com/j2se/1.5.0/download.html"/></embed>
</Body>
</Html>
Attempt 2:
<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>
<Body>
<br>
<br>
<OBJECT
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="200" height="200">
<PARAM name="code" value="Applet1.class">
</OBJECT>
</Body>
</Html>
Try below code
<APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt>
</APPLET>
OR
<object width="400" height="400" data="helloworld.class"></object>
Good Luck...
Use deployJava.js to write the applet element. The script is supported by Oracle, and will:
Check the user has the minimum required Java, prompting them to install if not, before..
Writing the object/embed or applet element as is best known for that browser.
Other notes:
Is it PendulumApplet.class or Applet1.class? It is hard enough to debug problems on international forums without introducing doubt about the name of the applet class.
The .class extension in the code attribute is tolerated, but not correct. The value should be a string representing the Fully Qualified Name of the class. E.G. javax.swing.JApplet as opposed to javax.swing.JApplet.class.
HTML element names should be all lower case (e.g. <html> as opposed to <Html>)
What output do you see in the Java console? When debugging applets in a browser, it is vital ensure the Java Control Panel is configured to pop open the console on discovering an applet (or JWS app.).
Although I have not done so myself, my Java textbook provides this outline for an embed:
<applet
code = "ClassName.class"
width = 250
height = 50
[archive = archivefile]
[vspace = vertical_margin]
[hspace = horz_margin]
[algin = applet_alignment]
[alt = alt_text]
>
</applet>
(Optional parameters in brackets)
I was having this SAME issue myself.
Using <applet code=""></applet> doesn't work, but <Applet> or <APPLET> seems to work.
Google Chrome and IE.
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
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.