我一直在搜索 Stackoverflow,发现问题似乎是,类的路径不正确。(我试图调整我的代码,但它仍然给我ClassNotFoundException)这段代码的目的是让用户点击列表,然后将他们重定向到一个网站。这也是来自thenewboston的实践培训。
爪哇:
package webApplet;
import java.applet.AppletContext;
import java.awt.BorderLayout;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class Applet extends JApplet {
HashMap webInfo;
List<String> name;
JList list;
public void init() {
webInfo = new HashMap();
name = new ArrayList();
populate();
add(new JLabel("please click on a website"), BorderLayout.NORTH);
list = new JList(name.toArray());
list.addListSelectionListener(
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent event) {
Object object = list.getSelectedValue();
URL url = (URL) webInfo.get(object);
AppletContext browser = getAppletContext();
browser.showDocument(url);
}
});
add(new JScrollPane(list), BorderLayout.CENTER);
}
public void populate() {
URL url;
String title;
String address;
int counter = 0;
title = getParameter("title" + counter);
while (title != null) {
try {
address = getParameter("address" + counter);
url = new URL(address);
webInfo.put(title, url);
name.add(title);
} catch (MalformedURLException ex) {
System.out.println("hi");
}
}
counter++;
title = getParameter("title" + counter);
}
}
html:
<html>
<body>
<applet code= "webApplet.Applet.class" width = "500" height = "250">
<param name= "title0" value = "thenewBoston.org">
<param name= "address0" value = "http://thenewboston.org">
<param name= "title1" value = "Awesome forum!">
<param name= "address1" value = "http://tnbforum.com/">
</applet>
</body>
</html>
错误:
Java Plug-in 10.25.2.16
Using JRE version 1.7.0_25-b16 Java HotSpot(TM) Client VM
User home directory = C:\Users\tin
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
在错误下它有这个:“webApplet.Applet.class”
这是我的文件流:
website ---->
source packages----->
webApplet---->
- Applet.java
- bucky.html