r/javahelp • • May 05 '22

Unsolved Creating a GUI in java

I’ve been out of the programming game for a while, when I was in college i made GUIs with JavaFX. I was wanting to start to make a game just for a hobby, but then I found out the newest JDK no longer supports JavaFX. Was there a better one introduced or did they fall back onto AWT?

19 Upvotes

20 comments sorted by

View all comments

Show parent comments

5

u/dionthorn this.isAPro=false; this.helping=true; May 05 '22

It is updated to jdk 18 by openjfx you can scope out their GitHub.

https://github.com/openjdk/jfx

Best GUI is based on your needs. Just need a basic GUI use Swing/AWT, need a little more control use JFX want 3D use LWJGL

1

u/mk_gecko Intermediate Brewer May 05 '22

Use Swing. If you want more control over component placement , use MigLayout .

tag /u/thisismyaccountsmile

2

u/dionthorn this.isAPro=false; this.helping=true; May 05 '22 edited May 05 '22

I found it difficult to gain per pixel control over canvas and Image objects for games in Swing it just felt easier in JavaFX.

https://github.com/dionthorn/2DTacticalRPG/blob/master/src/main/java/org/dionthorn/tacticalrpg2d/render/TileSet.java

And yes this is certainly over kill for what I'm using it for and no I am not a pro. >.> The pixel reader and pixel writer. I'm sure there is a way in Swing but I like this method.

In my render util I make heavy use of the Graphics Context from canvas

https://github.com/dionthorn/2DTacticalRPG/blob/master/src/main/java/org/dionthorn/tacticalrpg2d/render/RenderUtil.java

1

u/mk_gecko Intermediate Brewer May 06 '22

What you're doing is complicated. I do different things. It's not hard to control pixels on JPanels. You just have to make sure you're using the Jpanel size and not the JFrame size.
And sprites work well too.

The best and fastest graphics come from drawing to a buffered image and then drawing the image on the JPanel.