Reputation: 213
I'm trying to get a Java Applet to display on a webpage. The applet runs in Eclipse, but does nothing on the webpage. For reference here is the applet (no, it's not complete):
package TestProg.webClient;
import java.applet.Applet;
import java.awt.*;
public class UserLogin extends Applet {
String accountId = "";
public void init() {
TextField username = new TextField(10);
TextField password = new TextField(10);
Button login = new Button(" Log In ");
add(username);
add(password);
add(login);
}
}
And here is the HTML code:
<body>
<center>
<div id="title"><h1>UserLogin</h1></div>
</center>
<applet code="sp.jar" width="400" height="100" alt="This isn't working"></applet>
</body>
I've also tried embedding with <object>
and <embed>
, have tried with both Chrome and Firefox on a Linux machine, and for some reason took the .class file out of the .jar and tried that.
Absolutely nothing displays on the webpage.
Any help would be greatly appreciated. Richard
Upvotes: 1
Views: 3076
Reputation: 213
I discovered what the problem was, and there seems to be a severe lacking of this knowledge out there....
The HTML tag should look like this...
<applet code=NameOfPackage.NameOfApplet archive=NameOfApplet.jar width=300 height=300>
Thanks to all who helped...
Upvotes: 4
Reputation: 305
If you don't need it on the site, you could wrap it using http://launch4j.sourceforge.net/ and providing a link to download the executable you made. Perhaps wrap it as an exe than modify the java code to submit values to the server. Then, tell the user to reload the page if the server responds that it received the information. Sorry, it is a clumsy workaround- but it might work.
Upvotes: 0
Reputation: 34533
Can the code attributte be a .jar ? Everything in the right directory?
Try something like this:
<applet code=NameOfApplet.class name=NameOfApplet archive=NameOfApplet.jar
width=300 height=300>
<param name="bgcolor" value="ffffff">
<param name="fontcolor" value="000000">
Your browser is not Java enabled.
</applet>
Upvotes: 1
Reputation: 497
Have you installed the pluging for java on yout browser ?
http://www.oracle.com/technetwork/java/index-jsp-141438.html
Upvotes: 0
Reputation: 4637
Try adding a Jpanel before you add your button and text box.
JPanel panel = new JPanel();
Container content = getContentPane();
content.setLayout(new GridBagLayout()); // Used to center the panel
content.add(panel);
Upvotes: 0