Pessoal estou com um serio problemia, estou criando um player e por cima do player tenho uma janela transparente com algumas imagens que irao aparecer sobre o player, sendo q o problema e que no primeiro player a transparencia fica ok e consegue acompanhar o andamento do video, quando passa a executar o segundo video pq é uma lista de videos, a janela de tranparencia nao consegue acompanhar o video…fica como se fosse tirando foto do screen e carregando…alguem pode me ajudar em criar uma tela transparente que acompanhe o andamento de um video ??
import java.awt.AlphaComposite;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class TransparentBackground2 extends JComponent implements ComponentListener, WindowFocusListener,
Runnable {
private JFrame frame;
protected Image background;
private long lastupdate = 0;
public boolean refreshRequested = true;
public TransparentBackground2(JFrame frame) {
this.frame = frame;
updateBackground();
frame.addComponentListener(this);
frame.addWindowFocusListener(this);
new Thread(this).start();
}
public void updateBackground() {
try {
Robot rbt = new Robot();
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dim = tk.getScreenSize();
background = rbt.createScreenCapture(
new Rectangle(0,0,(int)dim.getWidth(),(int)dim.getHeight()));
} catch (Exception ex) {
// p(ex.toString());
ex.printStackTrace();
}
}
public void paintComponent(Graphics g) {
Point pos = this.getLocationOnScreen();
Point offset = new Point(-pos.x,-pos.y);
g.drawImage(background,offset.x,offset.y,null);
Graphics2D g2d = (Graphics2D) g;
drawSquares(g2d, 7 * 0.1F);
}
private void drawSquares(Graphics2D g2d, float alpha) {
g2d.setComposite(makeComposite(alpha));
ImageIcon Imagem2 = new javax.swing.ImageIcon( "globo.jpg" );
Image Ico2 = new ImageIcon(Imagem2.getImage().getScaledInstance(40, 40, 1)).getImage();
g2d.drawImage(Ico2, 350, 320, this);
}
private AlphaComposite makeComposite(float alpha) {
int type = AlphaComposite.SRC_OVER;
return (AlphaComposite.getInstance(type, alpha));
}
public void componentShown(ComponentEvent evt) { repaint(); }
public void componentResized(ComponentEvent evt) { repaint(); }
public void componentMoved(ComponentEvent evt) { repaint(); }
public void componentHidden(ComponentEvent evt) { }
public void windowGainedFocus(WindowEvent evt) { refresh(); }
public void windowLostFocus(WindowEvent evt) { refresh(); }
public void refresh() {
if(this.isVisible() && frame.isVisible()) {
repaint();
refreshRequested = true;
lastupdate = new Date().getTime();
}
}
/* private boolean recurse = false;
public void quickRefresh() {
p(“quick refresh”);
long now = new Date().getTime();
if(recurse ||
((now - lastupdate) < recurse =" true;" location =" frame.getLocation();" recurse =" false;" lastupdate =" now;" now =" new"> 1000)) {
if(frame.isVisible()) {
Point location = frame.getLocation();
frame.hide();
updateBackground();
frame.show();
frame.setLocation(location);
refresh();
}
lastupdate = now;
refreshRequested = false;
}
}
} catch (Exception ex) {
p(ex.toString());
ex.printStackTrace();
}
}*/
public void run() {
try {
while(true) {
Thread.sleep(250);
long now = new Date().getTime();
if(refreshRequested &&
((now - lastupdate) > 1000)) {
if(frame.isVisible()) {
Point location = frame.getLocation();
frame.hide();
updateBackground();
frame.show();
frame.setLocation(location);
refresh();
}
lastupdate = now;
refreshRequested = false;
}
}
} catch (Exception ex) {
//p(ex.toString());
ex.printStackTrace();
}
}
}