Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Making transparent frame!! urgent pls!!

843807May 7 2002 — edited Nov 9 2003
Hi to u all Java Gurus,

I have created a transparent frame with the help of a reply postd on this forum. it works fine,
as long as its stationary!!
one can see the underltying desktop through it.

but, what i want is that the frame should be transparent all the time even when i move it, iconify etc.
right now, if anyone can give me the solution only for moving the frame around and still make it transparent would be highly appreciated.

i tried using repaint() inside the componentMoved() method. that didn't work. then i tried getting the Graphics object of the frame inside this method using someG=this.getGraphics() and calling
paint(someG) method. that too, no use.

so if someone could tell me what code ahud i have to implement inside the componentMoved() method, i would be really greatful to that guy.

rgds

JP

the code is given below:

import java.awt.*;
import java.applet.*;
import java.awt.event.*;




class transFrame extends Frame implements WindowListener,ComponentListener{
Image img;
Rectangle rect;
Point p;
Robot r;

public transFrame(){
addWindowListener(this);
addComponentListener(this);


}



public void paint(Graphics g){

p=this.getLocationOnScreen();
rect=new Rectangle(p.x,p.y,400,300);
try{
r=new Robot();

}
catch(AWTException awe){
System.out.println("robot excepton occurred");
}

img=r.createScreenCapture(rect);
g.drawImage(img,0,0,this);


}


public void windowClosing(WindowEvent we){
this.setVisible(false);
this.dispose();
}

public void windowClosed(WindowEvent we){
}

public void windowOpened(WindowEvent we){
}

public void windowActivated(WindowEvent we){
}

public void windowDeactivated(WindowEvent we){
}

public void windowIconified(WindowEvent we){
}

public void windowDeiconified(WindowEvent we){
}


public void componentMoved(ComponentEvent ce){


repaint();

}

public void componentHidden(ComponentEvent ce){
}

public void componentShown(ComponentEvent ce){
}

public void componentResized(ComponentEvent ce){
}

}


public class trans{

public static void main(String args[]){

transFrame tp=new transFrame();
Button b1=new Button("Click");
tp.setSize(400,300);
tp.setLayout(new FlowLayout());
tp.add(b1);
tp.setVisible(true);
Graphics g=tp.getGraphics();
if(g!=null){
tp.paint(g);
}



}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 7 2003
Added on May 7 2002
31 comments
160 views