解决方案 »
- 多线程怎么实时控制,比如说叫你运行立刻获得cup的使用,而不是进入就绪
- 怎样获得字符在JTextArea中的位置?怎样在JTextArea的指定位置输入字符?~~help~~
- JInternalFrame中,弹出JDialog窗口,窗口切换后JDialog窗口找不到了,必须要用alt+tab键才能显示,这是为什么
- !·#!·#!#··#·怎么回事呀!!
- 问题一个
- 一个有趣的问题?????期盼解答/
- 请教一个问题?
- 请问,堆和堆栈有什么区别与联系?哪些数据放在堆中?哪些数据放在堆栈中?
- 怎样把<select>中的所有数据求出来.例如:(一定给分)
- java中使用URL类,读取服务器上的文件返回的中文为什么是乱码?
- spring查询多个表中的字段
- java socket编程中怎么获得本机mac
package animation;import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;@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 setWindowClosingAnimated(boolean animated, JFrame jFrame) {
if (animated) {
jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowClosingAnimationToJFrame(jFrame);
} else {
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} private static void addWindowClosingAnimationToJFrame(JFrame jFrame) {
jFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
windowClosingAnimation(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();
}
});
}
}
package animation;import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;@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 setWindowClosingAnimated(boolean animated, JFrame jFrame) {
if (animated) {
jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowClosingAnimationToJFrame(jFrame);
} else {
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} private static void addWindowClosingAnimationToJFrame(JFrame jFrame) {
jFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
windowClosingAnimation(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();
}
});
}
}
package animation;import java.awt.AlphaComposite;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;@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 setWindowClosingAnimated(boolean animated, JFrame jFrame) {
if (animated) {
jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowClosingAnimationToJFrame(jFrame);
} else {
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} private static void addWindowClosingAnimationToJFrame(JFrame jFrame) {
jFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
windowClosingAnimation(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();
}
});
}
}