free web hosting | website hosting | Web Hosting | Free Website Submission | shopping cart | Promoter Online | php hosting
affordable web hosting Pets web page hosting web hosting website hosting web hosting service web hosting web host
Java Programming Tips

Java Programming Tips

This page contains miscelleneous Java programming tips (tested under Java version "1.5.0_01" on Windows platform).

To test whether a removable drive is alive

To test whether a removable disk has a certain directory such as DCIM directory or not, use javax.swing.filechooser.FileSystemView class. Calling the usual File.isDirectory() will emit exceptions when the drive is not accessible.
  1. Call FileSystemView.getFileSystemView() and instantiate the FileSystemView class.
  2. Call FileSystemView.createFileObject(String path) to create a File object.
  3. Then call File.exists() to test the directory.
Click here for a snippet that tells whether I: drive has DCIM directory.

Popup Menu

Followings describe the steps to register a popup menu in response to a right mouse click.
  1. Instantiate JPopupMenu.
  2. Create JMenuItem's.
  3. Call addActionListener() and add an ActionListener to the JMenuItem.
  4. Use add() method to add JMenuItem's to the JPopupMenu.
  5. Add a MouseListener to the component from which the popup menu will be invoked.
  6. Set to call JPopupMenu.show() method to respond to mouse press and release actions in mousePressed() and mouseReleased(). Use isPopupTriggered to detect a right mouse click.
  7. Describe the action when the JMenuItem's are selected in actionPerformed().


Return to Home Page
Erica Asai
Last Modified: Sun Feb 27 18:07:21 2005