菜刀不行..更换大刀!(JavaSwing 旋转式关闭窗口);

这个可是我的爱....无私的奉贤给你们这些看文章不回帖的家伙们!!!!!

效果图:




源码

 

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JWindow;

public class Dissolver extends JComponent implements Runnable {
 JFrame frame;
 JWindow fullscreen;
 
int count;
 BufferedImage frame_buffer;
 BufferedImage screen_buffer;

 
public Dissolver() { }

 
public void run() {
  
try {
   count 
= 0;
   Thread.currentThread().sleep(
100);
   
for(int i=0; i<10; i++{
    count 
= i;
    fullscreen.repaint();
    Thread.currentThread().sleep(
100);
   }

  }
 catch (InterruptedException ex) {}
  System.exit(
1);
 }

 
public void dissolveExit(JFrame frame) {
  
try {
   
this.frame = frame;
   Robot robot 
= new Robot();
   
   Rectangle frame_rect 
= frame.getBounds();
   frame_buffer 
= robot.createScreenCapture(frame_rect);

   frame.setVisible(
false);

   Dimension screensize 
= Toolkit.getDefaultToolkit()
         .getScreenSize(); 
   Rectangle screen_rect 
= new Rectangle(0,0
    screensize.width, screensize.height); 
   screen_buffer 
= robot.createScreenCapture(screen_rect);

   fullscreen 
= new JWindow(new JFrame());
   fullscreen.setSize(screensize);
   fullscreen.add(
this);
   
this.setSize(screensize);
   fullscreen.setVisible(
true);

   fullscreen.repaint();
   
   
new Thread(this).start();
   }
 catch (Exception ex) {
    System.out.println(ex);
    ex.printStackTrace();
   }

  }


}

class SpinDissolver extends Dissolver {

 
public void paint(Graphics g) {
  Graphics2D g2 
= (Graphics2D)g;

  g.drawImage(screen_buffer,
-fullscreen.getX(),
   fullscreen.getY(),
null);
  
  AffineTransform old_trans 
= g2.getTransform();

  
// 移动到框架的上面-左手边角落
  g2.translate(frame.getX(), frame.getY());

  
// 向左边将框架移出
  g2.translate(0,
       
+(count+1* (frame.getX()+frame.getWidth())/20);

  
// 收缩 frame
  float scale = 1f / ((float)count+1);
  g2.scale(scale,scale);

  
// 中心的周围
  g2.rotate(((float)count)/3.14/1.3,
   frame.getWidth()
/2, frame.getHeight()/2);
  g2.drawImage(frame_buffer,
0,0,null);
  g2.setTransform(old_trans); 
 }
 
}


 

 下来没用一个类来实现他...

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JFrame;


public class DissolveHack {
    
        
public static void main(String[] args) {

            
final JFrame frame = new JFrame("Dissolve Hack");
            frame.setLayout(
new BorderLayout());
            
final JButton quit = new JButton("Quit");
            quit.addActionListener(
new ActionListener( ) {
                
public void actionPerformed(ActionEvent evt) {
                    quit.setVisible(
false);
                
                }

            }
);

            frame.getContentPane().add(quit,BorderLayout.NORTH);
            frame.getContentPane().add(
new JButton("我转~"),BorderLayout.CENTER);
            frame.getContentPane().add(
new JButton("我转~"),BorderLayout.SOUTH);
            frame.getContentPane().add(
new JButton("我转~"),BorderLayout.EAST);
            frame.getContentPane().add(
new JButton("我转~"),BorderLayout.WEST);
            frame.addWindowListener(
new WindowListener(){

                
public void windowActivated(WindowEvent arg0) {
                }

                
public void windowClosed(WindowEvent arg0) {                
                }

                
public void windowClosing(WindowEvent arg0) {
                    
new SpinDissolver().dissolveExit(frame);
                }

                
public void windowDeactivated(WindowEvent arg0) {
                }

                
public void windowDeiconified(WindowEvent arg0) {
                }

                
public void windowIconified(WindowEvent arg0) {
                }

                
public void windowOpened(WindowEvent arg0) {
                }

            }
);
            frame.pack( );
            frame.setLocation(
300,300);
            frame.setSize(
400,400);
            frame.setVisible(
true);
        }
 
    }


posted on 2008-05-23 15:37 相信 阅读(973) 评论(1)  编辑  收藏 所属分类: Swing文章

评论

# re: 菜刀不行..更换大刀!(JavaSwing 旋转式关闭窗口);[未登录] 2009-08-22 08:18 一粒沙

一点都不明白在说什么。  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

公告

不显示applet

常用链接

留言簿(16)

我参与的团队

随笔档案

文章分类

文章档案

新闻档案

相册

swingchina 专业搞Swing的网站

搜索

最新评论

阅读排行榜

评论排行榜