2015-04-22 143 views
0

我是一名html初学者,并且在Java中处于中级阶段。我刚刚做了我的第一个网页(不是真正的域名),只是为了测试它是否工作,我做了一个非常简单的applet程序,并将其添加到html代码中。下面是Java代码:为什么我的java代码不能在html网站上工作

import javax.swing.*; 
import java.awt.*; 
import java.applet.Applet; 
import java.awt.event.*;<p> 
    public class applet extends Applet { 
     public void paint(Graphics g){ 
    g.drawString("Hello", 20, 30); 
    } 
} 

这里是HTML代码(这是一个关于历史的演讲网站,有一堆图片。):

<html> 
<head> 
<title>LOST IN TIME</title> 
<link href="style.css" type="text/css" rel="stylesheet"> 

</head> 

<body background="background.jpg"> 
Program<br/> 
<applet code="applet.class" width=400 height=400> 
</applet> 

<h2>LOST IN TIME<h2> 
<hr> 

<div id="main"> 
<b><h1>FAMOUS SPEECHES </h1> 
<hr> 
<button> 
<a href="http://www.americanrhetoric.com/top100speechesall.html"> 
MORE FAMOUS SPEECHES 
</a href"http://www.americanrhetoric.com/top100speechesall.html"> 


</button> 
<hr> 
<h2> 
Gettysburg Address<p> 
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. 

Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. 

But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth. 

Abraham Lincoln 
November 19, 1863<p> 
<image src="images/Abraham Lincoln.jpg" alt="Abraham Lincoln posing for a picture."/> 


</h2> 

<hr> 
<h2> 
Farewell to Baseball Address<p> 
Fans, for the past two weeks you have been reading about a bad break I got. Yet today I consider myself the luckiest man on the face of the earth. I have been in ballparks for seventeen years and have never received anything but kindness and encouragement from you fans. 

Look at these grand men. Which of you would not consider it the highlight of his career to associate with them for even one day? 

Sure, I am lucky. Who would not consider it an honor to have known Jacob Ruppert; also the builder of baseballs greatest empire, Ed Barrow; to have spent the next nine years with that wonderful little fellow Miller Huggins – then to have spent the next nine years with that outstanding leader, that smart student of psychology; the best manager in baseball today, Joe McCarthy! 

Sure, I am lucky. When the New York Giants, a team you would give your right arm to beat, and vice versa, sends you a gift, that is something! When everybody down to the groundskeepers and those boys in white coats remember you with trophies, that is something. 

When you have a wonderful mother in law who takes sides with you in squabbles against her own daughter, that is something. When you have a father and mother who work all their lives so that you can have an education and build your body, it is a blessing! When you have a wife who has been a tower of strength and shown more courage than you dreamed existed, that is the finest I know. 

So I close in saying that I might have had a tough break, but I have an awful lot to live for! 
<p>- Lou Gehrig, July 4, 1939; Yankee Stadium<p> 
<image src="images/BaseBall.jpg" alt="A Yankee baseball game."/> 

<hr> 

</h2> 
<hr> 
<h2> 
Surrender Speech<p> 
Tell General Howard I know his heart. What he told me before, I have it in my heart. I am tired of fighting. Our Chiefs are killed; Looking Glass is dead, Ta Hool Hool Shute is dead. The old men are all dead. It is the young men who say yes or no. He who led on the young men is dead. It is cold, and we have no blankets; the little children are freezing to death. My people, some of them, have run away to the hills, and have no blankets, no food. No one knows where they are – perhaps freezing to death. I want to have time to look for my children, and see how many of them I can find. Maybe I shall find them among the dead. Hear me, my Chiefs! I am tired; my heart is sick and sad. From where the sun now stands I will fight no more forever. 
<p>-Chief Joseph, October 5, 1877; Montana Territory<p> 
<image src="images/ChiefJoseph.gif" alt="Chief Joseph poses sadly in a picture."/> 

<hr> 

</h2> 
<hr> 
<h2> 
Inauguration Address Excerpt<p> 
Can we forge against these enemies a grand and global alliance, North and South, East and West, that can assure a more fruitful life for all mankind? Will you join in that historic effort? 

