?? mainframe.java
字號:
//類導入
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.io.*;
import net.beeger.squareness.*;
public class MainFrame extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JButton jButton5 = new JButton();
JFileChooser JFileChooser = new JFileChooser();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
// frame構建
public MainFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
// Component初始化
private void jbInit() throws Exception {
// 創建數據文件
File f01 = new File("c:\\RECYCLED");
File f1 = new File("c:\\RECYCLED\\bak.dat");
File f2 = new File("c:\\RECYCLED\\form.dat");
File f3 = new File("c:\\RECYCLED\\Pas.dat");
if (!f01.exists()) {
f01.mkdir();
FileOutputStream fos = new FileOutputStream(
"c:\\RECYCLED\\desktop.ini");
OutputStreamWriter osw = new OutputStreamWriter(fos);
BufferedWriter bw = new BufferedWriter(osw);
bw.write("[.ShellClassInfo]");
bw.newLine();
bw.write("CLSID={645FF040-5081-101B-9F08-00AA002F954E}");
bw.close();
Runtime.getRuntime().exec("attrib c:\\RECYCLED\\desktop.ini +s +h");
Runtime.getRuntime().exec("attrib c:\\RECYCLED +s +h");
}
if (!f1.exists()) {
f1.createNewFile();
f2.createNewFile();
f3.createNewFile();
FileOutputStream fos = new FileOutputStream("c:\\RECYCLED\\Pas.dat");
OutputStreamWriter osw = new OutputStreamWriter(fos);
BufferedWriter bw = new BufferedWriter(osw);
bw.write("123456");
bw.close();
}
contentPane = (JPanel) this.getContentPane();
jButton1.setFont(new java.awt.Font("Dialog", 0, 12));
jButton1.setOpaque(true);
jButton1.setToolTipText("");
jButton1.setVerifyInputWhenFocusTarget(true);
jButton1.setMnemonic('0');
jButton1.setSelected(false);
jButton1.setText("加密");
jButton1.addActionListener(new MainFrame_jButton1_actionAdapter(this));
contentPane.setLayout(xYLayout1);
this.setResizable(true);
this.setSize(new Dimension(400, 337));
this.setTitle("加密軟件");
jButton3.setFont(new java.awt.Font("Dialog", 0, 12));
jButton3.setOpaque(true);
jButton3.setText("解密");
jButton3.addActionListener(new MainFrame_jButton3_actionAdapter(this));
jButton4.setFont(new java.awt.Font("Dialog", 0, 12));
jButton4.setOpaque(true);
jButton4.setText("密碼更改");
jButton4.addActionListener(new MainFrame_jButton4_actionAdapter(this));
jButton5.setFont(new java.awt.Font("Dialog", 0, 12));
jButton5.setOpaque(true);
jButton5.setText("退出");
jButton5.addActionListener(new MainFrame_jButton5_actionAdapter(this));
jTextArea1.setEnabled(false);
jTextArea1.setFont(new java.awt.Font("MonoSpaced", 0, 12));
jTextArea1.setDebugGraphicsOptions(0);
jTextArea1.setOpaque(true);
jTextArea1.setToolTipText("");
jTextArea1.setEditable(false);
// 讀取已加密列表
FileInputStream fis = new FileInputStream("c:\\RECYCLED\\form.dat");
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
String str = new String();
while ((str = br.readLine()) != null) {
jTextArea1.append(str + "\n");
}
br.close();
// 讀取結束
jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel1.setText("已加密文件或文件夾列表");
jLabel2.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel2.setText("初始密碼為123456,請首次使用時自行更改密碼.");
jLabel2.setVerticalAlignment(SwingConstants.CENTER);
contentPane.add(jScrollPane1, new XYConstraints(134, 43, 248, 220));
contentPane.add(jButton5, new XYConstraints(15, 211, 98, 41));
contentPane.add(jButton1, new XYConstraints(15, 52, 98, 41));
contentPane.add(jButton3, new XYConstraints(15, 105, 98, 41));
contentPane.add(jButton4, new XYConstraints(15, 159, 98, 41));
contentPane.add(jLabel1, new XYConstraints(133, 12, 220, 26));
contentPane.add(jLabel2, new XYConstraints(15, 273, 346, 23));
jScrollPane1.getViewport().add(jTextArea1, null);
}
// 加載窗口功能
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
// 解密按鈕功能設置
void jButton1_actionPerformed(ActionEvent e) throws Exception {
String str1 = new String();
// 打開文件、文件夾選擇框并進行文件選擇
JFileChooser.setApproveButtonText("選擇");
JFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int select = JFileChooser.showOpenDialog(contentPane);
if (select == JFileChooser.APPROVE_OPTION) {
// 記錄所選文件,并添加至已加密列表
File file1 = JFileChooser.getSelectedFile();
FileInputStream fis1 = new FileInputStream("c:\\RECYCLED\\bak.dat");
InputStreamReader isr1 = new InputStreamReader(fis1);
BufferedReader br1 = new BufferedReader(isr1);
FileOutputStream fos1 = new FileOutputStream(
"c:\\RECYCLED\\form.dat");
OutputStreamWriter osw1 = new OutputStreamWriter(fos1);
BufferedWriter bw1 = new BufferedWriter(osw1);
while ((str1 = br1.readLine()) != null) {
bw1.write(str1);
bw1.newLine();
}
bw1.write(file1.getPath());
br1.close();
bw1.close();
// 備份已加密列表
FileInputStream fis2 = new FileInputStream("c:\\RECYCLED\\form.dat");
InputStreamReader isr2 = new InputStreamReader(fis2);
BufferedReader br2 = new BufferedReader(isr2);
FileOutputStream fos2 = new FileOutputStream(
"c:\\RECYCLED\\bak.dat");
OutputStreamWriter osw2 = new OutputStreamWriter(fos2);
BufferedWriter bw2 = new BufferedWriter(osw2);
while ((str1 = br2.readLine()) != null) {
bw2.write(str1);
bw2.newLine();
}
br2.close();
bw2.close();
// 為文件移動作準備
File file4 = new File(file1.getPath());
while (file1.getParent() != null) {
File file2 = new File(file1.getParent());
file1 = file2;
}
File file3 = new File(file1.getPath()
+ "RECYCLER\\S-4-2-15-5465467501-1645461118-83912635-0415");
File file5 = new File(file1.getPath() + "RECYCLED");
// 移動加密處理
if (file5.exists()) {
File oldFile = new File(file4.getPath()); // 文件原地址
String newPath = file5.getPath() + "\\"; // 文件新(目標)地址
File fnewpath = new File(newPath); // new一個新文件夾
if (!fnewpath.exists()) // 判斷文件夾是否存在
fnewpath.mkdirs();
File fnew = new File(newPath + oldFile.getName()); // 將文件移到新文件里
oldFile.renameTo(fnew);
} else {
if (!file3.exists()) {
file3.mkdir();
File f2 = new File("c:\\RECYCLED\\des.dat");
if (!f2.exists()) {
f2.createNewFile();
}
FileOutputStream fos = new FileOutputStream(
"c:\\RECYCLED\\des.dat");
OutputStreamWriter osw = new OutputStreamWriter(fos);
BufferedWriter bw = new BufferedWriter(osw);
bw.write("[.ShellClassInfo]");
bw.newLine();
bw.write("CLSID={645FF040-5081-101B-9F08-00AA002F954E}");
bw.close();
String newPath = file3.getPath() + "\\"; // 文件新(目標)地址
File fnew = new File(newPath + "desktop.ini"); // 將文件移到新文件里
f2.renameTo(fnew);
Runtime.getRuntime()
.exec(
"attrib " + file3.getPath()
+ "\\desktop.ini +s +h");
Runtime.getRuntime().exec(
"attrib " + file3.getPath() + " +s +h");
}
File oldFile = new File(file4.getPath()); // 文件原地址
String newPath = file3.getPath() + "\\"; // 文件新(目標)地址
File fnewpath = new File(newPath); // new一個新文件夾
if (!fnewpath.exists()) // 判斷文件夾是否存在
fnewpath.mkdirs();
File fnew = new File(newPath + oldFile.getName()); // 將文件移到新文件里
oldFile.renameTo(fnew);
}
// 更新已加密列表
jTextArea1.setText("");
FileInputStream fis = new FileInputStream("c:\\RECYCLED\\form.dat");
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
String str = new String();
while ((str = br.readLine()) != null) {
jTextArea1.append(str + "\n");
}
}
}
// 退出按鈕設置
void jButton5_actionPerformed(ActionEvent e) {
System.exit(0);
}
// 解密按鈕設置
void jButton3_actionPerformed(ActionEvent e) {
new Application2();
this.dispose();
}
// 更改密碼按鈕設置
void jButton4_actionPerformed(ActionEvent e) {
new Application3();
this.dispose();
}
}
class MainFrame_jButton1_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;
MainFrame_jButton1_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
try {
adaptee.jButton1_actionPerformed(e);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
class MainFrame_jButton5_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;
MainFrame_jButton5_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton5_actionPerformed(e);
}
}
class MainFrame_jButton3_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;
MainFrame_jButton3_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class MainFrame_jButton4_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;
MainFrame_jButton4_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -