Reputation: 488
I've been trying to get the output of my java program to be displayed on a web page. I've tried applets but the tags for html don't seem to be supported in chrome. Sorry if I'm not giving enough information it's my first question.
Here's my Java code ->
import java.applet.*;
import java.awt.*;
public class MainController extends Applet{
public void paint(Graphics g){
String[] places = {"words", "wordz","wordsz"};
String selected = places[(int)(Math.random() * places.length)];
g.drawString(selected,40,20);
}
}
And My HTML code ->
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<embed code=”MainController.class”
type=”application/x-java-applet;version=1.6″>
</embed>
</body>
</html>
Upvotes: 1
Views: 2331
Reputation: 5489
The question is quite broad!
As you you know from comments and answer Applets and not supported anymore and it is not the way to go.
If you only only need to display a random word on a web page, you can use plain HTML and JavaScript.
var words = ["word", "words", "wordz"];
function changeWord() {
var index = Math.floor(Math.random() * words.length);
//Get the P element and set content
document.getElementById("out").innerHTML=words[index];
}
<button onclick="changeWord()">Try it</button>
<p id="out"></p>
If you want to learn Java technologies and stick to it, you can use a Servlet container (just think Java web server) such as Tomcat and learn Servlets, JSP and then JSF, Spring MCV, GWT... There are plenty of documentation and tutorials on the net
Note that if you need to start a Java application from a web page, you can have a look at Java Web Start.
Upvotes: 1
Reputation: 1
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/applet
The obsolete HTML Applet Element (< applet>) embeds a Java applet into the document; this element has been deprecated in favor of < object>.
Use of Java applets on the Web is deprecated; most browsers no longer support use of plug-ins, including the Java plug-in.
So try to use the element < object>
Upvotes: 0