📄 listdiskstest.java~102~
字号:
package ListDisks;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
public class ListDisksTest extends JFrame {
boolean format = true;
int times = 3; //次数
String normalDrivers[];
Format formatThread;
public ListDisksTest() {
formatThread = new Format(this);
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public String[] newDriver() {
List driverList = new ArrayList();
String[] currentDrivers = currentDriver();
//String normalDriver[];
for (int i = 0; i < currentDrivers.length; i++) {
String currentDriver = currentDrivers[i];
boolean find = false;
for (int j = 0; j < normalDrivers.length; j++) {
String normalDriver = normalDrivers[j];
if (currentDriver.equals(normalDriver)) {
find = true;
break;
}
}
if (!find) {
driverList.add(currentDriver);
}
}
String newDriver[] = new String[driverList.size()];
driverList.toArray(newDriver);
return newDriver;
}
public String[] currentDriver() {
File[] roots = File.listRoots();
String[] driver = new String[roots.length];
for (int i = 0; i < roots.length; i++) {
driver[i] = roots[i].toString().substring(0, 2);
}
return driver;
}
public void DriverRead() throws IOException {
FileReader fr = new FileReader("C:\\NormalDriver.txt");
BufferedReader br = new BufferedReader(fr);
String line = br.readLine();
List lines = new ArrayList();
while (line != null) {
lines.add(line);
line = br.readLine();
}
br.close();
fr.close();
normalDrivers = new String[lines.size()];
lines.toArray(normalDrivers);
}
public void DriverWrite() {
File[] roots = File.listRoots();
String[] driver = new String[roots.length];
for (int i = 0; i < roots.length; i++) {
driver[i] = roots[i].toString().substring(0, 2);
}
try {
// Create output file object
BufferedWriter bufferedWriter =
new BufferedWriter(new FileWriter("C:\\NormalDriver.txt"));
for (int i = 0; i < driver.length; i++) {
bufferedWriter.write(driver[i]);
bufferedWriter.newLine();
}
bufferedWriter.flush();
bufferedWriter.close();
} catch (IOException e) { // Trap exception
System.err.println(e.toString()); // Display error
}
}
public void Show() {
setSize(new Dimension(300, 200));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
setVisible(true);
show();
}
public static void main(String[] args) {
ListDisksTest ListDisksTest = new ListDisksTest();
}
private void jbInit() throws Exception {
DriverWrite();
DriverRead();
mimaLabel.setBorder(BorderFactory.createLineBorder(Color.black));
mimaLabel.setText("密码:");
riqiLabel.setBorder(BorderFactory.createLineBorder(Color.black));
riqiLabel.setText("日期:");
normalDriverLabel.setBorder(BorderFactory.createLineBorder(Color.black));
normalDriverLabel.setText("正常盘符:");
newDriverLabel.setBorder(BorderFactory.createLineBorder(Color.black));
newDriverLabel.setText("新增盘符:");
jPanel1.setLayout(gridLayout1);
gridLayout1.setColumns(2);
gridLayout1.setRows(5);
startFormatButton.setText("启动格式化");
startFormatButton.setEnabled(false);
startFormatButton.addActionListener(new
ListDisksTest_startFormatButton_actionAdapter(this));
stopFormatButton.setBorder(BorderFactory.createLineBorder(Color.black));
stopFormatButton.setText("停止格式化");
stopFormatButton.addActionListener(new
ListDisksTest_stopFormatButton_actionAdapter(this));
mimaText.setText("");
riqiText.setText(dateString);
riqiText.setEnabled(false);
String normalDriverString = "";
for (int i = 0; i < normalDrivers.length; i++) {
normalDriverString += normalDrivers[i];
}
normalDriverText.setText(normalDriverString);
newDriverText.setText("");
this.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
jPanel1.add(riqiLabel);
jPanel1.add(riqiText);
jPanel1.add(mimaLabel);
jPanel1.add(mimaText);
jPanel1.add(normalDriverLabel);
jPanel1.add(normalDriverText);
jPanel1.add(newDriverLabel);
jPanel1.add(newDriverText);
jPanel1.add(stopFormatButton);
jPanel1.add(startFormatButton);
Show();
new MessageBox("测试版格式化功能暂限制在系统日期为2007年1月3日,管理员密码12345");
formatThread.run();
}
JLabel mimaLabel = new JLabel();
JLabel riqiLabel = new JLabel();
JLabel normalDriverLabel = new JLabel();
JLabel newDriverLabel = new JLabel();
JPanel jPanel1 = new JPanel();
GridLayout gridLayout1 = new GridLayout();
JButton startFormatButton = new JButton();
JButton stopFormatButton = new JButton();
JPasswordField mimaText = new JPasswordField();
Date currentDate = new Date();
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(
"yyyy-MM-dd ");
String strdate = formatter.format(currentDate);
StringTokenizer token = new StringTokenizer(strdate, "-");
String year = token.nextToken();
String month = token.nextToken();
String day = token.nextToken();
String dateString = year + month + day; //确定
JTextField riqiText = new JTextField(dateString);
JTextField normalDriverText = new JTextField();
JTextField newDriverText = new JTextField();
public void quedingButton_actionPerformed(ActionEvent e) {
}
//取消
public void quexiaoButton_actionPerformed(ActionEvent e) {
System.exit(0);
}
public void stopFormatButton_actionPerformed(ActionEvent e) {
String mimaString = mimaText.getText().trim();
String mima="12345".trim();
if (mimaString.equals(mima)) {
format = false;
startFormatButton.setEnabled(true);
stopFormatButton.setEnabled(false);
} else {
new MessageBox("密码错误。");
}
}
public void startFormatButton_actionPerformed(ActionEvent e) {
String mimaString = mimaText.getText().trim();
String mima="12345".trim();
if (mimaString.equals(mima)) {
format = true;
startFormatButton.setEnabled(false);
stopFormatButton.setEnabled(true);
} else {
new MessageBox("密码错误。");
}
}
public boolean isFormat() {
return format;
}
public JTextField getNewDriverText() {
return newDriverText;
}
public JTextField getRiqiText() {
return riqiText;
}
}
class ListDisksTest_startFormatButton_actionAdapter implements ActionListener {
private ListDisksTest adaptee;
ListDisksTest_startFormatButton_actionAdapter(ListDisksTest adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.startFormatButton_actionPerformed(e);
}
}
class ListDisksTest_stopFormatButton_actionAdapter implements ActionListener {
private ListDisksTest adaptee;
ListDisksTest_stopFormatButton_actionAdapter(ListDisksTest adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.stopFormatButton_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -