Java 使用 Eclipse 在 Web 浏览器上运行小程序的步骤(将小程序程序连接到 html)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24846831/
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
Steps to run applet on web browser (connect applet program to html) using Eclipse
提问by rajeev mishra
Hi friends I am new to Java. I am trying to display applet on web browser using Eclipse.
嗨,朋友们,我是 Java 新手。我正在尝试使用 Eclipse 在 Web 浏览器上显示小程序。
Code:
代码:
import java.applet.*;
import java.awt.*;
public class AppletDemo extends Applet{
String msg="hello";
public void init(){
msg=getParameter("message");
}
public void paint(Graphics g){
g.drawString(msg,80,80);
}
}
Applet Tag:
小程序标签:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<applet code="AppletDemo.class"width="350"height="350">
<param name="message"value="Welcome to the world of Applet">
</applet>
</body>
</html>
Output should be "Welcome to the world of Applet" but when I run it, no value is getting displayed.
输出应该是“欢迎来到 Applet 的世界”,但是当我运行它时,没有显示任何值。
i got output in console is:
我在控制台中得到的输出是:
Oct 20, 2014 12:43:39 AM org.apache.catalina.core.AprLifecycleListener init
2014 年 10 月 20 日上午 12:43:39 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in
信息:基于 APR 的 Apache Tomcat Native 库,它允许在
production environments was not found on the java.library.path: C:\Program Files\Java
在 java.library.path 上找不到生产环境:C:\Program Files\Java
\jre8\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java
\jre8\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java
/jre8/bin/client;C:/Program Files/Java/jre8/bin;C:/Program Files/Java/jre8/lib
/jre8/bin/client;C:/Program Files/Java/jre8/bin;C:/Program Files/Java/jre8/lib
/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.8.0_05\bin;.;C:\Users\RAJEEV4\Desktop
\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.8.0_05\bin;.;C:\Users\RAJEEV4\Desktop
\eclipse-jee-kepler-SR2-win32(1)\eclipse;;.
\eclipse-jee-kepler-SR2-win32(1)\eclipse;;。
Oct 20, 2014 12:43:40 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
2014 年 10 月 20 日上午 12:43:40 org.apache.tomcat.util.digester.SetPropertiesRule 开始
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source'
警告:[SetPropertiesRule]{Server/Service/Engine/Host/Context} 设置属性“源”
to 'org.eclipse.jst.jee.server:demojsp' did not find a matching property.
to 'org.eclipse.jst.jee.server:demojsp' 没有找到匹配的属性。
Oct 20, 2014 12:43:40 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
2014 年 10 月 20 日上午 12:43:40 org.apache.tomcat.util.digester.SetPropertiesRule 开始
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source'
警告:[SetPropertiesRule]{Server/Service/Engine/Host/Context} 设置属性“源”
to 'org.eclipse.jst.jee.server:Zdemoappletweb' did not find a matching property.
to 'org.eclipse.jst.jee.server:Zdemoappletweb' 没有找到匹配的属性。
Oct 20, 2014 12:43:40 AM org.apache.coyote.AbstractProtocol init
2014 年 10 月 20 日上午 12:43:40 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
信息:初始化 ProtocolHandler ["http-bio-8080"]
Oct 20, 2014 12:43:40 AM org.apache.coyote.AbstractProtocol init
2014 年 10 月 20 日上午 12:43:40 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
信息:初始化 ProtocolHandler ["ajp-bio-8009"]
Oct 20, 2014 12:43:40 AM org.apache.catalina.startup.Catalina load
2014 年 10 月 20 日上午 12:43:40 org.apache.catalina.startup.Catalina 加载
INFO: Initialization processed in 2323 ms
信息:初始化在 2323 毫秒内处理
Oct 20, 2014 12:43:41 AM org.apache.catalina.core.StandardService startInternal
2014 年 10 月 20 日上午 12:43:41 org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
信息:启动服务 Catalina
Oct 20, 2014 12:43:41 AM org.apache.catalina.core.StandardEngine startInternal
2014 年 10 月 20 日上午 12:43:41 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.53
信息:启动 Servlet 引擎:Apache Tomcat/7.0.53
Oct 20, 2014 12:43:42 AM org.apache.coyote.AbstractProtocol start
2014 年 10 月 20 日上午 12:43:42 org.apache.coyote.AbstractProtocol 开始
INFO: Starting ProtocolHandler ["http-bio-8080"]
信息:启动 ProtocolHandler ["http-bio-8080"]
Oct 20, 2014 12:43:42 AM org.apache.coyote.AbstractProtocol start
2014 年 10 月 20 日上午 12:43:42 org.apache.coyote.AbstractProtocol 开始
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
信息:启动 ProtocolHandler [“ajp-bio-8009”]
Oct 20, 2014 12:43:42 AM org.apache.catalina.startup.Catalina start
2014 年 10 月 20 日上午 12:43:42 org.apache.catalina.startup.Catalina start
INFO: Server startup in 1961 ms
信息:服务器在 1961 毫秒内启动
What is the issue here?
这里有什么问题?
回答by Surajchamp
you can use this code ..
import java.applet.Applet.*;
import java.applet.*;
import java.awt.*;
public class Demo4 extends Applet
{
public void paint(Graphics g)
{
Font f=new Font("calibri",Font.BOLD,50);
g.setFont(f);
g.setColor(Color.red);
g.fillRect(0,0,1400,300);
g.setColor(Color.yellow);
g.fillRect(0,300,1400,600);
g.setColor(Color.green);
g.drawString("Welcome to the world of applet",100,200);
}
}
/*<applet code="Demo4.class" WIDTH=20 HEIGHT=20>
</applet>*/
Here thre is no need to make applet tag direct run this code..u have to foloow these rule to run
这里不需要让applet标签直接运行这个代码..你必须遵循这些规则才能运行
for compile- javac Demo4.java for run- appletViewer Demo4.java
用于编译- javac Demo4.java 用于运行- appletViewer Demo4.java
you get your ans easily..and don,t forget to include commen lines of applet these are the main lines
你很容易得到你的答案......并且不要忘记包括小程序的commen行这些是主要行
回答by SparkOn
First compile the AppletDemo
class then keep the .class
and the html
file in same location.
Then when you open the html file if you are getting error like
首先编译AppletDemo
类,然后将文件.class
和html
文件保存在同一位置。然后当你打开 html 文件时,如果你收到这样的错误
Your security settings have blocked a local application from running
Your security settings have blocked a local application from running
Then just go to
然后就去
start - >control panel -> java(if unable to find type java in the search field of control panel) -> Then click on it a menu pops up go to security tab -> then make the security label to medium and ok.
开始 -> 控制面板 -> java(如果在控制面板的搜索字段中找不到类型 java) -> 然后单击它一个弹出菜单转到安全选项卡 -> 然后将安全标签设置为中等即可。
Then again open the html in browser it will ask to click on run this application thats it.
然后再次在浏览器中打开 html 它会要求点击运行这个应用程序就是这样。