GraphStream - 未找到有效显示

GraphStream - No valid display found

我正在关注 graphStream 的 official tutorial。 我正在尝试 运行 从那里获取的示例代码:

import org.graphstream.graph.*;
import org.graphstream.graph.implementations.*;
    
public class Tutorial1 {
    public static void main(String args[]) {
        Graph graph = new SingleGraph("Tutorial 1");
    
        graph.addNode("A");
        graph.addNode("B");
        graph.addNode("C");
        graph.addEdge("AB", "A", "B");
        graph.addEdge("BC", "B", "C");
        graph.addEdge("CA", "C", "A");
    
        graph.display();
    }
}

我收到以下错误:

Exception in thread "main" java.lang.RuntimeException: Cannot launch viewer.
    at org.graphstream.graph.implementations.AbstractGraph.display(AbstractGraph.java:212)
    at org.graphstream.graph.implementations.AbstractGraph.display(AbstractGraph.java:204)
    at org.test.Test.main(Test.java:23)
Caused by: org.graphstream.util.MissingDisplayException: No valid display found. Please check your System.setProperty("org.graphstream.ui") statement.
    at org.graphstream.util.Display.getDefault(Display.java:79)
    at org.graphstream.graph.implementations.AbstractGraph.display(AbstractGraph.java:209)
    ... 2 more

我完全按照教程显示的那样做了。
我错过了什么? “未找到有效显示。” 是什么意思

如果您在 Java 应用程序中执行此操作,则需要使用 1.3 版。

添加以下依赖项。 Version 1.3

  • gs-core
  • gs-algo
  • gs-ui

主要

import org.graphstream.graph.*;
import org.graphstream.graph.implementations.*;
    
public class Main {
    public static void main(String args[]) {
        Graph graph = new SingleGraph("Tutorial 1");
        graph.setStrict(false);
        graph.setAutoCreate( true );
        graph.addNode("A");
        graph.addNode("B");
        graph.addNode("C");
        graph.addEdge("AB", "A", "B");
        graph.addEdge("BC", "B", "C");
        graph.addEdge("CA", "C", "A");
    
        graph.display();
    }
}

POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>sed.home</groupId>
    <artifactId>JavaTestArea</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>org.graphstream</groupId>
            <artifactId>gs-core</artifactId>
            <version>1.3</version>
        </dependency>        
        <dependency>
            <groupId>org.graphstream</groupId>
            <artifactId>gs-algo</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>org.graphstream</groupId>
            <artifactId>gs-ui</artifactId>
            <version>1.3</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>
</project>

输出

如果您使用 2.0 版,则需要在 JavaFXSwingAndroid 应用程序中完成。