求解Applet标签的用法
写了一个html运用了Applet标签,却总是提示找不到TestWelcomeApplet.class这个类。由于是新手,求各位大神解救。指点一些什么地方出问题了???
以下是编写的html代码
<html>
<head>
<title>welcome to testWelcomeApplet!!!</title>
</head>
<body>
<hr/>
<p>
This applet is from the book
<a href="http://www.horstmann.com/corejava.html">Core java</a>
by <em> cay Horstmann </em> and <em> Gary Cornell </em>,
published by Sun Miscosystems Press.
</p>
<applet code="TestWelcomeApplet.class" width="200" height="100" >
<param name="g" value="Welcome to Core Jave!"/>
</applet>
<hr/>
<p><a href="TestWelcomeApplet.java">The source.</a></p>
</body>
</html>
编写TestWelcomeApplet类的代码:
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
public class TestWelcomeApplet extends JApplet{
public void init()
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
setLayout(new BorderLayout());
JLabel label = new JLabel(getParameter("g"),SwingConstants.CENTER);
label.setFont(new Font("Serif",Font.BOLD,18));
add(label,BorderLayout.CENTER);
JPanel panel = new JPanel();
JButton cayButton = new JButton("cay Horstmann");
cayButton.addActionListener(makeAction("http://www.horstmann.com"));
panel.add(cayButton);
JButton garyButton = new JButton("Gary Cornell");
garyButton.addActionListener(makeAction("mailto:gary_cornell@apress.com"));
panel.add(garyButton);
add(panel,BorderLayout.SOUTH);
}
});
}
private ActionListener makeAction(final String urlString)
{
return new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try{
getAppletContext().showDocument(new URL(urlString));
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
}
};
}
}
html? applet java
[解决办法]
code参数值是applet的类的web位置,如果这个位置没错且没有对该位置进行下载限制,直接从浏览器中输入code的值(完整url)就可以下载到这个文件,如果是404错误,说明code的值不对。