Is everything possible with Java?
Hello!I use to say that everything is possible with Java but perhaps it is not?
I saw this simple but fly app and wondering if it is possible to do the same with Java but now I guess that it is not possible. The simple app is a calipers for pixels that actally always is on top of everything even above the appbar at the bottom of your desktop in win 2000.
You can download it at:
http://www.ksurf.net/~bermania/prog/dessin/prdessin034.html
My attempt to doing something like that is (with a lot of help of people at eksperten) by copying the desktop-image as a background but perhaps they not use that strategy in calipers.exe.
In this app thay also got the app to be on top always. Perhaps that is impossible for us Java developers.
Hope for a nice and giving conversation.
Best regards
Fredrik
My attempt with a fictiv transparent window:
package glasswindow;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class GlassWindowTest extends JWindow implements MouseListener, MouseMotionListener
{
private Image screen;
private Image backBuffer;
private Graphics backGraphics;
private Dimension preferredSize = new Dimension(250,200);
private Dimension screenSize;
private Rectangle screenRectangle;
private int xdiff = 0;
private int ydiff = 0;
private static Robot robot;
private Dimension windowSize;
private int newX;
private int newY;
private boolean first = false;
private java.awt.Point mouseP;
private double oldPosX, oldPosY, mouseFirstX, mouseFirstY, mouseNowX, mouseNowY;
public GlassWindowTest()
{
super();
JPanel content = (JPanel) getContentPane();
content.setOpaque(false);
setSize( getPreferredSize() );
windowSize = getSize();
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
screenRectangle = new Rectangle();
screenRectangle.setSize( screenSize );
Rectangle bounds = getBounds();
newX = (screenSize.width - bounds.width) / 2;
newY = (screenSize.height - bounds.height) / 2;
try
{
robot = new Robot();
}
catch(Exception e)
{
e.printStackTrace();
}
addMouseListener( this );
addMouseMotionListener( this );
copyScreen();
setSize(250, 200);
centerFrameOnScreen();
show();
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
if(backBuffer == null)
{
createBackGraphics();
}
if( screen != null )
{
backGraphics.drawImage( screen, 0, 0, windowSize.width, windowSize.height, newX, newY, newX+windowSize.width, newY+windowSize.height, null);
}
backGraphics.setColor(Color.red);
backGraphics.fillOval(50, 50, 50,50);
g.drawImage(backBuffer, 0, 0, null);
}
private void createBackGraphics()
{
backBuffer = createImage(250, 200);
backGraphics = backBuffer.getGraphics();
}
public void centerFrameOnScreen()
{
setBounds( newX, newY, 250, 200);
}
public void copyScreen()
{
screen = robot.createScreenCapture( screenRectangle );
}
public Dimension getMinimumSize()
{
return this.preferredSize;
}
public Dimension getPreferredSize()
{
return this.preferredSize;
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
first = true;
}
public void mouseDragged(MouseEvent e)
{
mouseP = e.getPoint();
if(first)
{
mouseFirstX = mouseP.getX();
mouseFirstY = mouseP.getY();
}
mouseNowX = mouseP.getX();
mouseNowY = mouseP.getY();
oldPosX = this.getX();
oldPosY = this.getY();
newX = (int)((oldPosX + mouseNowX) - mouseFirstX);
newY = (int)((oldPosY + mouseNowY) - mouseFirstY);
setLocation( newX, newY );
repaint();
first = false;
}
public void mouseMoved(MouseEvent e)
{
}
public static void main(String[] args)
{
GlassWindowTest glassWindow = new GlassWindowTest();
}
}
