📄 fileset.java
字号:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
public class FileSet extends JPanel implements ActionListener{
private static final long serialVersionUID = -2910248303777262867L;
protected static int COPYLEN=10620000;//切块内的基本拷贝速度10620000
private JLabel copyLenLabel=new JLabel("切割及合并速度(1~60620000字节):");
private JLabel helpLabel=new JLabel("");//提示信息
private static JTextField copyLenField=new JTextField(10);
private static JButton setOK=new JButton("保存设置");
private static JButton setCancel=new JButton("默认设置");
private static JCheckBox delMsg=new JCheckBox("删除文件列表时总是提示我");
private JCheckBox windowStyle=new JCheckBox("使用传统风格标题栏");
private JPanel valuePanel=new JPanel();
private JTextArea helpMessage=new JTextArea(5,40);
private JPanel helpPanel=new JPanel();
protected File softSet=new File("SoftSet.cut");//用于保存速度的文件
protected SetValue mySet=new SetValue();//软件设置值类
private JFrame f=new JFrame();//设置窗口的指针
public FileSet(JFrame f){
this.f=f;
helpLabel.setForeground(Color.blue);
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
valuePanel.setLayout(gridbag);
c.fill=GridBagConstraints.BOTH;
c.weightx=1.0;
gridbag.setConstraints(copyLenLabel, c);
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(copyLenField, c);
//下一行
c.gridwidth = GridBagConstraints.RELATIVE;
c.weightx=1.0;
gridbag.setConstraints(delMsg, c);
c.gridwidth = GridBagConstraints.REMAINDER;
c.weightx=5.0;
gridbag.setConstraints(windowStyle, c);
//下一行
c.weightx=0.0;
gridbag.setConstraints(helpLabel, c);
c.gridwidth = GridBagConstraints.RELATIVE;
c.weightx=1.0;
gridbag.setConstraints(setOK, c);
//同一行第二个
c.gridwidth = GridBagConstraints.REMAINDER;
c.weightx=5.0;
gridbag.setConstraints(setCancel, c);
valuePanel.add(copyLenLabel);
valuePanel.add(copyLenField);
valuePanel.add(delMsg);
valuePanel.add(windowStyle);
valuePanel.add(helpLabel);
valuePanel.add(setOK);
valuePanel.add(setCancel);
valuePanel.setBorder(BorderFactory.createTitledBorder("设置"));
delMsg.setSelected(true);//默认删除总是提示
f.setUndecorated(true);//默认是显示为FRAME风格的窗口的
f.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
if (softSet.exists()){//如果软件设置文件存在
try{
mySet.readFromFile(new FileInputStream(softSet));
}catch(FileNotFoundException e){}
catch(ClassNotFoundException e){}
catch(IOException e){}
finally{
COPYLEN=mySet.getCopyLen();
delMsg.setSelected(mySet.getDelTishi());
windowStyle.setSelected(mySet.getuseWindows());
if(windowStyle.isSelected()==true){
f.setUndecorated(false);
f.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
}
}
}
//没有更改过速度就采用默认的
copyLenField.setText(COPYLEN+"");;//否则采用默认值,我已经在类变量中初始化默认值了
windowStyle.addActionListener(this);
copyLenField.addActionListener(this);
setOK.addActionListener(this);
setCancel.addActionListener(this);
helpMessage.setEditable(false);
helpMessage.setLineWrap(true);
helpMessage.setText("--------------------------------------------------------------------------------------------------------------\n"+
" 欢迎使用天焰超速文件切割机1.3版\n"+
" 作者:zygege QQ:408301995 email:zygege@126.com\n"+
" 本软件所有权zygege所有 Copy Right @2007.9\n" +
" 仅供学习,禁止用于商业用途,否则后果自负!\n"+
"--------------------------------------------------------------------------------------------------------------"+
"版本更新说明:\n"+
"1.1版:提供基本的单个文件切割及合并功能.\n"+
"1.2版:增加了切割(合并)速度设置,并增添了简短帮助.\n"+
"1.2.1版:修正了1.2版切割(合并)速度设置的大小BUG.\n"+
"1.3版:功能得到了大大增强,可以多文件切割,多文件合并,切割的块数也增加到了9999块,比前面任何一个版本提高了10倍,每个文件可以自由设置切块的个数,合并文件时选择文件方便性大大增强,具体请参看帮助.\n"+
"1.4版(未开发):有想法增加MP3合并功能,MTV合并功能,音乐文件转换功能,...敬请期待.");
helpMessage.setBackground(this.getBackground());
helpMessage.setCursor(new Cursor(Cursor.TEXT_CURSOR));
helpPanel.add(helpMessage);
helpPanel.setBorder(BorderFactory.createTitledBorder("软件说明"));
this.setLayout(new BorderLayout());
this.add(valuePanel,"North");
this.add(helpPanel,"Center");
this.setSize(700,500);
}
public static void setSpeedEditable(boolean t){//切割或合并过程中需要禁止改变切合速度
copyLenField.setEditable(t);
setOK.setEnabled(t);
setCancel.setEnabled(t);
}
public static boolean getDel(){
return delMsg.isSelected();
}
public void actionPerformed(ActionEvent e) {
try {
if (e.getSource() == setOK || e.getSource() == copyLenField) {
if (copyLenField.getText() != null) {
try{
if(Integer.parseInt(copyLenField.getText())>=1 && Integer.parseInt(copyLenField.getText())<=60620000)
COPYLEN = Integer.parseInt(copyLenField.getText());
else
copyLenField.setText(COPYLEN+"");
}catch (NumberFormatException ex){
copyLenField.setText(COPYLEN+"");
}
boolean a = delMsg.isSelected();
boolean b = windowStyle.isSelected();
FileOutputStream outStream = new FileOutputStream(softSet);
mySet.give(COPYLEN, a, b, outStream);
}
helpLabel.setText("已保存设置!");
} else if (e.getSource() == setCancel) {
COPYLEN=10620000;
copyLenField.setText(COPYLEN+"");
delMsg.setSelected(true);
if(windowStyle.isSelected()){//如果风格选项不处于默认状态false
f.dispose();
f.setUndecorated(true);
f.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
f.setVisible(true);
windowStyle.setSelected(false);
}
mySet.give(10620000, true, false,
(new FileOutputStream(softSet)));
helpLabel.setText("已保存设置!");
}else if (e.getSource()==windowStyle){//窗口标题栏实时改变
if(windowStyle.isSelected()==true){
f.dispose();
f.setUndecorated(false);
f.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
f.setVisible(true);
}else{
f.dispose();
f.setUndecorated(true);
f.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
f.setVisible(true);
}
helpLabel.setText("标题栏风格已改变!请保存!");
}
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
}
}
/*public void getSpeed(){//读文件,以前版本的老方法
try{
if (speedFile.canRead()){
BufferedReader readSpeed=new BufferedReader(new FileReader(speedFile));
String line=readSpeed.readLine();
String s="";
while(line!=null){
s=s+line;
line=readSpeed.readLine();
}
readSpeed.close();
COPYLEN=Integer.parseInt(s);
}
else{
JOptionPane.showMessageDialog(this, "抱歉,速度文件正在被另一进程占用!所以速度值未被读入软件,采用默认速度!");
COPYLEN=10620000;
}
}catch(IOException e){}
}
public void setSpeed(int speed){//写文件,以前版本的老方法
try{
if (speed>=1 && speed<=60620000){
COPYLEN=speed;
if (speedFile.canWrite() || !speedFile.exists()){
FileWriter writeSpeed=new FileWriter(speedFile);
writeSpeed.write(speed+"");
writeSpeed.close();
}
else
JOptionPane.showMessageDialog(this, "抱歉,速度文件正在被另一进程占用!所以速度值未被写入文件,下次启动采用默认速度!");
}
}catch (IOException e){ }
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -