A bare bone graphic library in Java (on top of AWT) for teaching purpose, use at your own risk.
Download zen-6.0.jar, zen-6.0-sources.jar or/and zen-6.0-javadoc.jar.
Zen provides
-
a way to open a drawing area in full screen mode
Application.run(backgroundColor, context -> { ... });
The context object (
ApplicationContext
) let you interact with the drawing area. -
a way to get keyboard and mouse pointer events
Event event = context.pollEvent();
The
event
is either a keyboard event (KeyboardEvent
) or a mouse pointer event (PointerEvent
) -
a way to draw on the drawing area
context.renderFrame(graphics2D -> { // use the Graphics2D object to draw ... });
Download the jar file zen-6.0.jar then follow https://stackoverflow.com/questions/11463354/how-to-put-a-jar-in-classpath-in-eclipse.
Download the jar file zen-6.0.jar then follow https://stackoverflow.com/questions/7057229/how-to-include-classpath-jars-into-a-jar-in-ant.
The latest binary distribution of Zen is available on JitPack repository.
So first, you need to add Jitpack as a repository in the POM file,
...
<repositories>
...
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
and then add Zen as a dependency
<dependencies>
...
<dependency>
<groupId>com.github.forax</groupId>
<artifactId>zen</artifactId>
<version>6.0</version>
</dependency>
</dependencies>
The latest binary distribution of Zen is available on JitPack repository.
repositories {
...
maven { url 'https://jitpack.io' }
}
dependencies {
compile 'com.github.forax:zen:6.0'
}
Oracle has is a nice tutorial explaining how to use the class Graphics2D
,
https://docs.oracle.com/javase/tutorial/2d/
Images can be loaded using the package imageio. Here is an example
String imageName = ...
BufferedImage image;
try(InputStream input = MyClass.class.getResourceAsStream("/images/" + imageName)) {
image = ImageIO.read(input);
}
With the images stored in a sub folder images
of the jar file.
If you are using eclipse
, if you create the folder images
in src
, it will be copied into bin
automatically.
If you are using maven
or gradle
, if you create the folder images
in src/main/resources
, it will be copied
into target/classes
automatically. If you are using ant
, you have to copy the folder using the task copy
.
The BufferedImage
can later be drawn to the screen buffer using the method
graphics2D.drawImage(image, x, y, null).
The idea of Zen is to provide just the bare minimum to draw something on screen, exposing an instance of Graphics2D
.
If you want graphics components, you have to implement them by yourself, on top of Zen, which is a nice exercice BTW.
The javadoc is available online.
Yes, see Demo.java