I've written a Java Applet (in Eclipse, if that makes any difference) and embedded it in a local HTML file (which I will include). The applet code shouldn't be necessary because the problem lies in my HTML. The local HTML file works fine on Chrome, but Chrome is ending support for Java soon, so I'm trying to use the file on Safari. Theoretically, it should all function the same, but the Safari throws a ClassNotFoundException, while Chrome still runs it smoothly. The error reads "ClassNotFoundException", and the detail reads "chaos.chaos.class" (see HTML). (If it's relevant, I'm on OS X 10.10.3, with fully updated everything (I believe)) And, apparently, I'm not allowed to post pictures, so I shall verbally describe the layout of my folders. The HTML file is in the same directory as another directory called 'chaos'. Inside this directory are the 'chaos.jar' and 'chaos.class' referenced in my code, along with 'Shape.class' which is not referenced but is necessary for the applet to run (it's referenced by one to the other files). Thank you in advance for any and all help and suggestions.
UPDATE: I have also tried the HTML file on Firefox, and it works seamlessly there too. But I don't really like Firefox all that much, so I'm still searching for the answer.
<html>
<head>
<title>
The Chaos Game
</title>
</head>
<body align="center">
<blockquote>
<applet code="chaos.chaos.class"
archive="chaos.chaos.jar"
width=900 height=900
title="Chaos">
</applet>
</blockquote>
<br/>
<font size = "3">
Written by ...
</font>
</body>
</html>
Related
I try from a long time ago to launch Java applets in browser (they are simple games). For a long time it say out-of-date Java version (now have the latest version 8 update 45), even after I install the latest before 2 min. NVM, I hope I fixed it. Now it say a lot of different errors: runtime exception or AccessControlExeption for ex.
I am running this programs in Eclipse and I tried them, so they work. Maybe I have a problem with HTML code.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<canvas id="canvas-id" ></canvas>
</body>
<applet width="600" height="170" code="theLightRoute.class"></script>
</applet>
</html>
First: your HTML code is not valid, remove the </script> closing tag inside your <applet/> section. Even if some browsers can accept it, I don't think you can expect to have a valid result with an invalid tag definition.
Second: the <applet/> tag support can vary regarding the browser (see http://www.w3schools.com/tags/tag_applet.asp). You should try with <object/> instead (see http://www.w3schools.com/tags/tag_object.asp)
Third: you cannot expect anymore that any modern web browser will support a java applet, whatever the tag you use. Indeed, most of them have dropped or disabled by default the browser-side support of any java applet for security reasons. For example for Chrome 42, the java support is totally dropped: http://www.infoq.com/news/2015/04/chrome-42-npapi. For Firefox or safari it should be enabled manually https://support.mozilla.org/en-US/kb/how-allow-java-trusted-sites).
Actually, there is no good reason to create some java applet anymore, it's a totally deprecated and obsolete technology (https://softwareengineering.stackexchange.com/questions/154537/do-java-applets-have-any-place-on-the-web-today).
Try to learn HTML5 for game programming instead :-) Many courses exist and can help you, and many HTML5 game engine are available (http://html5gameengine.com/). And it is cross-platform, mobile included!
Have just finished programming my first Java Applet. How can I share this with my friends without them using eclipse on my computer?
I have 12 classes in eclipse. I have seen some examples of people using HTML to embed their applet in a website, but
A) I have only found examples with only one class.
B) I tried following this method: http://www.oxfordmathcenter.com/drupal7/node/37
but when I click on the html file, it just opens the html code in my browser, not the applet.
This is the HTML file that I made
<html>
<head>
<title>
World Cup Game
</title>
</head>
<body>
<h2>World Cup Game</h2>
<applet
codebase=“https://www.dropbox.com/s/lcojvh8tm2mukzn”
archive = “WorldCup.jar”
width = 800 height = 600>
</applet>
</body>
</html>
I don't mind whether I share it embedded on a web page or if I send them an executable jar file or whatever, but does anyone know how I can share my hard work!? Thanks :)
(Apparently executable jar file isn't an option with applets though...)
Of course it is an option:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>My Applet Page</html>
</head>
<body>
<applet code="ClassFile.class" archive="YourJar.jar" width="400px" height="400px">
Java is not installed on your machine or your browser does not allowed Java Applet to run<br /><br />Get the latest Java technology at http://www.java.com/
</applet>
</body>
</html>
But I would not use that. Servlets are much better idea. Applets are client side thing if you do something that do not have to be processed on back-end why not but I did not see any applets for couple of years...
If you dont see your applet then probably you have public static void main(String[] args) instead of public void init() that also could make you problems
The basic Problem about applets are that they need jvm oriented browsers to run.
due to this reason applets(java) failed. today servlets are considered. you would need eclipse or any jvm for your browser to run..
I read already a lot of topics like this or this on stack overflow without no luck.
So what is going on. I have an applet that I created in Netbeans. It works fine until I insert an image in it as icon. My os is MAC and I use Firefox.
In Netbeans the applet looks ok when I run it. The problem is that in Firefox I see just a gray BOX instead of my applet.
Does anyone have any idea what is going on here?
So my HTML file looks like that:
<HTML>
<HEAD>
<TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>
<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
<P>
<APPLET codebase="classes" code="slipapplet/SlipApplet.class" width=880 height=650 archive="/Users/Serial/NetBeansProjects/SlipApplet/build/classes/slipapplet/swing-layout-1.0.4.jar,/Users/Serial/NetBeansProjects/SlipApplet/build/classes/slipapplet/AbsoluteLayout.jar"></APPLET>
</P>
<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>
This is code about the label with icon in java:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Users/Serial/NetBeansProjects/SlipApplet/src/slipapplet/kemp.jpg")));
And the HTML file is in an upper file then everything else..
I am trying to embed a swing applet into our website, but it is not working. I have been able to get applets that use awt to do graphics to work. The web page that contains the applet only shows a blank box that should contain my applet, there aren't even any error messages. My applet works fine in netbeans. The applet is supposed to show a few buttons and a text field. I really don't know whats going on.
The web page is located at http://nuevawave.org/sandbox/JavaGallery/GUIApplet.html
The applet is at http://nuevawave.org/sandbox/JavaGallery/TestApplet.jar
Here is the html:
<html>
<head>
<title>Test Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<applet Archive ="TestApplet.jar, swing-layout-1.0.4.jar"
Code="test.GUIApplet"
WIDTH="250" HEIGHT="300" >
</applet>
</body>
</html>
as I wrote in the comments it works for me (I'm using OpenJDK 1.6.0_22, Linux (ubuntu) and Firefox).
If java works from your "command line" or terminal. I could be that the plugin for your browser isn't installed. I would recommend you reinstalling the JDK or JRE and remember to install the plugin for the browser aswell.
You can use the <object> tag instead. To know how to use this, check this link
This is my JSP file.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
//JFileChooser filechoose = new JFileChooser();
JFileChooser filechoose = new JFileChooser("D:\\");
filechoose.showOpenDialog(null);
File file = filechoose.getSelectedFile();
XLCauHoi.ImportXmlFileToData(file);
%>
<h4> Đã xuất file thành công </h4>
</body>
</html>
My problem is that: the JFileChooser pops up 2 times when I run it on browser. If I run it in a Java class, JFileChooser pops up 1 time.
What is my problem and how to solve it?
There's a major misconception here. First thing, JSP/Java runs at the webserver, produces a bunch of HTML/CSS/JS and sends it to webbrowser. Webbrowser retireves HTML/CSS/JS and interprets/applies/executes it. It doesn't run any line of Java code because it has already been executed on the webserver. Rightclick page in webbrowser and choose View Source. Do you see it? If webserver has done its job right, you should not see any line of Java code in there. The webbrowser namely doesn't understand it. It only understands HTML/CSS/JS.
Using a JFileChooser in a JSP scriptlet would technically only "work" when both the webserver and webbrowser runs at physically the same machine. It's basically the webserver which displays the dialog, not the webbrowser. This would only "work" when you're locally developing, but never when you publish the website into world wide web by a standalone webserver.
To upload files by HTML, you need an <input type="file"> element, not a JFileChooser. For more detail how to use it with JSP/Servlet, check this answer.
As to the concrete problem, I have no idea why it pops 2 times, but that should be your least concern in this particular case.