Java 小程序不显示任何内容 [英] Java applet does not display anything

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

问题描述

有谁知道为什么我的 Java 小程序不显示任何内容?

Does anyone know why my Java applet does not display anything?

这是我的第一个 Java 小程序,所以我是创建一个的新手.我研究了这个问题,但没有找到针对当前问题的答案.

This is my first Java applet so I am new to creating one. I researched this problem and haven't found an answer specific to the current problem.

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;

public class JavaRocksApplet extends Applet
{
public void paint( Graphics screen )
{
    Font f = new Font( "TimesRoman", Font.ITALIC, 36 );
    screen.setFont( f );
    Color c = new Color( 40, 80, 120 );
    screen.setColor( c );
    screen.drawString( "Java Rocks!!", 100, 60 );
}
}

我在命令模块或 html 页面中使用 appletviewer 都没有关系.

It doesn't matter whether I use appletviewer in the command module or an html page.

<html>
<head>
<title>JavaRocksApplet</title>
</head>
<body>
    <applet code = "JavaRocksApplet.class" width = 400 height = 200> </applet>
</body>
</html>

编译Java程序时没有错误,所以我有点困惑为什么它不起作用.

There are no errors when compiling the Java program, so I am a little bit confused about why it doesn't work.

此外,我使用的是运行 OSX 10.8.2 Mountain Lion 和 Java SE 6 的 MacBook Pro

Also, I am using a MacBook Pro running OSX 10.8.2 Mountain Lion with Java SE 6

推荐答案

这是此工作代码的屏幕截图.除了从指定的小程序高度缩短.

Here is a screenshot of this working code. Except shortened from the applet height specified.

所以,正如 Neet 在评论中指出的那样.'它在这里有效.'

So, as Neet noted in a comment. 'It works here.'

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;

/*
<applet code = "JavaRocksApplet.class" width = 400 height = 200> </applet>
*/
public class JavaRocksApplet extends Applet
{
    public void paint( Graphics screen )
    {
        Font f = new Font( "TimesRoman", Font.ITALIC, 36 );
        screen.setFont( f );
        Color c = new Color( 40, 80, 120 );
        screen.setColor( c );
        screen.drawString( "Java Rocks!!", 100, 60 );
    }
}

可能可以通过查看控制台找到有关问题实际原因的更多详细信息.请参阅如何启用和查看 Java 控制台?

Likely more details on the actual cause of the problem can be found by viewing the console. See How do I enable and view the Java Console?

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

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