Q1. Explain the concept of handling image in Java GUI application with example ?
Ans. Handling images in an application is a common problem for many beginning Java programmers. The standard way to access images in a Java application is by using the getResource() method. This tutorial shows you how to use the IDE's GUI Builder to generate the code to include images (and other resources) in your application. In addition, you will learn how to customise the way the IDE generates image handling code.The application that results from this tutorial will be a simple JFrame that contains one JLabel that displays a single image.
Creating the Application
(a) Choose File > New Project.(b) In the New Project wizard, select Java > Java Application and click Next.
(c) For Project Name, type Image DisplayApp.
(d) Clear the Create Main Class checkbox.
(e) Click Finish.
When you use images or other resources in an application, typically you create a separate Java package for the resources. On your local file system, a package corresponds with a folder.
Adding Package for the image
(a) In the Projects window, right-click the org.me.myimageapp node and choose New > Java package.(b) Adding a new Java package.
(c) Click Finish.
(d) In the Projects window, you should see a new package appear within the Source Packages folder.
(e) Projects window.
Displaying the image on the Label
In this application, the image will be embedded within a JLabel component.(a) In the GUI designer, select the label that you have added to your form.
(b) In the Properties window, click the Properties category and scroll to the Icon property.
(c) Click the ellipsis (..) button.
(d) The icon property editor is displayed.
(e) In the icon property dialogue box, click Import to Project.
(f) In the file chooser navigate to any image that is on your system that you want to use. Then click Next.
(g) In the Select target folder page of the wizard, select the newpackage folder and click Finish.
(h) Click Ok to close the icon property dialogue box.
After you click OK, the IDE does the following things:
(a) Copies the image to your project. Therefore, when you build and distribute the application, the image is included in the distributable JAR file.
(b) Generates code in the ImageDisplay class to access the image.
(c) Displays your image on the label in the Design view of your form.
[ Topic = Handling image , GUI Application in Java ]
[ Topic = Handling image , GUI Application in Java ]
Join us on Facebook and Twitter to get the latest study material. You can also ask us any questions.
Facebook = @ studywow
(click on it or search "studywow" on facebook)
Twitter = @ studywow
(click on it or search "studywow" on Twitter)
Email= studywow.com@gmail.com
Send us your query anytime!
[ Topic = Handling image , GUI Application in Java ]
[ Topic = Handling image , GUI Application in Java ]