如何将 Java 程序嵌入我的网站?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41029236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I embed a java program into my website?
提问by IsaacLightning
First off, this is for my web design class. I am doing a sort of "promotion website" for the game I made in my Computer Science 2 final for the final in this class. Everything is all good, except that I wanted to add a feature where you could play the game from the browser. The website is all in a local folder, and he will be examining it on his computer, so everything will be local, no servers. How would I go about adding the game to the website?
首先,这是我的网页设计课。我正在为我在计算机科学 2 决赛中制作的游戏做一个“宣传网站”,以参加本课程的决赛。一切都很好,只是我想添加一个可以从浏览器玩游戏的功能。该网站都在一个本地文件夹中,他将在他的计算机上检查它,所以一切都将是本地的,没有服务器。我将如何将游戏添加到网站?
回答by Raptor
You will need java applets for your java code to run in browser. Here is some intro about applets: http://docs.oracle.com/javase/tutorial/deployment/applet/
您将需要 Java 小程序才能让您的 Java 代码在浏览器中运行。下面是一些关于小程序的介绍:http: //docs.oracle.com/javase/tutorial/deployment/applet/
Here is a simple example:
Your java code:
这是一个简单的例子:
你的java代码:
import java.applet.*;
import java.awt.*;
public class Main extends Applet{
public void paint(Graphics g){
g.drawString("Welcome in Java Applet.",40,20);
}
}
Compiling the code will generate a .class file. For example: Main.class
编译代码将生成一个 .class 文件。例如:Main.class
Then embed the Main.class file in your browser:
然后在浏览器中嵌入 Main.class 文件:
<HTML>
<HEAD>
My game applet
</HEAD>
<BODY>
<div >
<APPLET CODE="Main.class" WIDTH="800" HEIGHT="500"></APPLET>
</div>
</BODY>
</HTML>
Some basic tutorials here: http://www.dreamincode.net/forums/topic/229033-introduction-to-java-applets/
这里有一些基本教程:http: //www.dreamincode.net/forums/topic/229033-introduction-to-java-applets/
Another way: Java Web Start
另一种方式:Java Web Start
Use Java Web Startwhich allows applications to be launched through browsers or via the Java Network Launching Protocol.
使用允许通过浏览器或通过 Java 网络启动协议启动应用程序的Java Web Start。
Some valuable resources here: https://stackoverflow.com/tags/java-web-start/info
这里有一些有价值的资源:https: //stackoverflow.com/tags/java-web-start/info