Swingでカーソルを砂時計にする2

public class LockGlassPane2 extends JComponent implements MouseInputListener {
    private Cursor oldCursor;
    private KeyEventDispatcher dispatcher;

    public LockGlassPane2() {
        super();
        this.addMouseListener(this);
        this.addMouseMotionListener(this);
        this.dispatcher = new KeyEventDispatcher() {
            public boolean dispatchKeyEvent(KeyEvent ke) {
                return true;
        }};
    }
    public void lock() {
        KeyboardFocusManager.getCurrentKeyboardFocusManager()
             .addKeyEventDispatcher(this.dispatcher);
        this.oldCursor = this.getCursor();
        this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        this.setVisible(true);
    }
    public void unLock() {
        this.setCursor(this.oldCursor);
        KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .removeKeyEventDispatcher(this.dispatcher);
        this.setVisible(false);
    }
    @Override
    protected void paintComponent(final Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(Color.white);
        g2.setComposite(
                AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
        g2.fillRect(0, 0, this.getWidth(), this.getHeight());
    }
    @Override
    public void mouseClicked(MouseEvent e) { e.consume(); }
    @Override
    public void mouseEntered(MouseEvent e) { e.consume(); }
    @Override
    public void mouseExited(MouseEvent e) { e.consume(); }
    @Override
    public void mousePressed(MouseEvent e) { e.consume(); }
    @Override
    public void mouseReleased(MouseEvent e) { e.consume(); }
    @Override
    public void mouseDragged(MouseEvent e) { e.consume(); }
    @Override
    public void mouseMoved(MouseEvent e) { e.consume(); }
}

実装

LockGlassPane2 blocker;
・・・
this.blocker = new LockGlassPane2();
view.setGlassPane(blocker);

//ロック(砂時計)
this.blocker.lock();;

//ロック解除(砂時計解除)
view.getBlocker().unLock();

スポンサーリンク
google 6948682462
google 6948682462

シェアする

  • このエントリーをはてなブックマークに追加

フォローする

スポンサーリンク
google 6948682462