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.
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 ]
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.
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.
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!
Joined: Feb 09, 2007
Dear all, Thanks for the suggestions and ideas. Will do as suggested. Regards.