views:

418

answers:

2

Hi all,

I'm trying to create a java desktop application that holds desktop icons. The app will be a menu/panel that is invisible until you hover your cursor near the top of the screen, at which point the menu full of desktop icons will drop down. To add new icons to the menu one must simply drag icons from the desktop into the menu and they should snap to grid. As I am an intermediate level programmer but I havn't ever done a GUI app before in any language, I was wondering if someone could help me out, both with how to approach the problem and on the packages and methods I should be using. Also, I'm thinking of doing this with NetBeans unless you have any other suggestions.

Thanks, Andrew

A: 

You can use java.awt.MouseInfo to get the location of the mouse at any point in time, even if you don't have any windows open.

So, you could start a java program, then in your main loop poll the mouse location. If it's in the 'top', then you can open a window.

You can use the easiest thing to do would be to use JButtons or JLabels with images to represent the desktop icons. Just load the image you want to use and stick that on as a label.

I'd start by going through swing tutorial and writing a few simple GUI programs to get the hang of it.

But the MouseInfo thing is what you need to tell when the mouse is at the top of the screen.

Chad Okere
+1  A: 

As an alternative to Chad's option, you could also do this by creating a frame and using Java's transparent window capability to make the frame transparent (or translucent, if you want a hint that it's there), and using mouse entered/exited events to return the frame to its normal "solid" opacity.

Personally I'd try this solution just because I'd rather use event-based notification than polling the mouse position, but I expect it's more work than the other alternative.

As to drag and drop, I haven't used it extensively enough in Java to give any solutions, but it's not immediately obvious (from a cursory internet search) of how to handle native desktop drag and drops. I'd suggest starting with some dnd tutorials within an application so that you really understand Java's drag and drop API and capabilities.

Ash
+1 for avoiding mouse position polling.
tangens