@SuppressWarnings("serial")
public class WindowClosingAnimation extends JPanel {
/**
* Specifies the content pane.
*/
public WindowClosingAnimation() {
setLayout(new BorderLayout());
add(new JLabel("测试窗口关闭效果", SwingConstants.CENTER), BorderLayout.CENTER);
}
private static void createAndShowGUI() {
/* Specifies the L&F using its own JFrame decorations */
JFrame.setDefaultLookAndFeelDecorated(true);
try {
UIManager.setLookAndFeel("com.han.gen.GenLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
/* Creates a JFrame object and shows it */
JFrame jFrame = new JFrame();
jFrame.setContentPane(new WindowClosingAnimation());
jFrame.setSize(300, 200);
jFrame.setLocationRelativeTo(null);
jFrame.setVisible(true);
// Choose "true" or "false" to see the difference
setWindowClosingAnimated(true, jFrame);
}
private static void windowClosingAnimation(JFrame jFrame) {
/* Firstly stores the bounds of our JFrame object to be closed as final */
final Rectangle bounds = jFrame.getBounds();
/* Captured the entire JFrame image */
BufferedImage image = new BufferedImage(bounds.width, bounds.height,
BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
jFrame.paint(g);
g.dispose();
/*
* Creates a new JWindow object to show the captured image, and at the
* same time hides the JFrame object.
*/
JWindow jWindow = new JWindow() {
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
};
jWindow.setBounds(bounds);
jFrame.setVisible(false);
jWindow.setVisible(true);
/* Uses a Timer to perform the size variation of JWindow */
int delay = 15; // milliseconds
final int indent = 20;
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// ...Perform a task...
Rectangle bounds = jWindow.getBounds();
bounds.x += indent / 2;
bounds.y += indent / 2;
bounds.width -= indent;
bounds.height -= indent;
if (bounds.width < 0 || bounds.height < 0) {
System.exit(0);
} else {
jWindow.setBounds(bounds);// will call repaint()
}
}
};
new Timer(delay, taskPerformer).start();
}
public static void main(String[] args) {
// To make sure that the GUI creation happens on the EDT
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
}
@SuppressWarnings("serial")
public class WindowClosingAnimation extends JPanel {
static float alpha = 1.0f;
static double shx = 0.0;
/**
* Specifies the content pane.
*/
public WindowClosingAnimation() {
setLayout(new BorderLayout());
add(new JLabel("测试窗口关闭效果", SwingConstants.CENTER), BorderLayout.CENTER);
}
private static void createAndShowGUI() {
/* Specifies the L&F using its own JFrame decorations */
JFrame.setDefaultLookAndFeelDecorated(true);
try {
UIManager.setLookAndFeel("com.han.gen.GenLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
/* Creates a JFrame object and shows it */
JFrame jFrame = new JFrame();
jFrame.setContentPane(new WindowClosingAnimation());
jFrame.setSize(300, 200);
jFrame.setLocationRelativeTo(null);
jFrame.setVisible(true);
// Choose "true" or "false" to see the difference
setWindowClosingAnimated(true, jFrame);
}
private static void windowClosingAnimation(JFrame jFrame) {
/* Firstly stores the bounds of our JFrame object to be closed as final */
final Rectangle bounds = jFrame.getBounds();
/* Captured the entire JFrame image */
BufferedImage image = new BufferedImage(bounds.width, bounds.height,
BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
jFrame.paint(g);
g.dispose();
/*
* Creates a new JWindow object to show the captured image, and at the
* same time hides the JFrame object.
*/
JWindow jWindow = new JWindow() {
@Override
public void paint(Graphics g) {
super.paint(g);// important to call to have transparency
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, alpha));
g2.shear(shx, 0);
g2.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
};
jWindow.setBounds(bounds);
jFrame.setVisible(false);
jWindow.setVisible(true);
/* Uses a Timer to perform the size variation of JWindow */
int delay = 30; // milliseconds
final int indent = 20;
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// ...Perform a task...
alpha -= 0.1;
shx += 0.01;
Rectangle bounds = jWindow.getBounds();
bounds.x += indent / 2;
bounds.y += indent / 2;
bounds.width -= indent;
bounds.height -= indent;
if (shx > 0.1 || alpha < 0 || bounds.width < 0
|| bounds.height < 0) {
System.exit(0);
} else {
jWindow.setBounds(bounds);// will call repaint()
}
}
};
new Timer(delay, taskPerformer).start();
}
public static void main(String[] args) {
// To make sure that the GUI creation happens on the EDT
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
}
@SuppressWarnings("serial")
public class WindowClosingAnimation extends JPanel {
/**
* Specifies the content pane.
*/
public WindowClosingAnimation() {
setLayout(new BorderLayout());
add(new JLabel("测试窗口关闭效果", SwingConstants.CENTER), BorderLayout.CENTER);
}
private static void createAndShowGUI() {
/* Specifies the L&F using its own JFrame decorations */
JFrame.setDefaultLookAndFeelDecorated(true);
try {
UIManager.setLookAndFeel("com.han.gen.GenLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
/* Creates a JFrame object and shows it */
JFrame jFrame = new JFrame();
jFrame.setContentPane(new WindowClosingAnimation());
jFrame.setSize(300, 200);
jFrame.setLocationRelativeTo(null);
jFrame.setVisible(true);
// Choose "true" or "false" to see the difference
setWindowClosingAnimated(true, jFrame);
}
private static void windowClosingAnimation(JFrame jFrame) {
/* Firstly stores the bounds of our JFrame object to be closed as final */
final Rectangle bounds = jFrame.getBounds();
/* Captured the entire JFrame image */
BufferedImage image = new BufferedImage(bounds.width, bounds.height,
BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
jFrame.paint(g);
g.dispose();
/*
* Creates a new JWindow object to show the captured image, and at the
* same time hides the JFrame object.
*/
JWindow jWindow = new JWindow() {
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
};
jWindow.setBounds(bounds);
jFrame.setVisible(false);
jWindow.setVisible(true);
/* Uses a Timer to perform the size variation of JWindow */
int delay = 15; // milliseconds
final int indent = 20;
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// ...Perform a task...
Rectangle bounds = jWindow.getBounds();
bounds.x += indent / 2;
bounds.y += indent / 2;
bounds.width -= indent;
bounds.height -= indent;
if (bounds.width < 0 || bounds.height < 0) {
System.exit(0);
} else {
jWindow.setBounds(bounds);// will call repaint()
}
}
};
new Timer(delay, taskPerformer).start();
}
public static void main(String[] args) {
// To make sure that the GUI creation happens on the EDT
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
}
@SuppressWarnings("serial")
public class WindowClosingAnimation extends JPanel {
/**
* Specifies the content pane.
*/
public WindowClosingAnimation() {
setLayout(new BorderLayout());
add(new JLabel("测试窗口关闭效果", SwingConstants.CENTER), BorderLayout.CENTER);
}
private static void createAndShowGUI() {
/* Specifies the L&F using its own JFrame decorations */
JFrame.setDefaultLookAndFeelDecorated(true);
try {
UIManager.setLookAndFeel("com.han.gen.GenLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
/* Creates a JFrame object and shows it */
JFrame jFrame = new JFrame();
jFrame.setContentPane(new WindowClosingAnimation());
jFrame.setSize(300, 200);
jFrame.setLocationRelativeTo(null);
jFrame.setVisible(true);
// Choose "true" or "false" to see the difference
setWindowClosingAnimated(true, jFrame);
}
private static void windowClosingAnimation(JFrame jFrame) {
/* Firstly stores the bounds of our JFrame object to be closed as final */
final Rectangle bounds = jFrame.getBounds();
/* Captured the entire JFrame image */
BufferedImage image = new BufferedImage(bounds.width, bounds.height,
BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
jFrame.paint(g);
g.dispose();
/*
* Creates a new JWindow object to show the captured image, and at the
* same time hides the JFrame object.
*/
JWindow jWindow = new JWindow() {
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
};
jWindow.setBounds(bounds);
jFrame.setVisible(false);
jWindow.setVisible(true);
/* Uses a Timer to perform the size variation of JWindow */
int delay = 15; // milliseconds
final int indent = 20;
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// ...Perform a task...
Rectangle bounds = jWindow.getBounds();
bounds.x += indent / 2;
bounds.y += indent / 2;
bounds.width -= indent;
bounds.height -= indent;
if (bounds.width < 0 || bounds.height < 0) {
System.exit(0);
} else {
jWindow.setBounds(bounds);// will call repaint()
}
}
};
new Timer(delay, taskPerformer).start();
}
public static void main(String[] args) {
// To make sure that the GUI creation happens on the EDT
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
}
@SuppressWarnings("serial")
public class WindowClosingAnimation extends JPanel {
static float alpha = 1.0f;
static double shx = 0.0;
/**
* Specifies the content pane.
*/
public WindowClosingAnimation() {
setLayout(new BorderLayout());
add(new JLabel("测试窗口关闭效果", SwingConstants.CENTER), BorderLayout.CENTER);
}
private static void createAndShowGUI() {
/* Specifies the L&F using its own JFrame decorations */
JFrame.setDefaultLookAndFeelDecorated(true);
try {
UIManager.setLookAndFeel("com.han.gen.GenLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
/* Creates a JFrame object and shows it */
JFrame jFrame = new JFrame();
jFrame.setContentPane(new WindowClosingAnimation());
jFrame.setSize(300, 200);
jFrame.setLocationRelativeTo(null);
jFrame.setVisible(true);
// Choose "true" or "false" to see the difference
setWindowClosingAnimated(true, jFrame);
}
private static void windowClosingAnimation(JFrame jFrame) {
/* Firstly stores the bounds of our JFrame object to be closed as final */
final Rectangle bounds = jFrame.getBounds();
/* Captured the entire JFrame image */
BufferedImage image = new BufferedImage(bounds.width, bounds.height,
BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
jFrame.paint(g);
g.dispose();
/*
* Creates a new JWindow object to show the captured image, and at the
* same time hides the JFrame object.
*/
JWindow jWindow = new JWindow() {
@Override
public void paint(Graphics g) {
super.paint(g);// important to call to have transparency
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, alpha));
g2.shear(shx, 0);
g2.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
};
jWindow.setBounds(bounds);
jFrame.setVisible(false);
jWindow.setVisible(true);
/* Uses a Timer to perform the size variation of JWindow */
int delay = 30; // milliseconds
final int indent = 20;
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// ...Perform a task...
alpha -= 0.1;
shx += 0.01;
Rectangle bounds = jWindow.getBounds();
bounds.x += indent / 2;
bounds.y += indent / 2;
bounds.width -= indent;
bounds.height -= indent;
if (shx > 0.1 || alpha < 0 || bounds.width < 0
|| bounds.height < 0) {
System.exit(0);
} else {
jWindow.setBounds(bounds);// will call repaint()
}
}
};
new Timer(delay, taskPerformer).start();
}
public static void main(String[] args) {
// To make sure that the GUI creation happens on the EDT
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
}