[java] Newbie questions - AWT vs Swing

Started by
7 comments, last by stecal849 17 years, 11 months ago
Hi, I am new to java but am pretty good with c# so getting my first few java programs up and running weren't a problem. I am reading different articles on the web about awt vs swing ect and can't quite tell what is the standard practice for gui's and java 1.5 Opinions seem to change depending on the date of the article so i was hoping someone here could get me up to speed on what to learn. Basically, i want to be able to write a standard app with a main window, menus and the usual windows stuff. Should i learn awt or swing? Also, i am using netbeans and ws wondering if there was anything i should be aware of when using the gui maker thing :) Thanks
Advertisement
Hi,

Swing is a set of LIGHTWEIGHT components, that is, components that are independent of native calls of the OS - which is not the case for AWT, who is a set of HEAVYWEIGHT components.

I'd advise you to learn swing without an editor, first. It is of utmost importance that you learn the basics of swing before attempting to "draw" components in a tool that generates code for you, because it will be a mess to work with that code without knowing the basics of swing workflow.

Son Of Cain
a.k.a javabeats at yahoo.ca
Swing all the way. It's easier to use, it looks the same on every OP(thought it might look different on older versions of the JVM), it looks ten times better, and AWT had text displaying problems on every computer I used.
-----------------------------------------Everyboddy need someboddy!
Thanks Cain :)
AWT is supported but obsolete, only old apps use it. Swing has much more advanced features. AWT used to be faster many years ago, but now Swing is well optimized and it even has hardware acceleration.
Only AWT widgets are obsolete: Swing is layered (some would say bolted...) on top of the basic AWT mechanisms and semi-compatible with it, allowing ugly and buggy mixed GUIs.
This legacy causes some confusion and complication due to compatibility kludges (e.g. Graphics and Graphics2D, Component and JComponent) and superseded interfaces leaving lots of reasonable-looking but wrong and dangerous methods in the widget classes.

Currently, the only significant alternative to Swing is SWT from the Eclipse project; it uses native widgets like AWT, with the same portability problems and bonus installation complexities, it is acceptably fast, and it is much less sophisticated than Swing (i.e. easier to understand and simple, but primitive and limited for practical use).

Omae Wa Mou Shindeiru

I'd suggest learning AWT first because it is the foundation for Swing. Several pre-existing applications use it so it's important to know how to work with it. It doesn't mean you need to build new projects with it. It will help you understand what the need for Swing is, and how the details differ.
AWT is practically dead so I wouldnt bother with it, you could spend your time bettering your skills at Swing or MFC than AWT. However i'd highly recommend writing Swing code manually i.e. Do not use Netbeans built in editor. I find this way your code stays clean and you can easily employ object orientated methodology through programming components instead of dragging and dropping them onto a Jpanel etc. However each to their own, and anyway, Swing is very simple to use.

I would recommend Eclipse as an editor. It practically codes for you.

Good Luck

Ste
Dead? HAHAHAHAHA! Considering all the pre-existing programs out there (10 years) to modify & upgrade from time to time, obviously a clear understanding of AWT is important. If you don't know how to use AWT, it is difficult to use Swing effectively. Don't worry, learning AWT is learning Swing - just add a J :) It's the same thing with C and C++ programming. Being a good programmer is knowing where one ends and where the other begins. Java has that same requirement on the job. Anyway, learn things from the bottom up is my advice. I recommend Swing in the long run, though. It's more portable and extends major functionality to the old AWT components.
Ok dead was the wrong term. It wouldnt hurt to know AWT however I would start off with Swing. Its the most used and tbh if your familar with Swing your familiar with AWT.

This topic is closed to new replies.

Advertisement