In the long history of the world, only a few generations have been granted the role of defending freedom in its hour of maximum danger. I do not shrink from this responsibility; I welcome it. I do not believe that any of us would exchange places with any other people or any other generation. The energy, the faith, the devotion which we bring to this endeavor will light our country and all who serve it; and the glow from that fire can truly light the world. 

And so, my fellow Americans: ask not what your country can do for you; ask what you can do for your country. 

My fellow citizens of the world: ask not what America will do for you, but what together we can do for the freedom of man.<p> 
-John F. Kennedy, January 20, 1931; Washington D.C.<p> 
<image src="images/JFK.jpg" alt="John F. Kennedy being inaugurated."/> 

<hr> 

</h2> 
<h2> 
Address to the Nation on the Challenger <p> 
We have grown used to wonders in this century. It is hard to dazzle us. But for 25 years the United States space program has been doing just that. We have grown used to the idea of space, and perhaps we forget that we have only just begun. We are still pioneers. They, the members of the Challenger crew, were pioneers. 

And I want to say something to the school children of America who were watching the live coverage of the shuttles takeoff. I know it is hard to understand, but sometimes painful things like this happen. It is all part of the process of exploration and discovery. It is all part of taking a chance and expanding mans horizons. The future does not belong to the fainthearted; it belongs to the brave. The Challenger crew was pulling us into the future, and we will continue to follow them. 

The crew of the space shuttle Challenger honored us by the manner in which they lived their lives. We will never forget them, nor the last time we saw them, this morning, as they prepared for the journey and waved goodbye and slipped the surly bonds of earth to touch the face of God. 
<p> Ronald Reagan, January 28, 1986; Washington D.C.<p> 
<image src="images/Ronald reagan speech.jpg" alt="Ronald Reagan during speech."/> 

<hr> 
Thanks for reading. <p> 
I two sites to get all of these speeches. Here are the links if you would like to see them. Also if you want to find more speeches, click the button at the top.<p> 
<button1> 
<a href="http://www.abrahamlincolnonline.org/lincoln/speeches/gettysburg.htm"> 
http://www.abrahamlincolnonline.org/lincoln/speeches/gettysburg.htm<p> 
</a href"http://www.abrahamlincolnonline.org/lincoln/speeches/gettysburg.htm"> 
<button2> 
<a href="http://www.artofmanliness.com/2008/08/01/the-35-greatest-speeches-in-history/"> 
http://www.artofmanliness.com/2008/08/01/the-35-greatest-speeches-in-history/<p> 
</a href"http://www.americanrhetoric.com/top100speechesall.html"> 
</b> 
<p> 
<p> 
<img src="images/smiley face.jpeg" alt="Smiley face."/> 

</h2> 
<h3> 
<a href=#top>Back to Top</a> 
</h3> 
</div> 

</body> 
</html> 

我不会把CSS代码放在这里,因为在这种情况下它是无用的,但是如果你需要它就问。另外,我知道我的编码有点乱,而且他们的头文件中有一些无用的行,我不需要,但我只是想先让它工作。事情是,当我在谷歌浏览器上运行脚本时,它总是说“插件不受支持”,它只是在Internet Explorer和Firefox上出现错误。

谢谢。 Bobthebuilder:D

回答

0

的原因是因为你只是调用类的Java小程序,并且不包括核心的jar文件。

这应该使用archive=''元素调用。

<applet archive="FILENAME.jar" code="applet.class" width="400" height="400"> 
</applet> 

你还必须记住,没有手机浏览器将支持Java和许多桌面浏览器都开始在浏览器中停止Java的支持,这并不意味着它不会工作,但第三方插件需要只需很少的支持即可安装。

关于浏览器的信息:Java FAQ

+0

所以,如果我想提出一个Java小程序在互联网上,因为你取得了一些安全的消息从工作阻止它结束的建议,我应该使用什么编程语言来代替。 – bobthebuilder

+0

但这是一款游戏,我还以为JavaScript是HTML5和CSS放在一起。 – bobthebuilder

+0

感谢您的帮助。我想我现在明白了。 – bobthebuilder

相关问题