Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Why is Swing preferred over AWT?

Which Swing component could be used for playing a video on it?

share|improve this question
add comment

closed as not constructive by MainMa, Walter, ChrisF Oct 5 '11 at 12:38

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers

up vote 10 down vote accepted

AWT is older than Swing and supports only a limited set of components. Otherwise you have to write your own such as tables/data grids for example (typically, you will have to write your own video player, good luck !). Swing is more "modern" as Sun engineers learned from their AWT mistakes and made something better, albeit more complex. Both Swing and AWT are event-based so if you know event-driven programming you will be at home. The learning curve is a bit steeper with Swing because of the larger number of available classes, though by practicing a bit with tutorials you should quickly be fine.

Check out this IBM presentation on SWT, Swing & AWT, it really is a good read. Also AWT vs Swing.

As to how you can play video on Java: http://stackoverflow.com/questions/4569490/how-to-play-video-in-java-using-swing

share|improve this answer
add comment

AWT components are essentially a thin layer on top of native OS GUI controls. To draw for example a checkbox, AWT components were calling underlying OS. Such approach caused two problems:

  • the same app had a bit different GUI behaviour under different OS
  • overcoming known differences caused AWT code to be bloated and IIRC a bit buggy

Because of this connection between AWT component and underlying OS control AWT controls were called "heavyweight". In contrast Swing offers, so called "lightweight" controls. They are purely Java, have no dependency on underlying OS and basically "draw themselves" using Java2D primitives (pixels, lines, brushes and so on). This approach has several advantages but what is most important -- it fixes AWT outstanding problems mentioned above.

As for Swing component for video playing, I don't think there is one, at least among standard Swing components. You may want to google for one, as it probably is already written. You can also look at JMF API, but I think you'd have to code a few bits yourself before you can display video.

share|improve this answer
add comment

1) AWT is prehistorical FrameWork and is strong based on Windows OS

2) Swing is GUI FrameWork based on AWT, all JComponent inherits or implemetns part of usefull methods from ATW Components, sure if exist,

3) Swing implements a few of new JComponents, for example JTable, best from comparison table here

4) for video and multimedia are there lots of Custom API, (never use that) but I think that based on AWT Canvas

5) since as of the JDK 6 update 12 and JDK7 build 19 releases, promiss that you can mixing AWT and Swing Components, but don't suggest to do that, Components are painter in the Container correctly, but still there exist same difference betweens heavyweight and lightweight components as before, and you have to calculate with that

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.