⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 animatedcursor.java

📁 《SWING HACKS》源码 作者: Joshua Marinacci,Chris Adamson 著 徐晔 译 出版: 2007年2月
💻 JAVA
字号:
import java.awt.*;import java.awt.event.*;import javax.swing.*;public class AnimatedCursor implements Runnable, ActionListener {    private boolean animate;    private Cursor[] cursors;    private JFrame frame;    public AnimatedCursor(JFrame frame) {        animate = false;                cursors = new Cursor[8];        this.frame = frame;        cursors[0] = Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR);        cursors[1] = Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);        cursors[2] = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);        cursors[3] = Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);        cursors[4] = Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);        cursors[5] = Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);        cursors[6] = Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR);        cursors[7] = Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);    }    public void run() {        int count = 0;        while(animate) {            try {                Thread.currentThread().sleep(200);            } catch (Exception ex) {            }                        frame.setCursor(cursors[count % cursors.length]);            count++;        }        frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));    }    public void actionPerformed(ActionEvent evt) {        JButton button = (JButton)evt.getSource();        if(animate) {            button.setText("Start Animation");            animate = false;        } else {            animate = true;            button.setText("Stop Animation");            new Thread(this).start();        }    }    public static void main(String[] args) {        JFrame frame = new JFrame("Animated Cursor Hack");        JButton button = new JButton("Start Animation");        button.addActionListener(new AnimatedCursor(frame));        frame.getContentPane().add(button);        frame.pack();        frame.show();    }        public static void p(String str) {        System.out.println(str);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -