File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

learning swing ....

 
mark stone
Ranch Hand
Posts: 417
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am starting out with swing. (awt was simple and fun to learn and easy too...)
there is a prefix 'J' for similar classes in awt. (looks though from the api heirarchy)
like Component (in awt) and JComponent (in swing) but then there is nothing as JContainer ?
can someone let me know some sort of similarities etc between swing and awt so that learning can be easy and logical too ?
(one difference was with how we add components in awt and swing, any other differences... )
and the class JColorChooser, wow what a class.... its a full fledged application ! any other such noteworthy classes !!!
 
Rajendar
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mark stone:
i am starting out with swing. (awt was simple and fun to learn and easy too...)
there is a prefix 'J' for similar classes in awt. (looks though from the api heirarchy)
like Component (in awt) and JComponent (in swing) but then there is nothing as JContainer ?
can someone let me know some sort of similarities etc between swing and awt so that learning can be easy and logical too ?
(one difference was with how we add components in awt and swing, any other differences... )
and the class JColorChooser, wow what a class.... its a full fledged application ! any other such noteworthy classes !!!
 
Rajendar
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mark,
yes swing is very powerful when compared to awt.
it got a lot more useful classes which makes life easy.
The eventhandling mechanism is the same as in Awt ,but u can achieve a lot than that in Awt.
classes like JTable,JTree which help u create tables and trees directly,which wasnt possible in AWT.
Like this there are a lot more useful classes.Learning swing is not difficult.
Hope this helps..

Originally posted by mark stone:
i am starting out with swing. (awt was simple and fun to learn and easy too...)
there is a prefix 'J' for similar classes in awt. (looks though from the api heirarchy)
like Component (in awt) and JComponent (in swing) but then there is nothing as JContainer ?
can someone let me know some sort of similarities etc between swing and awt so that learning can be easy and logical too ?
(one difference was with how we add components in awt and swing, any other differences... )
and the class JColorChooser, wow what a class.... its a full fledged application ! any other such noteworthy classes !!!
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Mark. yes you are right Swing is much better than awt. the reasons for that is that awt uses the native system for its graphics and thus need to look for the lowest common thing in order to support all the platforms. swing is platform independant and all will look the same on all platform !
the main diffrences i can think of are:
1) like you said, all components in swing begin with a capital J .(notice that not the layout , only the components).
2) you dont add components to a JFrame directly, like you did with frame but you use its content pane to add things to it.
3) there is another layout called BoxLayout added to the regular use of layouts.
4) There is no longer an equivalent of Canvas. use JPanel instead.
5) Checkbox is now JCheckBox (notice the capital B).
6) to make radio Buttons you dont do it as you did in awt. you now have a class called JRadioButton and you add those radiobuttons to a class called ButtonGroup. (no J here too).
7) to set the menu in the JFrame use the method : setJMenuBar (not setMenuBar).
8) dont juse SWING components with AWT components cause it messes up the graphics.
9) there is JComboBox instead of Choice class.
10)you can use the function setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) so that it will close when u press the x (you dont have to write a listener to do that like in awt).
11) you have diffrent look and feels
12) You can use icons in buttons and labels with ImageIcon.
13) use can use HTML as text in buttons and labels.
14) You have borders you can add to components.
15) you have the JOptionPane to show simple dialogs and the JColorChooser and JFileChooser dialogs made for you.
16) you have ToolBar, Tooltip and ProgressBar you can use.
17) and many many more speacial panels like: splitpane,scrollpane,tabbedpabe,desktoppane etc..
here is a good link to sum it all up:
swing link
[ March 04, 2002: Message edited by: Roy Ben Ami ]
 
mark stone
Ranch Hand
Posts: 417
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it says it all Roy. roy, you need to author a book. your explainations are to the point and would be very helpful to give the full worth of buying a book !!!
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Mark!
im glad you find it helpful!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,

Welcome to the wonderful world of Swing!

Roy Ben Ami has already pointed out most of the differences between Swing and AWT... but the best way to learn is to do it!

I would go through Sun's Swing tutorial first - link here. This will give you a good overview of Swing.

Then, I would work on making simple GUIs using the "J" versions of AWT components.

Then I would start learning some of the more difficult components like JTree and JTable.

The best book I have found on Swing so far is David M. Geary's "Graphic Java 2 - Mastering the JFC : Vol II - Swing". However, I would go through the tutorials first... the book is great for high level stuff, but not too great for just starting out. I'm still working my way through it (it is a biiiig book!), but it gives new insights an useful information in every chapter...

-Nate
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic