我正在尝试将 graphstream 库集成到我的 java 小程序中。该小程序在 Eclipse 上运行,当我使用 appletviewer 实用程序时,但当我运行嵌入了小程序的 html 文件时,它只会呈现灰色屏幕。
这是我使用 java applet 运行 html 文件时遇到的错误。(我在 Internet Explorer 上测试过)
Java Plug-in 11.66.2.18
Using JRE version 1.8.0_66-b18 Java HotSpot(TM) Client VM
User home directory = C:\Users\mark
----------------------------------------------------
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>
----------------------------------------------------
basic: Added progress listener: sun.plugin.util.ProgressMonitorAdapter@187b275
security: Expected Main URL: file:/C:/Users/mark/workspace/JavaApplet/bin/swingGraph.jar
basic: Plugin2ClassLoader.addURL parent called for file:/C:/Users/mark/workspace/JavaApplet/bin/swingGraph.jar
basic: Plugin2ClassLoader.addURL parent called for file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar
network: Cache entry found [url: file:/C:/Users/mark/workspace/JavaApplet/bin/swingGraph.jar, version: null]
cache: Adding MemoryCache entry: file:/C:/Users/mark/workspace/JavaApplet/bin/swingGraph.jar
cache: Resource file:/C:/Users/mark/workspace/JavaApplet/bin/swingGraph.jar has expired.
network: ResponseCode for file:/C:/Users/mark/workspace/JavaApplet/bin/swingGraph.jar : 200
network: Encoding for file:/C:/Users/mark/workspace/JavaApplet/bin/swingGraph.jar : null
CacheEntry[file:/C:/Users/mark/workspace/JavaApplet/bin/swingGraph.jar]: updateAvailable=false,lastModified=Mon Dec 07 16:01:59 CST 2015,length=8212
cache: registerReference: com.sun.deploy.cache.MemoryCache$CachedResourceReference@d725590a: 1
cache: registerReference: com.sun.deploy.cache.MemoryCache$CachedResourceReference@d725590a: 2
security: Blacklist revocation check is enabled
security: blacklist: created: NEED_LOAD, lastModified: 1449401487364
security: The jar file isnt signed so the blacklist check will be skipped
security: Trusted libraries list check is enabled
security: Trusted libraries list file not found
cache: Reading Signers from 5 file:/C:/Users/mark/workspace/JavaApplet/bin/swingGraph.jar | C:\Users\mark\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\52\539c2334-19921083.idx
network: No certificate info for unsigned JAR file: file:/C:/Users/mark/workspace/JavaApplet/bin/swingGraph.jar
cache: Done readSigners(file:/C:/Users/mark/workspace/JavaApplet/bin/swingGraph.jar)
cache: Read manifest for file:/C:/Users/mark/workspace/JavaApplet/bin/swingGraph.jar: read=85 full=85
network: Created version ID: 1.8.0.66
network: Created version ID: 1.8.0.65
network: Created version ID: 1.8.0.66
network: Created version ID: 1.8.0.65
cache: registerReference: com.sun.deploy.cache.MemoryCache$CachedResourceReference@d725590a: 3
security: SSV validation:
running: 1.8.0_66
requested: null
range: null
javaVersionParam: null
Rule Set version: null
network: Created version ID: 1.8.0.66
network: Created version ID: 1.8.0.66
security: continue with running version
security: JUT Record:
plugin2
file://C:\Users\mark\workspace\JavaApplet\bin\myapplet.html: launchjnlp= code=swingGraph.SwingGraphApplet codebase=file:///C:/Users/mark/workspace/JavaApplet/bin/ width=800 archive=./swingGraph.jar,../lib/gs-core-1.3.jar height=500 app_model=eJyNU91qE0EUPtmkTWpDhYg3FkGkogjdoYgt6FUIRVpWKE37AJPNNDvt7s44czbZeFHwJQQvfAPfw3ufwVvfQNAzu5sfqYTsxezMzjnf+b7znf32Czasgd1QJb7NUn8odKymvhFXflfr92ooYiifmgf3AmiF9GnArUDYCa75mLNUILs8D94GsD0UNjRSo1QpQqe8jnk6Yn00Mh1RSEfkKFJLAefCqsyEwiI8LCMzlDHrGsOngbRIwe1rbuZhH+AW6lQ/ViF3Bdy5FsBWwmXai7ktAjxKsiLMjMSp447wMiBljJSxUhkjZWymbK+/FEsFN1BiLCqgBk41ATxdCXBBMZS4ORbpUJkiM9fUz7ZT5FNrfGrN52dHh49+/zR1aJ5AK+I26lHyCTS0MkgSeIaRcjRmla/kgkWkLFb7ljYKVaji6lwnKlXJP9WDAAgvWO8Nu7TCWJZwc8MmytxYzUPBTokVcY/JsoFMmUvewrKeLng/KHg7J/y5E/mnH4+/fOdf61AjzlZ+FLl2AzFpuDUvGt+mnVd88Ajl+Ypp2jtdmLqYLO+us80xCaiOrqnu3ZzprJgfrqvUTmj+3hmuI5+Gqsh2y7augO//F/5oHfhYDtjI7ofKiP0D/9Ud/PxfaI3wel3WyZQXBz/CJC6sraxC2F1S1J9vy1y9+vrWwJNVBrmZrpyBDhlsYKeYCvcn+8dplixfUq3N7tlZcHyh/wIhUG1n
basic: Applet loaded.
basic: Applet resized and added to parent container
basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 309164 us, pluginInit dt 512505 us, TotalTime: 821669 us
network: Cache entry found [url: file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar, version: null]
cache: Adding MemoryCache entry: file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar
cache: Resource file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar has expired.
network: ResponseCode for file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar : 200
network: Encoding for file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar : null
CacheEntry[file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar]: updateAvailable=true,lastModified=Mon Dec 07 14:36:53 CST 2015,length=1033670
cache: registerReference: com.sun.deploy.cache.MemoryCache$CachedResourceReference@fbedeb27: 1
cache: Resource file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar has expired.
network: ResponseCode for file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar : 200
network: Encoding for file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar : null
network: Server response: (length: 992680, lastModified: Tue Apr 07 12:21:14 CST 2015, downloadVersion: null, mimeType: application/x-java-archive)
network: Downloading resource: file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar
Content-Length: 992,680
Content-Encoding: null
network: Wrote URL file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar to File C:\Users\mark\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\5\218096c5-322fa223-temp
security: The jar file isnt signed so the blacklist check will be skipped
security: Trusted libraries list file not found
network: CleanupThread used 356788 us
cache: Create from verifier: JarSigningData{hasOnlySignedEntries=false, hasSingleCodeSource=false, hasMissingSignedEntries=false}
network: CleanupThread used 3 us
network: Cache: Enable a new CacheEntry: file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar
network: Remove cache entry: file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar
cache: MemoryCache: removed entry file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar
network: Downloaded file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar: C:\Users\mark\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\5\218096c5-322fa223
cache: Adding MemoryCache entry: file:/C:/Users/mark/workspace/JavaApplet/lib/gs-core-1.3.jar
cache: registerReference: com.sun.deploy.cache.MemoryCache$CachedResourceReference@fbedeb27: 1
cache: registerReference: com.sun.deploy.cache.MemoryCache$CachedResourceReference@fbedeb27: 2
java.lang.reflect.InvocationTargetException
at java.awt.EventQueue.invokeAndWait(Unknown Source)
at java.awt.EventQueue.invokeAndWait(Unknown Source)
at javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
at swingGraph.SwingGraphApplet.init(SwingGraphApplet.java:11)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
at org.graphstream.ui.graphicGraph.stylesheet.Rule.<init>(Rule.java:80)
at org.graphstream.ui.graphicGraph.stylesheet.StyleSheet.initRules(StyleSheet.java:303)
at org.graphstream.ui.graphicGraph.stylesheet.StyleSheet.<init>(StyleSheet.java:99)
at org.graphstream.ui.graphicGraph.GraphicGraph.<init>(GraphicGraph.java:229)
at org.graphstream.ui.view.Viewer.<init>(Viewer.java:247)
at swingGraph.SwingGraphPanel.<init>(SwingGraphPanel.java:21)
at swingGraph.SwingGraphApplet.createGUI(SwingGraphApplet.java:22)
at swingGraph.SwingGraphApplet$1.run(SwingGraphApplet.java:13)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.RuntimeException: corrupted graphstream.jar ? the org/miv/graphstream/ui/graphicGraph/rgb.properties file is not found
at org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.<clinit>(StyleConstants.java:241)
... 22 more
basic: Applet initialized
basic: Starting applet
basic: completed perf rollup
basic: Applet made visible
basic: Applet started
basic: Told clients applet is started
这是我的小程序代码: 1. SwingGraphPanel.java
package swingGraph;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.graphstream.graph.Node;
import org.graphstream.graph.implementations.MultiGraph;
import org.graphstream.ui.swingViewer.ViewPanel;
import org.graphstream.ui.view.Viewer;
public class SwingGraphPanel extends JPanel implements ActionListener {
private MultiGraph graph = new MultiGraph("Multigraph");
private static final long serialVersionUID = 3280131219271802894L;
private Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
private ViewPanel view = viewer.addDefaultView(false);
private static String ADD_COMMAND = "add";
private static String REMOVE_COMMAND = "remove";
private static String CLEAR_COMMAND = "clear";
public SwingGraphPanel() {
super(new BorderLayout());
JButton addButton = new JButton("Add");
addButton.setActionCommand(ADD_COMMAND);
addButton.addActionListener(this);
JButton removeButton = new JButton("Remove");
removeButton.setActionCommand(REMOVE_COMMAND);
removeButton.addActionListener(this);
JButton clearButton = new JButton("Clear");
clearButton.setActionCommand(CLEAR_COMMAND);
clearButton.addActionListener(this);
JPanel panel = new JPanel(new GridLayout(0,3));
panel.add(addButton);
panel.add(removeButton);
panel.add(clearButton);
add(panel, BorderLayout.NORTH);
add(view, BorderLayout.CENTER);
Node nodeA = graph.addNode("A");
nodeA.addAttribute("xy", 0, 0);
Node nodeB = graph.addNode("B");
nodeB.addAttribute("xy", 10, 0);
Node nodeC = graph.addNode("C");
nodeC.addAttribute("xy", 10, 10);
graph.addEdge("AB", "A", "B");
graph.addEdge("BC", "B", "C");
graph.addEdge("CA", "C", "A");
graph.addAttribute("ui.quality");
graph.addAttribute("ui.antialias");
}
public static void createAndShowGui() {
JFrame frame = new JFrame("Graph Swing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SwingGraphPanel graphPanel = new SwingGraphPanel();
graphPanel.setOpaque(true);
frame.setContentPane(graphPanel);
frame.setSize(500, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
2. SwingGraphApplet.java
package swingGraph;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
public class SwingGraphApplet extends JApplet {
private static final long serialVersionUID = 676241475056525767L;
public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void createGUI() {
SwingGraphPanel graphPanel = new SwingGraphPanel();
graphPanel.setOpaque(true);
setContentPane(graphPanel);
}
}
这是我的 html 文件代码
<html>
<head>
</head>
<body>
<applet archive="./swingGraph.jar,../lib/gs-core-1.3.jar"
code="swingGraph.SwingGraphApplet"
width="800"
height="500">
</applet>
</body>
</html>
===== 编辑 ======
这是“jar -tvf gs-core-1.3.jar”的输出