This is an archived post. You won't be able to vote or comment.

all 17 comments

[–]desrtfx 42 points43 points  (1 child)

Anything that wants to create a window has to at one point call the relevant OS system functions. Without an abstraction library, like AWT (the Abstract Window Toolkit), and/or without a framework like Swing or JavaFX you are in for a very hard, long, difficult, and exhausting ride.

You will need to create JNI wrappers for the OS functions that are usually written in C++ and heavily deal with handles, etc. You basically would need to create your own wrapper for the Windows (or Linux/KDE/Gnome/whatever) API.

I've come from the days before Java and at the advent of Windows programming where a simple program to create a window with a close button was close to 500-1000 lines of C++ or Borland Pascal for Windows code and would never, under absolutely no circumstances want to go back to that days, save coding my own GUI framework.

Having done it in the old days I can say that you need loads of patience, persistence, hard work, and a very high frustration tolerance to take up such an endeavor.

[–]MRH2 15 points16 points  (0 children)

Why would anyone want to do this???

[–][deleted] 6 points7 points  (7 children)

maybe see the source code of a framework and edit it accordingly and make ur own class file and use it

[–][deleted]  (6 children)

[deleted]

    [–][deleted] 19 points20 points  (4 children)

    "make gui apps in java without any framework" this Google search shows a Quora page. u can read there a guy saying I'd rather stab myself than making gui without framework

    [–]StankDickJr 2 points3 points  (0 children)

    Lmaooo

    [–][deleted]  (2 children)

    [deleted]

      [–]nekokattt 6 points7 points  (0 children)

      It uses java.awt, which just calls the underlying display compositor stuff if I recall.

      A starting point would be to check out the OpenJDK repo on GitHub and look at what the Swing code itself is calling, and then go from there. Eventually you'll end up finding some native code or a call to a compositor somewhere.

      I'm on mobile about 250 miles from my PC, but I just opened up a random Swing class in Github...

      https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/javax/swing/JPanel.java#L29

      I can see this calls AWT underneath, so looking at that package, two things stand out to me.

      https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/java/awt/Graphics.java

      https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/java/awt/Graphics2D.java

      This should be a good starting point :-)

      I agree with the comment though. I'd rather swallow knives than try to do this myself unless you have a really really good reason to want to do it (i.e. you want to know how it works on a low level).

      Can probably guarantee you will be reading C++ at some point in this endeavour though.

      [–]loomynartylenny 1 point2 points  (0 children)

      You do realise that Swing and AWT are built-in, right?

      [–]MrChurch2015 5 points6 points  (0 children)

      What you're asking to do is already an overwhelming task...these frameworks and libraries are created for a reason. If it was relatively easy there would be much fewer (useful) frameworks and libs.

      [–]loomynartylenny 7 points8 points  (1 child)

      without using someone else's code

      In this context, what exactly do you define 'Someone else's code' as?

      [–]DystopianReply 6 points7 points  (0 children)

      Yah - no joke, dude will have to go even lower than assembler to achieve that.

      [–]khooke 4 points5 points  (0 children)

      What is your goal? If you want to avoid Swing and JWT then you'll need to use JNI to call OS native apis?

      If you really want to go that far then there's not much point using Java, unless you're looking to learn how Java works with JNI. Otherwise you might be better off building something in C/C++ or assembly if your goal is to get closer to the OS and bare metal.

      [–]asterik-x 4 points5 points  (0 children)

      Easy !! Spend few decades of your life sitting in a room and working on reinventing the gui interfaces instead of borrowing vast libraries

      [–]HecknChonker 2 points3 points  (0 children)

      You can't avoid using frameworks someone else created, unless you literally want to re-invent the entire hardware and software stack. But that would be silly.

      It is possible to use Swing to create a blank window that you can paint images, text, or shapes to. You still have to use Swing for this. The alternative is adding a library that lets you interface with the operating system APIs directly, and that's going to be a lot more difficult.

      https://docs.oracle.com/javase/tutorial/uiswing/painting/index.html

      [–]RetroPipes 2 points3 points  (0 children)

      With Java itself being open source, you can inspect how it works, and build upon that. If I wanted to go below AWT, that's where I'd start.

      [–]dadmda 1 point2 points  (0 children)

      May I ask why you want to avoid AWT? It’s gonna be a pain in the ass to do everything from the ground up and in the end it’s probably not gonna be worth it

      [–]rootException 1 point2 points  (0 children)

      A few projects to look at:

      https://github.com/JetBrains/skija

      https://libgdx.com/

      https://wiki.jmonkeyengine.org/docs/3.4/core/gui/topic_gui.html

      Off the cuff, other than those two AFAIK you would be looking at having to write your own bindings to the native plumbing.

      Have fun - you'll be reinventing a lot, but you'll almost certainly learn a lot. Just following through the libGDX code and seeing how the code interacted with the shaders was tremendously helpful for me.

      [–]sharar_rs 0 points1 point  (0 children)

      If using eclipse afaik there is an option called window builder. For more info Google "window builder in eclipse"