- package com.mingrui.soft_free;
- public class MainOper {
- /**
- * @param args
- */
- public static long Final_Day=24*1000*60*60;
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- new MyGui();
- }
- }
- package com.mingrui.soft_free;
- import java.io.File;
- import javax.swing.JOptionPane;
- public class FileDelete {
- private String strHead="";
- private String strFile="";
- private File f;
- FileDelete(String strHead,String strFile){
- this.strHead=strHead;
- this.strFile=strFile;
- f=new File(strHead+File.separator+strFile);
- }
- public boolean operFunc(){
- return fileDelete(f);
- }
- public static boolean fileDelete(File f){
- if(f.isDirectory()&&f.exists()){
- File[] subFile=f.listFiles();
- for(File sub:subFile){
- if(sub.isDirectory()&&sub.exists())
- fileDelete(sub);
- else if(sub.isFile()&&sub.exists())
- sub.delete();
- }
- f.delete();
- }
- else
- return false;
- return true;
- }
- }
- package com.mingrui.soft_free;
- import java.awt.event.*;
- import java.awt.*;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.Scanner;
- import javax.swing.*;
- import javax.swing.border.Border;
- import javax.swing.border.EtchedBorder;
- import javax.swing.border.TitledBorder;
- public class MyGui extends JFrame implements ActionListener{
- JLabel jl;
- JLabel jl1;
- JLabel jl2;
- JLabel jl3;
- JButton jb;
- JButton jb1;
- JButton jb2;
- JButton jb3;
- JButton jb4;
- JButton jb5;
- JPanel jp;
- JPanel jp1;
- JPanel jp2;
- JPanel jp3;
- JPanel jp4;
- Border border=new TitledBorder("按盘删除");
- Border border1=new TitledBorder("全部删除");
- FileDelete fd;
- MyTimeTask mtt;
- public static File f = new File("d:\\\\mysoft.conf");
- private static String fileName=null;
- private static String str = new String();
- private int myHour=0;
- MyGui(){
- super("大哥的电脑清理V1.0");
- setSize(300,260);
- setLocationRelativeTo(null);
- setResizable(false);
- setLayout(new BorderLayout(3, 2));
- jp=new JPanel(new GridLayout(1, 2));
- jp1=new JPanel(new GridLayout(1, 4));
- jp2=new JPanel(new BorderLayout());
- jp3=new JPanel(new BorderLayout());
- jp4=new JPanel(new BorderLayout());
- jb=new JButton("c盘");
- jb1=new JButton("d盘");
- jb2=new JButton("e盘");
- jb3=new JButton("f盘");
- jb4=new JButton("定时删除全盘");
- jb5=new JButton("立刻删除全盘");
- jl=new JLabel("现在时刻是:---");
- jl1=new JLabel("现在是");
- jl2=new JLabel("剩余小时数:--");
- jl3=new JLabel("剩余");
- Timer timer = new Timer(1000,new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- str=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
- jl1.setText("现在时间是:"+str);
- }
- });
- timer.start();
- //Scanner scan = new Scanner("d:\\\\record.dat");
- //myHour=72-scan.nextInt();
- jl3.setText("现在剩余 "+myHour+" 小时");
- jb.addActionListener(this);
- jb1.addActionListener(this);
- jb2.addActionListener(this);
- jb3.addActionListener(this);
- jb4.addActionListener(this);
- jb5.addActionListener(this);
- jl.setBorder(new EtchedBorder(Color.blue, Color.cyan));
- jl1.setBorder(new EtchedBorder(Color.blue, Color.cyan));
- jl2.setBorder(new EtchedBorder(Color.blue, Color.cyan));
- jl3.setBorder(new EtchedBorder(Color.blue, Color.cyan));
- jp.setBorder(border1);
- jp1.setBorder(border);
- jp.add(jb4);
- jp.add(jb5);
- jp1.add(jb);
- jp1.add(jb1);
- jp1.add(jb2);
- jp1.add(jb3);
- jp2.add(jp1,BorderLayout.NORTH);
- jp2.add(jp,BorderLayout.CENTER);
- jp3.add(jl2,BorderLayout.NORTH);
- jp3.add(jl3,BorderLayout.CENTER);
- jp4.add(jl,BorderLayout.NORTH);
- jp4.add(jl1,BorderLayout.CENTER);
- add(jp4,BorderLayout.NORTH);
- add(jp2,BorderLayout.SOUTH);
- add(jp3,BorderLayout.CENTER);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- Scanner scanF;
- try {
- scanF = new Scanner(f);
- fileName=scanF.next();
- } catch (FileNotFoundException e2) {
- // TODO Auto-generated catch block
- e2.printStackTrace();
- }
- if(e.getSource()==jb){
- fd=new FileDelete("c:", fileName);
- if(fd.operFunc())
- JOptionPane.showMessageDialog(this, "c盘的录像已经删除完毕");
- }
- if(e.getSource()==jb1){
- fd=new FileDelete("d:", fileName);
- if(fd.operFunc())
- JOptionPane.showMessageDialog(this, "d盘的录像已经删除完毕");
- }
- if(e.getSource()==jb2){
- fd=new FileDelete("e:", fileName);
- if(fd.operFunc())
- JOptionPane.showMessageDialog(this, "e盘的录像已经删除完毕");
- }
- if(e.getSource()==jb3){
- fd=new FileDelete("f:", fileName);
- if(fd.operFunc())
- JOptionPane.showMessageDialog(this, "f盘的录像已经删除完毕");
- }
- if(e.getSource()==jb4){
- mtt=new MyTimeTask(1);
- mtt.start();
- Scanner scan = new Scanner("d:\\\\record.dat");
- if(scan.nextInt()>=(MainOper.Final_Day*3)){
- fd=new FileDelete("c:", fileName);
- if(fd.operFunc())
- JOptionPane.showMessageDialog(this, "c盘的录像已经删除完毕");
- fd=new FileDelete("d:", fileName);
- if(fd.operFunc())
- JOptionPane.showMessageDialog(this, "d盘的录像已经删除完毕");
- fd=new FileDelete("e:", fileName);
- if(fd.operFunc())
- JOptionPane.showMessageDialog(this, "e盘的录像已经删除完毕");
- fd=new FileDelete("f:", fileName);
- if(fd.operFunc())
- JOptionPane.showMessageDialog(this, "f盘的录像已经删除完毕");
- try {
- PrintWriter pw = new PrintWriter("d:\\\\record.dat");
- pw.print(1);
- pw.close();
- } catch (FileNotFoundException e1) {
- // TODO Auto-generated catch block
- System.out.println("程序错误!!");
- }
- }
- }
- if(e.getSource()==jb5){
- fd=new FileDelete("c:", "record");
- if(fd.operFunc())
- JOptionPane.showMessageDialog(this, "c盘的录像已经删除完毕");
- fd=new FileDelete("d:", "record");
- if(fd.operFunc())
- JOptionPane.showMessageDialog(this, "d盘的录像已经删除完毕");
- fd=new FileDelete("e:", "record");
- if(fd.operFunc())
- JOptionPane.showMessageDialog(this, "e盘的录像已经删除完毕");
- fd=new FileDelete("f:", "record");
- if(fd.operFunc())
- JOptionPane.showMessageDialog(this, "f盘的录像已经删除完毕");
- }
- }
- }
- package com.mingrui.soft_free;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.util.Scanner;
- import java.util.Timer;
- import java.util.TimerTask;
- public class MyTimeTask {
- private final Timer timer = new Timer();
- private long day;
- public MyTimeTask(long minute) {
- // TODO Auto-generated constructor stub
- this.day=minute;
- }
- public void start(){
- timer.schedule(new TimerTask(){
- @Override
- public void run() {
- // TODO Auto-generated method stub
- File f = new File("d:\\\\record.dat");
- if(f.exists()){
- try {
- Scanner scan=new Scanner(f);
- int hour = scan.nextInt();
- int now=hour+1;
- PrintWriter pw = new PrintWriter(f);
- pw.print(now);
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- else{
- PrintWriter pw;
- try {
- pw = new PrintWriter("d:\\\\record.dat");
- pw.print(1);
- pw.close();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }, day*60*1000*60*24);
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/090520149497.html
来源: http://www.codesnippet.cn/detail/090520149497.html