As we know AWT classes uses native OS libraries for creating GUIs but Swing uses Java library itself for creating the GUI.Can anyone please give me an example of the Windows OS library corresponds to a AWT GUI ?
Thx
In theory it may depend on jvm implementation. But in windows it use WinAPI probably.
The short answer is the MFC (Microsoft Foundation Classes) which all of Windows widgets are based on.
If you recall the great MS and Java Lawsuit the reason MS "Split" with how Java was developing was the MFC--at that point, Sun was considering a "JFC" which more or less later became Swing. they didn't want to re-invent something they already have. regardless, Swing is based on AWT which is heavily based on Motif/X which if I remember right is also what MS based their MFC on... It not the jvm that determines how a particular Java Swing/AWT element--like a button, but the Native Peer for that platform, which is bound to Java via the JNI....
If you need to know the really small details of how it's implemented in a low-level, download the jdk source (OpenJDK is FLOSS), and read the code yourself.
Don't expect anyone except developers who were directly related to that code to know the exact answer to your question.
Related
I need to create a desktop application for Windows as primary OS and Linux secondary. The programming language i prefer is Java since most of the backend work is in Java. I checked Qt, Gtk+, wxWidgets but was not able to come to a conclusion as which one is better. Can you suggest as of today which widget toolkit is good with support for Java? Also its fine if its not open source.
Another important aspect is I would like to know if the toolkit would create with UI native to the OS or will it have its own theme?
Well, the two best-known ones for Java are SWT and Swing. SWT will look more native, since it uses the OS's widgets. Swing will have its own look, but you can get it to emulate the OS's look. They are both available for Windows, Mac, and Linux.
There are a few more options. One thing you could look into is Jambi, which is the Java binding for Qt. It looks pretty native on all platforms it supports, and again supports Windows, Mac, and Linux.
You could also get other toolkits to work with Java using something like JNI or JNA. Look at this question regarding what the best one to use is for your situation. I bet you could easily get GTK+ to work with JNA, since it's purely a C interface, but I haven't tried it personally.
There is an application which is built in the SunAWTFrame class and, as you can guess, this is a strange world for the Windows API.
So I wonder, what should I do/use to get text from controls in a GUI built with this or automate them?
Is there some sort of API or library that can accomplish this and is suitable for work inside pure C++ or similiar language (not only Java)?
Your problem is likely due to the Java GUI being a Swing GUI program (note that the MS Windows class for these GUI's -- at least I know for JFrames -- is "SunAWTFrame"), and since Swing uses light-weight components, not MS Windows native components, you won't easily be able to extract window information from them. I don't know of any easy way around this without the Java source code.
Edit 1
After a little Googling some I have found new information:
Have you looked into using perhaps Java Monkey or Java Ferret?
Or perhaps best of all, Java Access Bridge which "is a technology that exposes the Java Accessibility API in a Microsoft Windows DLL, enabling Java applications and applets that implement the Java Accessibility API to be visible to assistive technologies on Microsoft Windows systems"
java access bridge c# example:
[a link] https://github.com/jdog3/JavaAccessBridge.Net-Sample
i am looking into making my own OS just to say i've done it. i know that there is a project called JNode that has done one in assembly and java.
what i was wondering was, what embedded graphics do you need to run java? i know java uses the graphics of the specific os so this confuses me
I think you would need to port the JVM to your OS. Have a look at the Java Virtual Machine spec. It will tell you exactly what need to implement to support Java.
If you need to implement AWT/Swing, then you obviously need to have some kind of library that can draw 2D graphics in a screen. I'd recommend however to start from implementing the virtual machine and some basic libraries. Printing in a screen will be sufficient.
Have a look here for a list of implementations of JAVA for the ARM platform. Kaffe is interesting.
Java can run in headless mode. That might be a good starting point suitable for server side stuff, which you can then extend if you feel like it.
Have a look at Sanos - http://www.jbox.dk/sanos/ - which is a tiny OS providing just the facilities needed to run the Windows JVM.
Have you ever attempted using Swing only to end up changing courses because it just couldn't do what you wanted?
I'm pretty new to Swing, having only used it for school projects over 5 years ago, but it seems Swing has come a long way in providing a more native look and feel, so much so that I'm considering using it to develop the GUI for an app on Mac OS X. Before I do, though, I wanted to see if anyone has run into any showstopper issues that prevented them from using Swing.
Just off the top of my head, some possibilities:
Problems developing custom components that looked "right"
Bad interactions with native applications and widgets
Performance issues (unresponsiveness, repaint problems)
Inability to mimic native behaviors (like Dock interaction)
Swing isn't going to give you perfect fidelity with the hosting OS. Sun simply can't devote the considerable resources necessary to do so. My impression is that Swing has gotten much better, but is still going to look out of place by default.
The minimum required to even hope to pass as a Mac app:
package your .jar in a .app
set the L&F to system default
set apple.laf.useScreenMenuBar property to true
must do this before any UI code
Dock interaction is non-existent in standard Java. You'll have to use Apple's Cocoa-Java bridge, which is no longer supported. I have no idea how tractable JNI is on OS X, which is the only real alternative.
Performance shouldn't be a problem. Drag & Drop is probably as hairy on OS X as it is everywhere else.
Basically, if you're explicitly targeting OS X you're best off using Objective-C. Its far from impossible to build an app on OS X using Java & Swing, but its a lot of work to make it look "native".
As Kevin and John said you should try Objective-C, Cocoa and XCode if you are only targeting Mac users. The developer tools for Mac is freely available.
If you want to (or have to) use Java and Swing you can use some libraries to create a GUI that looks well on Macs:
Quaqua look and feel
MacWidgets
For deploying your application you should read the JarBundler docs.
However, in this case interaction with dock and native applications is very limited.
Some other good links are:
Making Java/Swing Applications Look (More) Like
Native Mac OS X Applications
Java: How to handle drop events to the Mac OS X Dock icon
#Kevin++
Using Cocoa is probably better
If you want it to look exactly like native applications
If you are targeting only the Mac
If you intend to distribute your applications for Windows, Linux, etc. Swing is a decent choice. It's better but like in any toolkit there are still issues. You'll never get a truly native look and feel with it, same goes for similar UI toolkits which claim to be "cross-platform".
The Apple Guidelines for Java development can be found here.
Swing is a nice way to go, or you can go SWT, or BOTH!
But either way, use them on top of the RCP platform. (either with Eclipse or Netbeans).
Have a look at this: http://www.adam-bien.com/roller/abien/entry/eclipse_rcp_vs_netbeans_rcp
marco
For the program idea I have, it requires that the software be written in one binary that is executeable by all major desktop platforms, meaning it needs an interpreted language or a language within a JVM. Either is fine with me, but the programming language has to balance power & simplicity (e.g. Python)
I know of wxPython but I have read that it's support on Mac OS X is fairly limited
Java sounds good & it looks good but it seems almost too difficult to program in
Any help?
I used Python with wxPython for quite a while and found it very easy to use. I now use Java with both Swing and SWT.
I prefer Java but that's just a personal preference so you shouldn't let that sway you.
I didn't find the transition from Python to Java that difficult. In terms of GUI, they both have the layout manager paradigm - the managers are different but not so different you'll have trouble switching.
Java has an absolute huge class library to the point where you probably don't need to write your own version of anything, just string together the components. I never really got that deep into Python but it may well be similar. One thing I did notice is that all the really good stuff I used in Python (e.g., s[-4:-1]) could still be done quite easily in Java. Both languages were a step up from C where I had to manage strings with my own libraries.
If you think wxPython is limited on MacOS, you should try Java. I run my Java code on Windows, Linux and other UNIXes without compatibility problems. Sadly, not Mac, so I can't really advise you there.
My advice, pick a smallish project - do it in both Python and Java - see how it runs on all the platforms you're interested in.
Python with PyQt or the eventually-to-be-equivalent-but-gratis PySide seems the way to go -- after all, few languages are easier to program in than Java (which you consider "almost too difficult to program in"), Python is one of those few, Qt arguably the best cross-platform GUI toolkit in any language, and PyQt (now, but GPL or for-$$$) or PySide (eventually, gratis even if you want to close-source your own code) are powerful interfaces between Python and Qt.
You can use any of languages targeting JVM, e.g. Jython (Python impl) and JRuby (Ruby impl).
You can try using Qt bindings for Python, Qt seems to support many of Mac OSX specifics.
Consider Tcl/Tk. I'm not sure how you define "one binary that is executeable [sic] by all major desktop platforms" but Tcl probably meets this as well as java, and likely better than any other scripting language.
Using the tcl packaging technology of starkits you can either a) create a single file that can be run on any platform that has an appropriate runtime engine (and they are available for all major and many minor platforms), or you can package that platform-specific runtime engine and and cross-platform starkit into a single file executable for each platform.
The starkit technology is something other languages should aspire to. What you get is a complete, fully functional virtual file system within a single file. This lets you easily package up sound files, dll/.so files (which must be copied to disk for obvious (?) reasons), images, data, etc along with your executable code.
Tk, the graphical library, is very mature and has really good support on all platforms. Some people think it looks dated but those impressions are usually based on information that is at least 5 years old. Modern Tk looks quite good. For some examples see the tkdocs website. I's not clear whether you're more concerned with eye candy or functionality, but if it's functionality you're interested in then Tk is something to seriously consider.
Most agree that Tcl is an aquired taste but those that use it professionally usually swear by it. I've been doing wxPython programming the last several months and would switch back to tcl/tk in a heartbeat if given the opportunity.
You could use Groovy to work around the Java complexities.
Still you'll need good foundations of Swing.
While the learning curve may be steep, the trade of of not having to completely re-write the whole application again for the next platform will be a good reward.
Bear in mind, that even though it is cross platform, you should consider different platforms still have different idioms ( e.g. Copy/Past in Windows is ctrl+v, ctrl+v while in Mac it is cmd+c, cmd+v )
I work on a program that has to run on Windows, Linux and OS X (and OS X is my development platform), and wxPython is what we use.
If I had a chance to start again, I'd probably go with PyQT (based on advice from friends), but wxPython will get the job done.
I think wxPython is pretty good, though I am not sure what you mean by "support on Mac OS X is fairly limited" but I have been porting a wxPython app (www.mockupscreens.com) to Mac and it wasn't that difficult with few tweaks e.g. some UI elements may not come up as you expected, as wxPython uses native UI elements, which can be an advanatage or disadvantage based on your requirements.
Other good option is PyQT which will give you consistent look on all platforms.
Java seems better for what you want.
Well what about the web application in Javascript?
How about SWT
Cross Platform
Native Look and feel
Huge community
Constantly maintained/upgraded ( IBM backed )
Atleast one mega successful cross platform project
I would suggest going the wxPython route, I know that wxWidgets (which is what wxPython is using) can be made to have great looking Mac apps (look at PgAdmin3 from postgresql). While PgAdmin3 is not done in python, it was done with wxWidgets and looks fine on a mac.
I use three cross-platform tools regularly: Realbasic from Realsoftware which is what Visual Basic v6 would have been if allowed to grow; Revolution from Runrev which is what Hypercard would have been if allowed to survive (and its neat using a scripting language whose syntax is basically English); and finally, Delphi Prism with Mono.
All are quite mature and yet expanding at a great rate. For instance, Revolution is just introducing a web-application feature to its language that is really easy to use.