I use swing now for my GUIs in Java, and I was wondering about the quality of gwt. Are there compatibility issues with some things (I have a hard time with serialization sometimes when using swing, as an example), is the interface intuitive? How is the performance?
Swing and AWT are for desktop applications. GWT is for web applications. They're not comparable at all.
GWT is not just a GUI toolkit, it is a complete framework including a Java to JavaScript compiler, for writing Java code to be compiled into JavaScript and run by the browser. It includes support for serialization and other nice things, but it doesn't support the entire Java language/API. (No reflection for example).
Java applets are really just Java applications running within the browser. Applets don't really integrate with the HTML document model, and (Applet's) don't describe their GUI using html.
For doing GUI development: GWT does all its layout in the HTML DOM modul(Like you would if you wrote the JavaScript yourself) so to do layout you need to understand how HTML and CSS work.
Using GWT for GUIs are very different from using Swing/AWT exactly because you need to describe the GUI using HTML/CSS elements.
Related
I've got a question today and would like to know which would be better to use in Java development. Which would be better to use: Java Swing OR Java Applet. I am new to Java development and have been confused between the two.
If you were creating a game which would be better to use.
Which is better to understand and uses less lines ect.
Which is light weight?
Any questions would be awesome!
Java Swing OR Java Applet
There is some confusion here.
AWT has Frame for desktop applications/Applet for applets.
Swing has JFrame for desktop applications/JApplet for applets.
Other matters:
AWT/Swing. Why AWT rather than Swing? See this answer on Swing extras over AWT for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see Mixing Heavyweight and Lightweight Components.
Applet vs. application. Why code an applet? If it is due to spec. by teacher, please refer them to Why CS teachers should stop teaching Java applets.
Many of the components in javax.swing.* have made other still accessible JDK components obsolete, such as AWT. Swing is actually built on top of AWT, and is a large improvement in performance, features, and usage over AWT.
This tutorial on custom graphics with Swing may help:
http://www.ntu.edu.sg/home/ehchua/programming/java/J4b_CustomGraphics.html
As for Java Applets, these are unrelated to Swing in terms of normal application development. Java Applets are small applications that can run in a web browser.
Swing is a set of platform independent UI tools (JButton, JScrollBar, etc.). It guarantees that your user interface design will look the same on different platforms. An applet is an app that runs inside a browser or other hosted environment. An applet can use Swing UI, but doesn't need to.
Personally, I wouldn't develop a game in either if it's graphics intensive. If you want lightweight, I would suggest using JavaScript in Chrome's V8. Check out Chrome's developer showcase. They're doing amazing things with Javascript these days.
Is/was there a browser that used Java instead of Javascript as it's client-side programming language?
I appreciate that it would have required sites to have multiple versions of their client-side scripting logic as Javascript always seems to have been the dominant language.
Not as an Applet language, but as the language for interacting with the DOM.
I am aware that IE used VBScript for a while.
I am doing a research project on the evolution of the browser and there is so much noise in search engines for these terms that it is difficult to answer this question.
There is a WebView (based on the WebKit) in JavaFX 2 in which you can pass a Java object to JavaScript an call methods on it.
So this can be considered as a browser running on a JVM. Here is an example of how Google Maps are rendered in this browser: Maps in JavaFX 2.0.
JS-to-Java call sample: WebViewSample.
In eclipse you can detach tabs and they will displayed in a special kind of window.
Win7 with aero displays it as follows
http://www.oliholz.de/data/1.jpg
How can i produce this frame? i have tried many styles of JFrame,JWindow,JDialog, ...
As other people mentioned eclipse uses it's own library for UI. That library is based on SWT which is better integrated with the native window system.
See this article for explanation on how SWT, AWT, and Swing relate to each other.
Eclipse Rich Client Platform which is also mentioned here can be observed as a layer above SWT that can make your life much easier if you intend to develop a complex, feature rich application (for example an IDE for the new programming language you made).
Take a look at the Eclipse Rich Client Platform. If you want to emulate their look and feel, you might consider building your user interface upon their free (and rather good) open source framework.
This seems to be a question where the answer is implicit, hence I can't find anything explicit.
Does Google Web Toolkit only support custom layout managers, or a sub-set of the Java layout managers?
For example, is it possible to take a Java Swing application using GroupLayout and get it to work with GWT?
GWT layout support is done through subclasses of 'Panel'. Some of them like 'DockPanel' behave a little bit like Swing layouts (BorderLayout) but there's no way you'll ever be able to take Swing code and compile it into GWT.
This is a common mis-understanding when it comes to GWT. It's written in Java solely because Java is statically type and widely supported with world class editors. The fact that it's written in Java has nothing to do with any desire by the GWT team to allow you to port SWT/AWT/Swing to GWT. The web is a different environment to the desktop, and since your code ends up compiled into javascript it would never make sense to take any kind of Java Desktop application and hit the convert button. That's what Applets tried to do many years back...and we all know how that turned out ;)
No, GWT doesn't support Layout managers from Swing/AWT. These are not compatible.
Source of incompatibility is that those are totally different technologies with different APIs. Swing/AWT is pixel-based, while GWT renders to HTML. GWT layouts simply output different HTML tags (div/table/inline elements, ...), while Swing/AWT layouts do actually compute position of children components. In GWT, position of children is computed by browser, when they are displayed.
Most bottom line issue is that World Wide Web isn't Desktop Application no matter how much you'd want it to be. There's numerous issues involved, these are some which pop into mind:
WWW is stateless, desktop applications aren't. WWW is made stateful usually by cookies, URI parameters and session management and now that we've those for a couple of decades, we've mostly gone over the stateful/stateless issue of WWW.
WWW pages are (nowadays) described with some form of XML and usually CSS, in which the page is described as a tree. Comparing to Desktop Applications, while it's possibly to do nearly the same with XML and just plain component clustering, it just isn't the same. Once again one of the biggest issues is that in DA those components, widgets are stateful by nature on the application level while in WWW you can be truly stateful on the page level at most and even that requires JavaScript/AJAX.
So, direct use of layout managers is a no-go. But, assuming the Web UI Framework you're using allows it, you may create something that behaves quite similarly to layout managers. While I don't know about GWT specifically, I believe that one could do at least a simple layout manager in JSP (or my favorite, Apache Wicket) and make it behave just as the Swing layout managers do.
Note that I really do mean re-creating the whole concept of layout managers here as a set of specialized classes/whatnot, just as Peter Štibraný replied, GWT doesn't support them directly (in fact I haven't heard anything beyond Swing does) and I believe it would be more of an effort to create a wrapped/adapter for Swing Layout Managers instead of just creating your own, properietary ones for WWW.
IF you want a Swing Web application, consider AjaxSwing, but be prepared for network latency and consuming server resources. I think as soon as there's libraries for SVG/VML, we'll see more stuff move to the web. If you want to see a JavaScript IDE, check out Lively Kernel from Sun Labs. Have people tried porting Swing to GWT? It seems evident that there's AjaxSwing that a lot of Swing Could be ported to GWT, just perhaps not the Java2D stuff. Probably some smart company will figure out how to convert Swing to web client technology.
This question was originary in my head as "Can I use AWT controls in a Servlet?", which will show all my ignorance on the subject.
I am new to JAVA technologies but after a bit of reading, I seem to understand AWT controls directly hook up the OS GUI elements so there is no way to use or extend JPanels, JButtons and so forth in a Servlet to be injected in a JSP and let the browser render those controls (an alternative could probably be embedding an applet in a JSP but I don't wanna do that).
I am looking for a way of building custom re-usable web controls using JSPs and Servlets.
How is this usually done and can you provide some samples/links?
EDIT: This is part of a test run I am giving to the Google Application Engine - so it would probably make sense for me to explore the Google Web Toolkit - any pointers in that directions would be appreciated as well.
Any help appreciated!
AWT is the OS-specific part of UI rendering on desktop, not on the Web side of things in which JSP, Servlets etc. live. A bit more specifically, things like Swing (which has those JPanels, JButtons and so on you mentioned as UI components) and SWT are currently based on AWT and work on top of it to render the UI and allow it to work as expected.
Unfortunately all this means you can't use AWT based components on Web pages since, well, Web pages are (usually) platform agnostic in the sense that they don't get to decide exactly how parts of the UI are rendered, there's just a pile of markup which is treated as a sort of plea to the Web browser to do things the Web designer hopes for without 100% quarantee that the end result will be what the designer wanted.
There's been a lot of reinventing the wheel to achieve Swing/AWT kind of UI creation on the Java's Web side since it's a clever model, like you seem to already know Google Web Toolkit tries to do its part to make Web seem more like a desktop application while in reality it merely automates the needed JavaScript Ajax underneath to make the web page behave as if it was a desktop application. One another framework for this is Tapestry which I haven't personally used but some think it's a decent choice too.
And then there's of course my personal favorite Apache Wicket which allows you to have a true separation between Java code and markup and it behaves quite similarly to Swing UI code too! In fact there's a whole bunch of name collisions with Swing's UI component classes for the most simple things. Assuming you're any familiar with coding a desktop application UI I strongly recommend Wicket, it abstract away the boring and tedious parts (Servlets, URL resolving, page bookmarkability, security...) and replaces them with an event-driven model similar (but not equal) to Swing's EDT which is where the desktop UI magic would normally happen.
While this is going completely away from what you're looking for, with Wicket you can create such a set of POJO Web components that you can reuse them just about anywhere and thus get what you asked for. A word of warning though, Wicket assumes you really know how to code with Java and some laughably easy things may be tedious at first but in the end you should be quite happy with what you got.
In JSP you are probably looking for Custom Tags. Custom Tags are ways to create re-usable code components to be used in the display of JSP pages. There are some very nice ones out there such as those found in the struts2 framework or the display tags library.
But you can write your own or extend the existing ones with new functionality.