JattMannu / react-blog-github

🔥 React + Github Issues 👉 Your Personal Blog
https://saadpasta.github.io/react-blog-github/#/
MIT License
0 stars 0 forks source link

Helloworld for GTK on Debian+Java #6

Open JattMannu opened 3 years ago

JattMannu commented 3 years ago

Dependency

To compile a java-gnome class it's necessary to add the gtk-4.1.jar jar in the classpath. The jar is available on Debian (and all Debian-based distributions) in the libjava-gnome-java package, which can be found in the official repositories (the jar is installed under the /usr/share/java path).

How to add gtk-4.1.jar to the classpath

Under your project create a folder /lib/com.gtk/gtk/4.1 place the gtk-4.1.jar to the directory.

Update pom.xml

...
    <repositories>
        <repository>
            <id>MyProjectRepo</id>
            <name>MyProjectRepo</name>
            <url>file://${project.basedir}/lib</url>
        </repository>
    </repositories>
....
    <dependencies>
        <dependency>
            <groupId>com.gtk</groupId>
            <artifactId>gtk</artifactId>
            <version>4.1</version>
        </dependency>
    </dependencies>
...

Code

package org.yourpackage.javagnome.example;

import org.gnome.gdk.Event;
import org.gnome.gtk.Gtk;
import org.gnome.gtk.Widget;
import org.gnome.gtk.Window;
import org.gnome.gtk.WindowPosition;

public class GdkSimple extends Window {
    public GdkSimple() {
        setTitle("Example");
        connect((DeleteEvent)(source, event) -> {
            Gtk.mainQuit();
            return false;
        });
        setDefaultSize(250, 150);
        setPosition(WindowPosition.CENTER);
        show();
    }

    public static void main(String[] args) {
        Gtk.init(args);
        new GdkSimple(); 
        Gtk.main(); 
    } 
}

Result

image