Java Tutorial: Working with Files and Directories in Java
To make a nice, graphical view we’ll need some graphics elements to put inside <img> HTML-tags. It’s like collecting a jig saw puzzle. If you look at figure 1 then you’ll see that we only need these 6 pieces:
I have made two directory images – since we’ll soon implement an open/close-directory function in our application. As you can see I’ve dropped the plus/minus-signs on the directory-pictures to simplify things a bit.
The pictures are made with a simple graphics utility (like Paint Shop Pro) using a few screen dumps with FrontPage pages. Be prepared to use some time to get the size of the pictures right — if you don’t simply use mine from the zip-file. Now it’s simply a matter of putting these pieces together to make a directory structure. To show you how it works let’s create figure 1 (without the text). The border of each picture has been made visible to show how it’s done:
To make the graphics view we’ll have to code a new version of MyFileStructure – the class that builds the output. A couple of notes about how this is done:
The “Explorer” class
The new class — called MyFileStructureExplorer (since it has a Windows File Explorer look) — may be coded like this: