very confused about java graphics, swing, awt, applet, etc...
hello, i'm really stressing about this. it seems that there are so many different ways you can make graphics in Java and i need to straighten things out.
i started out making Java applets by extending the Applet class and using these built in methods to get input ( no listeners ) . I also used the paint() method to draw everything, I used no GUI elements. then I learned that that JApplet is the new thing to be using ( is this true? ) and its part of the swing classes, but I still used awt.Color, Graphics, and awt event listeners. currently, im using that and im drawing in my own panel class that I extended from JPanel, and it has its own paintComponent method instead of using a paint mehtod in the main body. just now, i read the beginning of a tutorial that said swing and awt were to different alternative methods of achieving the same thing. meanwhile im using them in the same program. i'm really confused as to whats deprecated, and whats the current and accepted way to do things. i know i've asked a similar question regarding Applet and JApplet, and I understand that difference, but I need something more concrete. Every tutorial i find online does something differently. Some on the sun website are talking about Java 1.2, meanwhile im using 1.5. Thanks a lot for taking the time to read this..
A very interesting question. One that made me want to dig into it for an answer as well. Here's what I came up with:
When you think of Swing (aka the Java Foundation Classes). Think of 'JButton', 'JFrame', 'JScrollBar', 'JApplet', J this, J that.
When you think of AWT, think of 'Button', 'Frame', 'ScrollBar', 'Applet', etc, etc, lots of graphical stuff without the 'J'. These indeed fall under AWT if you look them up.
AWT (Abstract Windowing Toolkit) was the first type of GUI for java since Java 1.0.
Some time ago, they realized there were some bugs and inconsistencies with AWT that were very hard to fix.
Here is the reference for that:
some awt info
Anyway, when Java 1.2 came around they decided to do a more standardized and consistent GUI approach with Java Foundation Classes (JFC), aka Swing.
This seems to be a complete redesign with consistency implied from the ground up.
Then, later on (you'll find in the above reference) they tried to fix AWT with Java 1.4. They successfully fixed a lot of the bugs, glitches, etc and made it apparently somewhat better.
I think what you're looking at is old-school vs new-school. I think they kept AWT to keep their old-school following, which makes sense. You don't want to piss off the people who helped get Java off the ground.
My personal observation is that Swing is simply superior in almost every way. If you do a side by side comparison of Button vs JButton, Frame vs JFrame in the API docs it is clear the 'J' wins with features every time. Try it for yourself.
JFC/Swing seemed to be designed from the ground up with reliability and consistency in mind. AWT was started with good intentions, was buggy, later patched up, and is still here but not bragged about.
If you look at their main page for the Java 2 platform (1.4.2, and 1.5.0), they never mention anything about AWT. It's always about Swing/Java Foundation Classes.
Apparently 'Swing' was the project code name for the Java Foundation Classes, and it stuck.
In a nutshell AWT = old and busted, Swing/JFC = the new hotness.
Btw, all you old schoolers please don't flame me I'm just reporting what I got out of the docs
wow thanks alot. thats exactly what i wanted to hear. thanks so much, so swing all the way for me i suppose.
No problem, it answered some of my own questions. As a followup, I noticed that some things that AWT does for you are not available in Swing. Such as Java.awt.Color, and java.awt.Graphics.
I think they kept the parts of AWT that worked well and upgraded the parts that did not. So you probably will be using both of those component types from what you've described.
I think the idea is the complicated user interface items were replaced/upgraded, while the general graphics abilities such as colors and 2D drawing were kept under the AWT name. Even though they were improved on greatly, they kept the AWT name.
So if you can, use Swing. If it doesn't have what you are looking for use AWT.
I just wanted to add this to Philwx excellent resume of the java language development:
The big deal in the 90's was that java code could run on any platform (windows, mac, unix) and still have the same look and fee w.out changing or even recompiling the code, the java VM should handle all that jazz, but the old awt didn't. The introduction of swing should fix that.
If that is the case today ? hmm, not sure, don't think so...
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL