Java小程序不显示任何内容 [英] Java applet does not display anything
问题描述
有谁知道为什么我的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.
另外,我使用的MacBook Pro运行OSX 10.8.2山狮与Java SE 6
Also, I am using a MacBook Pro running OSX 10.8.2 Mountain Lion with Java SE 6
推荐答案
下面是这个工作code的截图。除了从指定applet的高度缩短。
Here is a screenshot of this working code. Except shortened from the applet height specified.
所以,啃老族在评论中指出的。 它在这里工作。
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屋!