小工具

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<String[]> 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);
}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章