package tool;

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

public class Windows extends JFrame {

String configFile="C:\\TOOL_OU\\config\\config.txt";
JFrame jf = new JFrame();
JPanel panel = new JPanel();
ArrayList list = new ReadFile().readFile(configFile);

// 创建窗口
@SuppressWarnings("restriction")
public void CreatFrame() {
    panel.setBackground(null);
    panel.setOpaque(false);
    // 一般情况下,他不能被直接放在顶层容器中
    Container con = jf.getContentPane();
    JLabel jb = new JLabel("");
    // button 坐标
    int x = 1;
    int y = 1;
    int w = 200;
    int h = 28;

    for (int i = 0; i < list.size(); i++) {
        JButton jt = new JButton(list.get(i)[0]);
        // button 背景颜色
        jt.setBackground(new Color(237,237,237));
        final String aa = list.get(i)[1];
        jt.setBounds(x, y, w, h);
        if("insert".equals(aa)){
            // 添加鼠标点击事件
            jt.setHorizontalAlignment(SwingConstants.CENTER);
            jt.addMouseListener(new MouseAdapter() { 
                 public void mouseClicked(MouseEvent event) {
                      new UpLoad().eventOnImport(new JButton());
                 }
                }); // 文件上传功能
        } else{
            // フォルダーを開く
            jt.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        java.awt.Desktop.getDesktop().open(new File(aa));
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
        x = x + w + 1;
        if ((i + 1) % 3 == 0) {
            x = 1;
            y = y + h + 1;
        }
        con.add(jt);
    }
    jb.setHorizontalAlignment(MAXIMIZED_HORIZ);
    con.add(jb);
    // 窗口背景颜色
    //con.setBackground(new Color(0, 0, 0, 0));
    jf.setUndecorated(true);
    //jf.setBackground(new Color(0, 0, 0, 0));
    // 去掉标题栏
    jf.setUndecorated(true);
    // X Y坐标
    jf.setLocation(500, 800);
    // W H宽高
    jf.setSize(604, 160);
    jf.setVisible(true); 
    com.sun.awt.AWTUtilities.setWindowOpacity(jf, 0.8f);
    jf.setDefaultCloseOperation(EXIT_ON_CLOSE);
}

}