Help me with Java, specific problem to solve

Oct 27, 2007
17,009
5
0
I'm new to Java programming and I have a specific problem I need help with. A method of mine takes a Rectangle object as a parameter which is fine. What I need is to be able to have the program take over the whole screen (but keep all other windows visible, the program should be invisible). The user can click and drag the mouse to create a rectangle and on pressing "enter" my method will be called with this rectangle as a parameter.

I'm not even sure where to start with this problem to be honest. I have read a bit about MouseListeners and I'll be pouring through the API tonight to figure something out. The main thing I need help with is how can I create this environment where all windows remain on screen but the mouse will not interact with any of them. If anyone has used Windows Vista's Snipping Tool (try it now if you have Vista and haven't seen it) they will know what I mean.
 

SJP0tato

Senior member
Aug 19, 2004
267
0
76
There's a number of ways to go about completing your project, the best thing is to pick the one that seems most intersting, or most viable.

I can think of a couple off the top of my head:

One would be to use the built-in GUI tools with Netbeans. I've only done some peripheral experimentation with Netbeans, but it seemed like for graphical stuff (which I think is what you're working on) it had some very useful tools.

The second is implementing something in OpenGL. Unfortunately Java isn't as popular as C++ for OpenGL, and this is bound to be more complicated than the Netbeans method. On the other hand, if you find it interesting you might be able to learn how to do other, more powerful implementations as well.

Best of luck.
 
Sep 29, 2004
18,656
68
91
Review the Robot class. It is a good class to know about for the things you are talking about.

Consider extending the Window class so that it takes up the whole screen, and contains() always returns true. Making contains() return true at all times will cause your program to "steal" any clicks that would normally go to the visible (but not interactive) programs that are underneath your application window.

And over-ride paint() to do nothing. This will make your window steal mouse events. Remember to make the window occupy the entire screen! There is a simple way to get all the monitor information you need. I forget how. Use Google.

Just some ideas. Good luck. Tracking the mouse position on screen is easy. Preventing the mouse from interacting with other programs is the trick. I think I covered how to do that though.

If you want to monitor mouse events and then forward them onto the actual underlying window, you will need C/C++.

There is also a way to interact wit the AWT Event Queue, but I forget how. It's not something I spent alot of time caring about since I don't get paid to do things like this.