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

📄 main.java

📁 java+eclipse做的TTPlayer
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        String lrcID = "LRC";        Action nextAction = new AbstractAction() {            public void actionPerformed(ActionEvent e) {                if (mp != null) {                    mp.processNext(e.getModifiers());                }            }        };        Action pauseAction = new AbstractAction() {            public void actionPerformed(ActionEvent e) {                if (mp != null) {                    mp.processPause(e.getModifiers());                }            }        };        Action playAction = new AbstractAction() {            public void actionPerformed(ActionEvent e) {                if (mp != null) {                    mp.processPlay(e.getModifiers());                }            }        };        Action stopAction = new AbstractAction() {            public void actionPerformed(ActionEvent e) {                if (mp != null) {                    mp.processStop(e.getModifiers());                }            }        };        Action lrcAction = new AbstractAction() {            public void actionPerformed(ActionEvent ae) {//                toggleLyricWindow(!lrcWin.isShowing());                mp.lrc.doClick();            }        };        Action eqAction = new AbstractAction() {            public void actionPerformed(ActionEvent ae) {//                toggleEqualizer(!eqWin.isShowing());                mp.eq.doClick();            }        };        Action plAction = new AbstractAction() {            public void actionPerformed(ActionEvent ae) {//                togglePlaylist(!plWin.isShowing());                mp.pl.doClick();            }        };        setKeyboardAction(nextID, nextStroke, nextAction);        setKeyboardAction(pauseID, pauseStroke, pauseAction);        setKeyboardAction(playID, playStroke, playAction);        setKeyboardAction(stopID, stopStroke, stopAction);        setKeyboardAction(lrcID, lrcStroke, lrcAction);        setKeyboardAction(eqID, eqStroke, eqAction);        setKeyboardAction(plID, plStroke, plAction);    }    public void setKeyboardAction(String id, KeyStroke key, Action action) {        mp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(key, id);        mp.getActionMap().put(id, action);        mp.getPlaylistUI().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(key, id);        mp.getPlaylistUI().getActionMap().put(id, action);        mp.getEqualizerUI().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(key, id);        mp.getEqualizerUI().getActionMap().put(id, action);        mp.getLyricUI().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(key, id);        mp.getLyricUI().getActionMap().put(id, action);    }    public void addSystemTray() {        if (SystemTray.isSupported()) {            try {                final PopupMenu pm = new PopupMenu(Config.NAME);                MenuItem about = new MenuItem(Config.getResource("menuitem.about"));                MenuItem showMain = new MenuItem(Config.getResource("menuitem.showMain"));                MenuItem set = new MenuItem(Config.getResource("menuitem.set"));                MenuItem exit = new MenuItem(Config.getResource("menuitem.exit"));                set.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent ae) {                        JDialog jd = config.getOptionDialog();                        jd.setVisible(true);                    }                });                exit.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent ae) {                        mp.closePlayer();                    }                });                showMain.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent ae) {                        Main.this.setVisible(true);                        Main.this.setExtendedState(JFrame.NORMAL);                        if (config.isShowEq()) {                            eqWin.setVisible(true);                        }                        if (config.isShowPlayList()) {                            plWin.setVisible(true);                        }                        if (config.isShowLrc()) {                            lrcWin.setVisible(true);                        }                    }                });                about.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent ae) {                        JOptionPane.showMessageDialog(null,                                new AboutPanel());                    }                });                pm.add(about);                pm.add(set);                pm.add(showMain);                pm.add(exit);                Image img = Util.getImage("player/icon.png");                final TrayIcon ti = new TrayIcon(img, Config.NAME, pm);                ti.setImageAutoSize(true);                ti.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent ae) {                        Main.this.setVisible(true);                        Main.this.setExtendedState(JFrame.NORMAL);                        if (config.isShowEq()) {                            eqWin.setVisible(true);                        }                        if (config.isShowPlayList()) {                            plWin.setVisible(true);                        }                        if (config.isShowLrc()) {                            lrcWin.setVisible(true);                        }                    }                });                SystemTray.getSystemTray().add(ti);            } catch (AWTException ex) {                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);            }        }    }    public void loaded() {    }    public void close() {        config.setLocation(getLocation().x, getLocation().y);        config.setLrcLocation(lrcWin.getLocation());        config.setEqLocation(eqWin.getLocation());        config.setPlLocation(plWin.getLocation());        config.setLrcSize(lrcWin.getSize());        config.setPlSize(plWin.getSize());        Config.save();        dispose();        System.exit(0);    }    public void minimize() {        if (config.isMiniHide()) {            setVisible(false);            eqWin.setVisible(false);            plWin.setVisible(false);            if (config.isShowLrc() && config.isLyricTopShow()) {                lrcWin.setVisible(true);            } else {                lrcWin.setVisible(false);            }        } else {            this.setState(JFrame.ICONIFIED);        }    }    public void togglePlaylist(boolean enabled) {        config.setShowPlayList(enabled);        if (plWin != null) {            showOrHide(plWin, enabled, config.isShadow());        }    }    public void toggleEqualizer(boolean enabled) {        config.setShowEq(enabled);        if (eqWin != null) {            showOrHide(eqWin, enabled, config.isShadow());        }    }    public void toggleLyricWindow(boolean enabled) {        config.setShowLrc(enabled);        if (lrcWin != null) {            if (enabled) {                mp.getLyricUI().start();            } else {                mp.getLyricUI().pause();            }            showOrHide(lrcWin, enabled, config.isShadow());        }    }    private void showOrHide(final Window win, final boolean enabled, final boolean isAlpha) {        new Thread() {            public void run() {                showOrHide0(win, enabled, isAlpha);            }        }.start();    }    /**     * 设置窗口出现或者隐起来     * 可以设置有特效或者无特效     * @param win 窗体     * @param enabled 是否可见     * @param isAlpha  是否要渐变     */    private void showOrHide0(Window win, boolean enabled, boolean isAlpha) {        if (enabled) {            win.setVisible(true);            if (!config.isLinux() && isAlpha && WindowUtils.isWindowAlphaSupported()) {//                WindowUtils.setWindowTransparent(win, true);                for (float f = 0.f; f <= 1.0f; f += 0.1f) {                    try {                        Thread.sleep(20);                        WindowUtils.setWindowAlpha(win, f);                    } catch (InterruptedException ex) {                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);                    }                }                WindowUtils.setWindowAlpha(win, 1.0f);            }        } else {            if (!config.isLinux() && isAlpha && WindowUtils.isWindowAlphaSupported()) {//                WindowUtils.setWindowTransparent(win, true);                for (float f = 1.0f; f >= 0; f -= 0.1f) {                    try {                        Thread.sleep(20);                        WindowUtils.setWindowAlpha(win, f);                    } catch (InterruptedException ex) {                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);                    }                }                WindowUtils.setWindowAlpha(win, 0.0f);            }            win.setVisible(false);        }    }    @Override    public synchronized void setLocation(int x, int y) {        Point now = new Point(x, y);        super.setLocation(now.x, now.y);        if (plWin != null && (config.isSnapPlWindow() || !plWin.isShowing())) {            Point dis = config.getDisPl();            if (dis != null) {                plWin.setLocation(now.x + dis.x, now.y + dis.y);            }        }        if (eqWin != null && (config.isSnapEqWindow()) || !eqWin.isShowing()) {            Point dis = config.getDisEq();            if (dis != null) {                eqWin.setLocation(now.x + dis.x, now.y + dis.y);            }        }        if (lrcWin != null && (config.isSnapLrcWindow()) || !lrcWin.isShowing()) {            Point dis = config.getDisLrc();            if (dis != null) {                lrcWin.setLocation(now.x + dis.x, now.y + dis.y);            }        }    }    public void reRange() {        this.setLocation(300, 100);        eqWin.setSize(285, 155);        plWin.setSize(285, 155);        lrcWin.setSize(285, 465);        eqWin.setLocation(300, 255);        plWin.setLocation(300, 410);        lrcWin.setLocation(585, 100);        config.updateDistance();    }    public JDialog changeLrcDialog() {        Point p = lrcWin.getLocation();        Dimension size = lrcWin.getSize();        mp.getLyricUI().pause();        lrcWin.removeAll();        lrcWin.dispose();        lrcWin = new JDialog(this);        lrcWin.setContentPane(mp.getLyricUI());        lrcWin.setMinimumSize(mp.getLyricUI().getMinimumSize());        lrcWin.setUndecorated(true);        config.setLrcWindow(lrcWin);        lrcWin.setSize(size);        lrcWin.setLocation(p);        lrcWin.setAlwaysOnTop(config.isLyricTopShow());        mp.getLyricUI().setParent(lrcWin);        if (config.isShowLrc()) {            lrcWin.setVisible(true);        }        return lrcWin;    }}

⌨️ 快捷键说明

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