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

📄 mainwindow.java

📁 桌面管理 可以将桌面的快捷方式集中管理
💻 JAVA
字号:
package com.deskManager.view;

import com.deskManager.contr.Time;
import com.deskManager.File.Config;
import com.deskManager.File.Data;
import com.deskManager.window.contr.*;
import com.jpackages.jflashplayer.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.ResourceBundle;
import java.util.logging.*;
import javax.swing.*;

/**
 * 主窗口类
 * @author Administrator
 */
public class MainWindow extends JFrame implements ActionListener {

    private static final long serialVersionUID = 7624512447312990831L;
    private PopupMenu m_popupMenu = new PopupMenu();
    private MenuItem add = new MenuItem("添加");
    private JPanel timep = new JPanel();
    private PopupMenu popup = new PopupMenu();
    private MenuItem show = new MenuItem("显示");
    private MenuItem exit = new MenuItem("退出");
    private TrayIcon trayIcon;
    ResourceBundle bundle = ResourceBundle.getBundle("com/deskManager/resources/resources"); // NOI18N
    private Left left = new Left(this);
    public static JScrollPane sc;
    public static JLabel jTime = new JLabel();

    public MainWindow(Config config) {
        this.setTitle(bundle.getString("Application.title"));
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        sc = new JScrollPane();
        m_popupMenu.add(add);
        this.add(m_popupMenu);
        add.addActionListener(this);
        this.setResizable(false);
        this.setIconImage(new ImageIcon(getClass().getResource("/com/deskManager/resources/icon.JPG")).getImage());
        this.setSize(625, 450);
        this.setLocation((screenSize.width - this.getWidth()) / 2, (screenSize.height - this.getHeight()) / 2);
        this.setLayout(new BorderLayout());
        // this.add(top, BorderLayout.NORTH);
        try {
            sc.setViewportView(new Index());
        } catch (JFlashLibraryLoadFailedException ex) {
            System.out.print(ex.toString());
        // Logger.getLogger(thisWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (JFlashInvalidFlashException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(this, "找不到index.swf", "系统信息", JOptionPane.WARNING_MESSAGE);
        }
        timep.add(jTime);
        this.add(timep, BorderLayout.NORTH);
        this.add(sc, BorderLayout.CENTER);
        this.add(left, BorderLayout.WEST);
        //  this.setUndecorated(true);
        this.addMouseListener(new MouseAdapter() {

            @Override
            public void mousePressed(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    m_popupMenu.show(e.getComponent(), e.getX(), e.getY());
                }
            } // 方法mousePressed结束

            @Override
            public void mouseReleased(MouseEvent e) {
                mousePressed(e);
            } // 方法mouseReleased结束
        } // 父类型为类MouseAdapter的匿名内部类结束
                ); // 方法addMouseListener调用结束

        Time time = new Time(config);
        time.start();
        tray();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == add) {
            Data d = new Data();
            new MessageEdit(this, d).setVisible(true);
        }
        if (e.getSource() == show || e.getSource() == trayIcon) {
            if (!this.isActive()) {
                this.setVisible(true);
            }
        }
        if (e.getSource() == exit) {
            System.exit(0);
        }
    }

    /**
     * 将窗口隐藏
     */
    public void close() {
        this.setVisible(false);
    }

    public void tray() {
        try {
            SystemTray tray = SystemTray.getSystemTray();// 装载托盘图象
            // 为这个托盘加一个弹出菜单
            show.addActionListener(this);
            exit.addActionListener(this);
            popup.add(show);
            popup.add(exit);
            trayIcon = new TrayIcon(new ImageIcon(getClass().getResource("/com/deskManager/resources/icon.JPG")).getImage(), "桌面管理", popup);
            tray.add(trayIcon);
            trayIcon.addActionListener(this);
        } catch (AWTException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

class Left extends JPanel implements ActionListener {

    private static final long serialVersionUID = 1L;
    private JButton index,  pro,  config,  about,  exit;
    ResourceBundle bundle = ResourceBundle.getBundle("com/deskManager/resources/resources"); // NOI18N
    JFrame temp;

    public JButton getAbout() {
        if (about == null) {
            about = new JButton(bundle.getString("Left.about.text"));
            about.setSize(90, 40);
            about.addActionListener(this);
        }
        return about;
    }

    public void setAbout(JButton about) {
        this.about = about;
    }

    public JButton getConfig() {
        if (config == null) {
            config = new JButton(bundle.getString("Left.config.text"));
            config.setSize(90, 40);
            config.addActionListener(this);
        }
        return config;
    }

    public void setConfig(JButton config) {
        this.config = config;
    }

    public JButton getExit() {
        if (exit == null) {
            exit = new JButton(bundle.getString("Left.exit.text"));
            exit.setSize(90, 40);
            exit.addActionListener(this);
        }
        return exit;
    }

    public void setExit(JButton exit) {
        this.exit = exit;
    }

    public JButton getIndex() {
        if (index == null) {
            index = new JButton(bundle.getString("Left.index.text"));
            index.setSize(90, 40);
            index.addActionListener(this);
        }
        return index;
    }

    public void setIndex(JButton index) {
        this.index = index;
    }

    public JButton getPro() {
        if (pro == null) {
            pro = new JButton(bundle.getString("Left.pro.text"));
            pro.setSize(90, 40);
            pro.addActionListener(this);
        }
        return pro;
    }

    public void setPro(JButton pro) {
        this.pro = pro;
    }

    public Left(JFrame p) {
        temp = p;
        this.setLayout(new newLayout(20, 15));
        this.setSize(120, 450);
        this.add(this.getIndex());
        this.add(this.getPro());
        this.add(this.getConfig());
        this.add(this.getAbout());
        this.add(this.getExit());
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == index) {
            try {
                MainWindow.sc.setViewportView(new Index());
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(temp, "找不到index.swf", "系统信息", JOptionPane.WARNING_MESSAGE);
            }
        }
        if (e.getSource() == pro) {
            try {
                MainWindow.sc.setViewportView(new ProJTabbedPane(temp));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        if (e.getSource() == config) {
            try {
                new ConfigView(temp).setVisible(true);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
        if (e.getSource() == about) {
            new AboutView(temp).setVisible(true);
        }
        if (e.getSource() == exit) {
            System.exit(0);
        }
    }
    /**
     * @return the other
     */
    /**
     * @param other the other to set
     */
}

class Index extends FlashPanel {

    private static final long serialVersionUID = -4639451532291084580L;

    public Index() throws JFlashLibraryLoadFailedException, FileNotFoundException, JFlashInvalidFlashException {
        super(new File("index.swf"));
    }
}

⌨️ 快捷键说明

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