tags:

views:

208

answers:

4

Is it possible to write "pure" lightweight code in java? Swing is lightweight but even it has heavyweight components like JWindow, JFrame, JDialog, and JApplet. So even Swing applications are not 100 percent independent of the underlying OS

Is it possible to have lightweight applications in java which are completely independent of the underlying OS for graphics display? Is it possible to write such code in java?

+7  A: 

Um...Yea, those ARE "100% independent" of the OS.

At least to the point that all JVMs must support them.

I guess I don't understand what you mean by 100% independent. At it's core, Swing needs little more than access to the core window manager and a blitter, though it obviously can (and does) use much more than that.

Simply stated, part of porting the JVM includes porting the core graphics capabilities required by Swing. Some ports leverage the OS better than other, but at the high level Swing level, you generally aren't concerned about that.

Will Hartung
A: 

In the end, only the OS knows what graphics hardware there is and how to tell it to draw a UI, and not amount of abstraction layers can change that - nor should it: that's exactly the point of having an OS in the first place.

I suppose in theory you could have some sort of framebuffer device and have Swing draw directly to that, but A) as you noted, Swing is based on AWT, and AWT does not work like that, and B) it would still be the OS that implements the framebuffer device.

Michael Borgwardt
+1  A: 

No, if you want to draw on the screen, you'll need to get the OS to do it for you.

If you're worried about the performance or bloat of Swing, check out SWT. It's lighter weight and matches the native look-and-feel more closely (since it's more or less a wrapper around the OS GUI stuff).

paxdiablo
Not really. Eclipse is horrible on my Linux machine running KDE 4.1 on openSUSE 11.1. SWT is not sleek, IMHO. I would prefer Qt as an alternate to Swing.
Adeel Ansari
Or just use whichever of the above you prefer since you wont really have any performance issues with either of them.
willcodejavaforfood
A: 

You need some kind of interfacing to the display. Obviousy you can create bitmaps in memory without any graphics hardware. There are a number of network display protocols, notably X Windows (X11) and the protocol used by VNC. You could also have a server display an interface throug applets and WebStart/JNLP. I understand Opera Mini uses a midlet to display bitmaps and return input to a web browser (presumably based on desktop Opera) running on a remote server. IBM used to have a remote AWT long ago (before Swing, IIRC).

Tom Hawtin - tackline