Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help GUI

 
Shouvik Biswas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Java and wish to create GUI applications (windows look) using Java. I was going through swing-tutorial in <java.sun.com> site. Its vast and am unable to relate one chapter to the other. Is there any good book or site that I may go through to learn on how to do this.
PS: Though i must tell you that I am not aware of AWT, however aware of Core Java.
Any help is appreciated.
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can understand your predicament.
One way of tackling it is starting of small and building up on it, while learning on the way.

I personally found Core Java by Horstmann and Cornell very easy to understand. Needless to say, others can recommend more books/sites.

AWT was the precursor of Swing.
If you google for AWT Swing difference, you can find out more information.

I am moving this to the Swing forum where you stand a better chance of getting help and ideas.
 
Brian Cole
Author
Ranch Hand
Posts: 907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bharat Chatla:
I have a pixel array and I want to write that image to disk. Below are the methods but when I run the program I get NullPointerException.


Exception in thread "main" java.lang.NullPointerException
at java.awt.image.SinglePixelPackedSampleModel.setPixels(Unknown Source)
at java.awt.image.WritableRaster.setPixels(Unknown Source)


WritableRaster.setPixels is documented to throw NullPointerException if the array in null, so I'd look there first.

Stepping back a bit, what is this code supposed to do? It seems to me that it is
1) creating a blank BufferedImage
2) obtaining a copy of its pixel data (as a Raster)
3) casting the Raster to a WritableRaster (which is not guaranteed to succeed)
4) altering the pixel data (the copy, not the original)
5) returning the still-blank BufferedImage

Presumably, this is not your intent.

PS. JavaRanch admins, for some reason clicking on the "quotes" button resulted in the post going to this different thread. [update: same URL as this thread--see here] Configuration issue? So now I'm trying it with the "post reply" button at the bottom of the page.
[ November 04, 2008: Message edited by: Brian Cole ]
 
Shouvik Biswas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh,
Thanks for helping me and putting the request on the swing forum. Will try the recommended books. However, the swing forum didn't help yet. Any further suggestions...

Regards.
 
Jorge Bendahan
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's something like this:
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
got the code from: http://java.sun.com/developer/JDCTechTips/2004/tt0309.html
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shouvik Biswas:
However, the swing forum didn't help yet...


If you spend any time here, you'll find that our ability to help often depends upon the question. Very specific questions often get very specific and helpful answers. Your question however is very broad. I can only second the Core Java recommendation as I have both volumes and find them to be very helpful, and also I recommend that you continue to go through the Swing tutorials on the Sun site as with time and concentrated effort, it will eventually all click together. In fact a good plan would be to tackle a tutorial section or two each week and come back here if you have any specific point of misunderstanding from the tutorial. Much luck.
 
Jorge Bendahan
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jorge Bendahan:
it's something like this:
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
got the code from: http://java.sun.com/developer/JDCTechTips/2004/tt0309.html


totally misinterpreted the question, sorry...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> and wish to create GUI applications...

your question is similar to
"I wish to build a car, are there any good step-by-step books"

the answer is you don't 'build a car', you instead build a motor, a gearbox, a chassis etc
and you put them all together - end result is a car.

in swing, you plan (depending on funcionality) what components to use,
(V8 or 6-cyl, auto gearbox or manual etc).
after determining the components to use, you choose what layout manager/s
will best display those components (soft-top/hard-top, 2-door/4-door etc)

at the end you'll have a GUI, and there's not a book in the world that would have been able to describe step-by-step how you did it.

the swing "How To's" page is worth bookmarking

http://java.sun.com/docs/books/tutorial/uiswing/TOC.html
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Pete and Michael.
Best way to learn is start off small and keep on building on it.

Why don't you try out something simple (a notepad like text editor maybe) to start with? If you get stuck on anything, you can always post your problematic code here and I am sure people will lend a helping hand. The demo/jfc directory of your jdk installation should have a SwingSet jar. If you run it, you can get an idea of what all things are possible in Swing.

Pssst. You might feel a bit awkward initially as you might find your questions silly. But if you browse the forums, you will come across questions which are even sillier
So go ahead! Ask away!
 
Shouvik Biswas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
Thanks for the suggestions and ideas. Will do as suggested.
Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic