如何将Java程序嵌入网站?

如何将Java程序嵌入网站?

问题描述:

首先,这是我的网页设计课程.我正在为我在本课程的决赛中在计算机科学2决赛中制作的游戏做一个促销网站".一切都很好,只不过我想添加一个功能,使您可以从浏览器玩游戏.该网站都在本地文件夹中,他将在自己的计算机上对其进行检查,因此所有内容都将是本地的,没有服务器.我将如何将游戏添加到网站上?

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?

您将需要Java小程序,以便Java代码在浏览器中运行.以下是有关applet的一些介绍: http://docs.oracle.com/javase/教程/部署/小程序/

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代码:

Here is a simple example:
Your java code:

import java.applet.*;
import java.awt.*;

public class Main extends Applet{
   public void paint(Graphics g){
      g.drawString("Welcome in Java Applet.",40,20);
   }
}

编译代码将生成一个.class文件.例如: Main.class

Compiling the code will generate a .class file. For example: Main.class

然后将Main.class文件嵌入到浏览器中:

<HTML>
  <HEAD>
    My game applet
  </HEAD>
  <BODY>
    <div >
      <APPLET CODE="Main.class" WIDTH="800" HEIGHT="500"></APPLET>
    </div>
  </BODY>
</HTML>

此处提供一些基本教程: http://www.dreamincode.net/forums/topic/229033-introduction-to-java-applets/

Some basic tutorials here: http://www.dreamincode.net/forums/topic/229033-introduction-to-java-applets/

另一种方式:Java Web Start

使用 Java Web Start 允许通过以下方式启动应用程序浏览器或通过Java网络启动协议.

Use Java Web Start which allows applications to be launched through browsers or via the Java Network Launching Protocol.

此处有一些宝贵的资源: https://*.com/tags/java-web-start/info

Some valuable resources here: https://*.com/tags/java-web-start/info