package makedisk;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.plaf.TableHeaderUI;
import javax.swing.table.JTableHeader;
import javax.swing.table.DefaultTableModel;
import java.util.Vector;
import java.io.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class Frame1 extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JComboBox istrue = new JComboBox();
JLabel jLabel2 = new JLabel();
JTextField path = new JTextField();
JPanel jPanel1 = new JPanel();
TitledBorder titledBorder1 = new TitledBorder("");
JButton newfile = new JButton();
JButton delfile = new JButton();
JButton openfile = new JButton();
JButton setauto = new JButton();
JButton delauto = new JButton();
JButton dauto = new JButton();
JTextPane jTextPane1 = new JTextPane();
DefaultTableModel dtm=new DefaultTableModel();
Vector v1=new Vector(),v2=new Vector(),v3=new Vector();
Process pro=null;
JLabel jLabel3 = new JLabel();
JComboBox canset = new JComboBox();
JButton jButton1 = new JButton();
JFileChooser open = new JFileChooser();
File f;
File fx[],fy[];
public Frame1() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(450, 330));
setTitle("文件夹虚拟磁盘工具[BY PHOENIX]");
jLabel1.setFont(new java.awt.Font("細明體", Font.PLAIN, 15));
jLabel1.setForeground(new Color(118, 30, 190));
jLabel1.setText("存在磁盘:");
jLabel1.setBounds(new Rectangle(17, 32, 71, 28));
istrue.setBounds(new Rectangle(99, 37, 71, 20));
jLabel2.setFont(new java.awt.Font("新細明體", Font.PLAIN, 15));
jLabel2.setForeground(new Color(118, 30, 190));
jLabel2.setText("映射路径:");
jLabel2.setBounds(new Rectangle(17, 78, 75, 16));
path.setText("");
this.setResizable(false);
path.setBounds(new Rectangle(97, 76, 266, 21));
jPanel1.setBorder(BorderFactory.createLoweredBevelBorder());
jPanel1.setBounds(new Rectangle(3, 107, 428, 180));
newfile.setForeground(new Color(118, 30, 190));
newfile.setText("建立磁盘");
newfile.addActionListener(new Frame1_newfile_actionAdapter(this));
delfile.setForeground(new Color(118, 30, 190));
delfile.setText("删除磁盘");
delfile.addActionListener(new Frame1_delfile_actionAdapter(this));
openfile.setForeground(new Color(118, 30, 190));
openfile.setText("打开磁盘");
openfile.addActionListener(new Frame1_openfile_actionAdapter(this));
setauto.setForeground(new Color(118, 30, 190));
setauto.setText("建立磁盘并设为自启动");
setauto.addActionListener(new Frame1_setauto_actionAdapter(this));
delauto.setForeground(new Color(118, 30, 190));
delauto.setText("删除磁盘并取消自启动");
delauto.addActionListener(new Frame1_delauto_actionAdapter(this));
dauto.setForeground(new Color(118, 30, 190));
dauto.setText("取消自启动");
dauto.addActionListener(new Frame1_dauto_actionAdapter(this));
jTextPane1.setFont(new java.awt.Font("細明體", Font.PLAIN, 15));
jTextPane1.setText(
"说明:建立磁盘时请选择正确的文件夹路径;\n删除、打开和设置自启动磁盘时\n请从下拉菜单中选中该磁盘,\n并确定该盘为虚拟盘\n\t\t BY PHOENIX [Frozen Down]");
jLabel3.setFont(new java.awt.Font("細明體", Font.PLAIN, 15));
jLabel3.setForeground(new Color(118, 30, 190));
jLabel3.setText("可设置磁盘:");
jLabel3.setBounds(new Rectangle(190, 36, 98, 22));
canset.setBounds(new Rectangle(296, 35, 72, 20));
jButton1.setBounds(new Rectangle(359, 74, 71, 25));
jButton1.setForeground(new Color(118, 30, 190));
jButton1.setText("浏览");
jButton1.addActionListener(new Frame1_liulan_actionAdapter(this));
additem();
contentPane.add(jLabel1);
contentPane.add(jLabel2);
contentPane.add(path);
contentPane.add(jPanel1);
contentPane.add(jLabel3);
jPanel1.add(newfile);
jPanel1.add(delfile);
jPanel1.add(openfile);
jPanel1.add(setauto);
jPanel1.add(dauto);
jPanel1.add(delauto);
jPanel1.add(jTextPane1);
contentPane.add(jButton1);
jTextPane1.setEnabled(false);
jTextPane1.setForeground(new Color(118, 30, 190));
}
public void exec(String str){
try {
pro = Runtime.getRuntime().exec(str);
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void additem(){
istrue.removeAllItems();
canset.removeAllItems();
fx=File.listRoots();
for(int i=0;i<fx.length;i++){
istrue.addItem(fx[i].toString());
}
for(int i=65;i<91;i++){
boolean is=true;
char a=(char) i;
String x=a+":\\";
for(int j=0;j<fx.length;j++){
if(x.equals(fx[j].toString())){
is=false;
break;
}
}
if(is){
canset.addItem(x);
}
}
contentPane.add(canset); contentPane.add(istrue);
}
public void newfile_actionPerformed(ActionEvent e) {
String pan=canset.getSelectedItem()+"";
if(path.getText()!=null&&!path.getText().equals("")){
f = new File(path.getText());
if(!pan.equals("")){
String str="subst "+pan.substring(0,pan.length()-1)+" \""+path.getText()+"\"";
//System.out.println(str);
exec(str);
javax.swing.JOptionPane.showMessageDialog(null,"建立成功!!");
additem();
}else{
javax.swing.JOptionPane.showMessageDialog(null,"请选择盘符!!");
}
}else{
javax.swing.JOptionPane.showMessageDialog(null,"请选择或填写路径!!");
}
}
public void delfile_actionPerformed(ActionEvent e) {
String pan=istrue.getSelectedItem()+"";
if(!pan.equals("")){
String str="subst "+pan.substring(0,pan.length()-1)+" /d";
//System.out.println(str);
exec(str);
javax.swing.JOptionPane.showMessageDialog(null,"删除成功!!");
additem();
}else{
javax.swing.JOptionPane.showMessageDialog(null,"请选择盘符!!");
}
}
public void openfile_actionPerformed(ActionEvent e) {
String pan=istrue.getSelectedItem()+"";
if(!pan.equals("")){
f=new File(pan+"startthis.bat");
FileWriter fw = null;
try {
fw = new FileWriter(f);
BufferedWriter bw=new BufferedWriter(fw);
bw.write("@echo off");
bw.newLine();
bw.write("start "+pan);
bw.newLine();
bw.write("del %0");
bw.close();
fw.close();
String str=pan+"startthis.bat";
//System.out.println(s