Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

Display a File from FileDialog

 

Training Index

by jGuru

Help  API Docs  About This Short Course  Short Course  Exercises

Create an application that instantiates and shows a FileDialog. Use getFile() to obtain the selected filename and display it as a label.

Skeleton Code

Tasks


1. Create a Frame to use as a parent and then create a FileDialog attached to that frame with a title of "Open". Show the file dialog. The current thread will block (unlike a pure Dialog object). Print to standard output the filename you typed in or selected--handle a null value gracefully. Do not forget to dispose of the frame you created.

Where help exists, the task numbers above are linked to the step-by-step help page.

Solution Source

Demonstration

This program cannot be run as an applet because opening a FileDialog is a security violation. Please run the solution DisplayFileDialog from the command line as an application.

Next Exercise

Exercises

Short Course

Copyright 1996-2000 jGuru.com. All Rights Reserved.