2015-04-22 46 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

相關問題