hi guys,
i am making a frame/window transparent, so that my application will look like a desktop application, since i will be able to have my own design instead of the regular rectangula shapes.
i have used java.awt.Robot class for this purpose.
i have managed to some extend to get what i want. ie if the frame sits idle at one location only, i am able to see the desktop screen right through the frame, though its components (in my case a single Button, for simplicity) reamins visible. thats perfectly fine!
the problem starts once i decide to drag the frame around the desktop!!! i keep on seeing the initial screen portion captured when the frame first became visible!!!
i have tried all possibilities of passing the Graphics context of the frame from the componentMoved() method, to just calling repaint() method from inside the componentMoved() method.
i can't understand this!
can anyone help me on this, on how to write a code inside the componentMoved() method or the paint() method ?
i would be really appreciated if you could!
i'm reproducing the code for your inspection and trial run.
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
public class transFrame extends Frame{
Image img;
Rectangle rect;
Point p;
Robot r;
MediaTracker mt;
public transFrame(){
addWindowListener(new myWindowAdapter(this));
addComponentListener(new myComponentAdapter(this));
}
public void update(Graphics g){
paint(g);
}
public void paint(Graphics g){
try{
r=new Robot();
}
catch(AWTException awe){
System.out.println("Robot exception occurred");
}
catch(SecurityException se){
System.out.println("Robot object could not be instantiated");
}
p=this.getLocationOnScreen();
System.out.println("frame window at location : "+p.x+", "+p.y);
Dimension d=this.getSize();
img=r.createScreenCapture(new Rectangle(p.x,p.y,d.width,d.height));
mt=new MediaTracker(this);
mt.addImage(img,1);
try{
mt.waitForAll();
}
catch(InterruptedException ie){
System.out.println("Problem in loading the transparent image");
}
g.drawImage(img,0,0,this);
img.flush();
} // end of paint()
public static void main(
String args[]){
transFrame transparent=new transFrame();
Button b1=new Button("Click");
transparent.setSize(400,300);
transparent.setLayout(new FlowLayout());
transparent.add(b1);
transparent.setVisible(true);
Graphics g=transparent.getGraphics();
transparent.paint(g);
}
} // end of transFrame
class myWindowAdapter extends WindowAdapter{
transFrame frame;
public myWindowAdapter(transFrame frame){
this.frame=frame;
}
public void windowClosing(WindowEvent we){
frame.setVisible(false);
frame.dispose();
System.exit(0);
}
} // end of myWindowAdapter
class myComponentAdapter extends ComponentAdapter{
transFrame frame;
Image img;
Robot rbt;
public myComponentAdapter(transFrame frame){
this.frame=frame;
}
public void componentMoved(ComponentEvent ce){
//Graphics g=frame.getGraphics();
//frame.paint(g);
frame.repaint();
}
} // end of myComponentAdapter
// end of program