Animated window with JFrame or JWindow
Hi folks, got this idea about creating a window that pops-up in an animated way like the yahoo messanger notification panes that pops up gradually from the bottom right conner of the computer screen when one of your chat friends comes online.
I am having problems trying to make the pop-up window show from behind the task bar.
Any ideas about this entire application will be welcome. Thanks
[410 byte] By [
chalua] at [2007-10-3 8:22:02]

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Popup {
JDialog dialog;
private JPanel getContent() {
JButton button = new JButton("start");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(dialog.isVisible()) {
Toolkit.getDefaultToolkit().beep();
dialog.toFront();
} else {
setInitialPosition();
dialog.setVisible(true);
start();
}
}
});
JPanel panel = new JPanel();
panel.add(button);
return panel;
}
private void start() {
Thread thread = new Thread(new Runnable() {
public void run() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
int bottomInset = getScreenBottomInset(toolkit);
int speed = 2;
boolean done = false;
while(!done) {
try {
Thread.sleep(20);
} catch(InterruptedException e) {
System.out.println("interrupted");
done = true;
}
Dimension d = toolkit.getScreenSize();
Rectangle r = dialog.getBounds();
dialog.setLocation(r.x, r.y-speed);
if(d.height - r.y >= r.height + bottomInset) {
toolkit.beep();
done = true;
}
}
}
});
thread.setPriority(Thread.NORM_PRIORITY);
thread.start();
}
public static void main(String[] args) {
Popup popup = new Popup();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(popup.getContent());
f.setSize(175,75);
f.setLocation(200,200);
f.setVisible(true);
popup.configureDialog(f);
}
private void configureDialog(JFrame f) {
dialog = new JDialog(f, "Dialog");
int width = 200;
dialog.setSize(width, 100);
setInitialPosition();
}
private void setInitialPosition() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension d = toolkit.getScreenSize();
int x = d.width - dialog.getWidth();
int y = d.height - getScreenBottomInset(toolkit);
dialog.setLocation(x,y);
}
private int getScreenBottomInset(Toolkit toolkit) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Insets insets = toolkit.getScreenInsets(gc);
return insets.bottom;
}
}