Drawing outside a window in Java? - java

Is it possible to simply paint() (or use some other function) to the screen in Java? As in draw over everything else on some coordinates of the screen itself, not inside some window.
If not, is it possible to make an invisible window that takes up the entire screen and use its glass pane to do it? Would complications arise from doing this? (Such as not being able to click on other applications)
Are there any other ways?
Thanks.
Edit: I'm not trying to do full screen with this, by the way.

When you paint() in Java, you're painting only within the confines of the size and location of what is being paint()ed.
If you're looking to do full screen stuff, there are tutorials for that:
http://download.oracle.com/javase/tutorial/extra/fullscreen/index.html

In theory, you can create an transparent undecorated maximized JFrame. This will allow you to "paint" over the desktop. Problems are obvious: if an application stays behind this window, it will not receive any mouse events.
Months ago, I made an evil cheat to draw directly on Windows Explorer's Desktop: mixing some .NET coding with JNI and Sun's internal classes - that's surreal, but works.

Related

Jframe loading window in java

I need to do a loading window in java like this:
I tried with the jframe but I can't figure it out, I can't remove the close button, my jframe should look like a jpanel before that program begin, somebody know how to do this.
You Could...
Use Java's inbuild splash screen support. This is good as it gets loaded relatively earlier in the process by the JVM itself, so it comes up reasonably quick.
The major drawback (in my opinion) is it can be troublesome to get right as it doesn't follow the standard painting process that most developers are use to and you are going to have to paint it all yourself, there's no component support
How do I use SplashScreen without throwing a NullPointerException?
How to Undo the splash screen painting in java
Splash Screen Progress bar not drawing
You Could...
Create a JWindow. This is a frameless window, which won't appear on the taskbar (at least for some OSs).
You gain complete control over what and how things get displayed, as it's like dealing with any other window.
The only problem is that it won't become available for you to load until the JVM has completed loading your application. If the JVM needs to download resources over the network, for example, this could produce an undesirable delay
For example
Splashscreen in Java
SplashScreen java change alpha
Why won't this draw the image?
You Could...
Use an undecorated frame. This is pretty much the same as the JWindow option, except that a taskbar icon will be displayed, but on some OSs, this can't be completely helped.
See Frame#setUndecorated for more details
Final thoughts
Swing is not thread safe. So if you're displaying a splash screen, this means you should be ensuring that whatever actions you are taking are done off the Event Dispatching Thread, possibly through the use of SwingWorker

Drawing overlay on screen in C++ or Java

Is there any way to draw an invisible overlay on top of the screen (meaning in front of all windows and everything else) in C++ and/or Java?
It doesn't need to support 3D graphics or anything fancy, I just need to be able to draw
lines/pixels on it.
There are some other solutions that I found on the internet, but they all either
1) don't allow mouse clicks to go through them (onto the windows or other stuff under it) or
2) are only for Windows (I need something that works on Windows and Linux, but Mac support would also be nice).
One easy way could be create a transparent window which fits on the entire screen size, and lock it at the top of the z-order stack.
Thats what I usually do when write screensavers.

How to make overlay for video in swing

I want to make a transparent overlay for a foreign project to show live video. Sample of overlay is given in the image link below. In image you can see a overlay at right bottom corner showing face of a person, I also want to achieve same functionality using JMF to show face and then display the face in overlay using swing.
Sample Overley Imahe: http://www.ovostudios.com/images/vidsamsolo.jpg
Can someone help achieving this functionality?
If you're just starting the project and haven't actually got the JMF part up and running yet, then you might want to take a look at some alternatives before committing to it.
If you want to go ahead with Swing, to get the general overlay behaviour you want, you'll need to make use of Frame.setUndecorated() to turn off window borders and buttons, and Window.setAlwaysOnTop() to make sure the window stays on top of other windows. For the transparency, see this tutorial. However, I'm not sure whether transparency and video will work nicely together, so good luck!
You might also want to write a custom focus handler for the window so that it cannot be focused, although it is probably impossible for the overlay to be properly 'phantom' whereby clicks just pass through the overlay to the underlying desktop. That kind of behaviour might only be possible by using low-level graphics techniques i.e. by not creating a window at all, but by drawing directly onto the screen. That might require a native library.

how to create a drop down menu java app on the desktop to hold desktop icons (java)

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
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.
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.

Mouse Listener Question

I am developing a screen capturing utility in Java & I want to capture any background window, when I click on that particular window. But I am not getting how to add mouseClicked event to background window. Can somebody please help me?
I may be way off base but if the other window is not a Java window then it should be outside the Java sandbox. To interact with it requires a native API which is anathema to Java.
Quite obviously as it is you can't interact with other application windows. It can be any random window in your case I presume. Therefore, your mouselistener approach is not correct.
Rather, try to approach it like fetching pixel information displayed on the screen. There is an awt package java.awt.Robot or something that could be used for your purpose. If you want to implement capturing of active window then see if there are java APIs to interact with O.S. and get information of current active window and it's pixel co-ordinates. The co-ordinates could then be supplied to the rectangle attribute that is used with java.awt.Robot APIs to define screen capture area.
If that window is not part of your application you can't do much with it.
Otherwise you just have to add the mouse listener to that window too.
What's your situation?
java.awt.Robot has a method createScreenCapture(Rectangle screenRect) to capture screenshots.
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Robot.html
however, to get the current active window you would have to use OS specific extensions (mostly via JNI)

Categories

Resources