浏览器不显示 java 小程序 [英] browser doesn't show java applet

查看:39
本文介绍了浏览器不显示 java 小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用 Java 小程序,发现这个网站提供了教程.我输入了所有代码,但小程序没有显示在我的浏览器中:HelloWorld.java

I'm just starting with java applets and found this website that gives a tutorial. I entered all the code but the applet didn't show up in my browser: HelloWorld.java

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

public class HelloWorld extends Applet
{
    public void paint (Graphics g)
    {
    g.drawString("Hello World!", 300, 300);
    }
}

这是我的 HTML 文件

And this is my HTML file

<HTML>
<HEAD>
<TITLE>Hello World Applet</TITLE>
</HEAD>
<BODY>
<H1>Hello World Applet</H1>
<applet code="HelloWorld.class" WIDTH=300 HEIGHT=300></applet>
</BODY>
</HTML>

我已经编译了 java 文件 (HelloWorld.class) 并将所有文件保存在我的桌面上.我在 mac osx 山狮上使用最新版本的 safari.我在谷歌浏览器中尝试过,它说要安装一个插件,我做了但没有发生任何事情?

I have compiled the java file (HelloWorld.class) and saved all the files on my desktop. I'm using the latest version of safari on mac osx mountain lion. I tried it in google chrome and it said to install a plugin and i did but nothing more happened?

推荐答案

(注意:这些事情发生在 windows 中,少数发生在 Ubuntu 中.如果以下任何一项适用于您的问题,请检查以下内容)尝试以下操作东西:
1st- 在 HTML 文件中,将 body 标记更改为:

(Just Note: These things take place in windows and a few in Ubuntu. Just check the following if any of the following applies to your problem)Try the following things:
1st- In HTML file, change the body tag to:

<body bgcolor = red>

如果您发现您提到的尺寸的白色矩形,那么您就知道您的小程序正在浏览器上运行,但是由于浏览器/jre 的某些问题,小程序没有按预期运行.

SO that you know your applet is running on the browser if you find a white rectangle of the dimensions you mentioned but the applet is not running as expected because of some problem with the browser/jre.

2- 我们使用的浏览器通常是 32 位浏览器.如果您的浏览器是 32 位版本,请检查您是否安装了 32 位版本的 java.

2nd- Browsers that we use are generally 32 bit browsers. Do check if you have the 32 bit version of java installed in case your browser is a 32 bit-one.

3rd- 要检查您的小程序是否实际创建,请尝试在终端中使用小程序查看器运行 html 文件.

3rd- To check whether your applet is actually created, try running the html file using appletviewer using the terminal.

无论您使用哪个,在 cmd/终端中运行以下任一命令:

run the following either in cmd/terminal whichever you use:

appletviewer 文件名.html

appletviewer filename.html

或者,如果您使用的是 eclipse/netbeans,它们通常会在 IDE 中集成一个 appletViewer,因此它们可以直接运行 appletviewer.

or if you are using eclipse/netbeans, they usually have a appletViewer integrated along with the IDE so they run the appletviewer directly.

这篇关于浏览器不显示 java 小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