java实现变更文件查询的方法
作者:罪恶的花生 发布时间:2022-07-29 04:55:37
标签:java,文件,查询
本文实例讲述了java实现变更文件查询的方法。分享给大家供大家参考。具体如下:
自己经常发布包时需要查找那些文件时上次发包后更新的数据文件,所以写了这个发布包,
拷贝输出的命令,dos窗口下执行,
为啥不直接复制文件,因为java拷贝文件会修改文件最后修改日期,所以采用dos下的拷贝。
/*
*
* 更改所生成文件模板为
* 窗口 > 首选项 > Java > 代码生成 > 代码和注释
*/
package com.cn.wangk.tools;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
/** *//**
* Bean to display a month calendar in a JPanel. Only works for the Western
* calendar.
*
* @author Ian F. Darwin, http://www.darwinsys.com/
* @version $Id: Cal.java,v 1.5 2004/02/09 03:33:45 ian Exp $
*/
public class Cal extends JPanel{
/** *//** The currently-interesting year (not modulo 1900!) */
protected int yy;
/** *//** Currently-interesting month and day */
protected int mm, dd;
/** *//** The buttons to be displayed */
protected JButton labs[][];
/** *//** The number of day squares to leave blank at the start of this month */
protected int leadGap = 0;
/** *//** A Calendar object used throughout */
Calendar calendar = new GregorianCalendar();
/** *//** Today's year */
protected final int thisYear = calendar.get(Calendar.YEAR);
/** *//** Today's month */
protected final int thisMonth = calendar.get(Calendar.MONTH);
/** *//** One of the buttons. We just keep its reference for getBackground(). */
private JButton b0;
/** *//** The month choice */
private JComboBox monthChoice;
/** *//** The year choice */
private JComboBox yearChoice;
/** *//**
* Construct a Cal, starting with today.
*/
Cal(){
super();
setYYMMDD(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH));
buildGUI();
recompute();
}
/** *//**
* Construct a Cal, given the leading days and the total days
*
* @exception IllegalArgumentException
* If year out of range
*/
Cal(int year, int month, int today){
super();
setYYMMDD(year, month, today);
buildGUI();
recompute();
}
private void setYYMMDD(int year, int month, int today){
yy = year;
mm = month;
dd = today;
}
String[] months ={ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };
/** *//** Build the GUI. Assumes that setYYMMDD has been called. */
private void buildGUI(){
getAccessibleContext().setAccessibleDescription(
"Calendar not accessible yet. Sorry!");
setBorder(BorderFactory.createEtchedBorder());
setLayout(new BorderLayout());
JPanel tp = new JPanel();
tp.add(monthChoice = new JComboBox());
for (int i = 0; i < months.length; i++)
monthChoice.addItem(months[i]);
monthChoice.setSelectedItem(months[mm]);
monthChoice.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
int i = monthChoice.getSelectedIndex();
if (i >= 0){
mm = i;
// System.out.println("Month=" + mm);
recompute();
}
}
});
monthChoice.getAccessibleContext().setAccessibleName("Months");
monthChoice.getAccessibleContext().setAccessibleDescription(
"Choose a month of the year");
tp.add(yearChoice = new JComboBox());
yearChoice.setEditable(true);
for (int i = yy - 5; i < yy + 5; i++)
yearChoice.addItem(Integer.toString(i));
yearChoice.setSelectedItem(Integer.toString(yy));
yearChoice.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
int i = yearChoice.getSelectedIndex();
if (i >= 0){
yy = Integer.parseInt(yearChoice.getSelectedItem()
.toString());
// System.out.println("Year=" + yy);
recompute();
}
}
});
add(BorderLayout.CENTER, tp);
JPanel bp = new JPanel();
bp.setLayout(new GridLayout(7, 7));
labs = new JButton[6][7]; // first row is days
bp.add(b0 = new JButton("S"));
bp.add(new JButton("M"));
bp.add(new JButton("T"));
bp.add(new JButton("W"));
bp.add(new JButton("R"));
bp.add(new JButton("F"));
bp.add(new JButton("S"));
ActionListener dateSetter = new ActionListener(){
public void actionPerformed(ActionEvent e){
String num = e.getActionCommand();
if (!num.equals("")){
// set the current day highlighted
setDayActive(Integer.parseInt(num));
// When this becomes a Bean, you can
// fire some kind of DateChanged event here.
// Also, build a similar daySetter for day-of-week btns.
}
}
};
// Construct all the buttons, and add them.
for (int i = 0; i < 6; i++)
for (int j = 0; j < 7; j++){
bp.add(labs[i][j] = new JButton(""));
labs[i][j].addActionListener(dateSetter);
}
add(BorderLayout.SOUTH, bp);
}
public final static int dom[] ={ 31, 28, 31, 30, /**//* jan feb mar apr */
31, 30, 31, 31, /**//* may jun jul aug */
30, 31, 30, 31 /**//* sep oct nov dec */
};
/** *//** Compute which days to put where, in the Cal panel */
protected void recompute(){
// System.out.println("Cal::recompute: " + yy + ":" + mm + ":" + dd);
if (mm < 0 || mm > 11)
throw new IllegalArgumentException("Month " + mm
+ " bad, must be 0-11");
clearDayActive();
calendar = new GregorianCalendar(yy, mm, dd);
// Compute how much to leave before the first.
// getDay() returns 0 for Sunday, which is just right.
leadGap = new GregorianCalendar(yy, mm, 1).get(Calendar.DAY_OF_WEEK) - 1;
// System.out.println("leadGap = " + leadGap);
int daysInMonth = dom[mm];
if (isLeap(calendar.get(Calendar.YEAR)) && mm > 1)
++daysInMonth;
// Blank out the labels before 1st day of month
for (int i = 0; i < leadGap; i++){
labs[0][i].setText("");
}
// Fill in numbers for the day of month.
for (int i = 1; i <= daysInMonth; i++){
JButton b = labs[(leadGap + i - 1) / 7][(leadGap + i - 1) % 7];
b.setText(Integer.toString(i));
}
// 7 days/week * up to 6 rows
for (int i = leadGap + 1 + daysInMonth; i < 6 * 7; i++){
labs[(i) / 7][(i) % 7].setText("");
}
// Shade current day, only if current month
if (thisYear == yy && mm == thisMonth)
setDayActive(dd); // shade the box for today
// Say we need to be drawn on the screen
repaint();
}
/** *//**
* isLeap() returns true if the given year is a Leap Year.
*
* "a year is a leap year if it is divisible by 4 but not by 100, except
* that years divisible by 400 *are* leap years." -- Kernighan & Ritchie,
* _The C Programming Language_, p 37.
*/
public boolean isLeap(int year){
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
return true;
return false;
}
/** *//** Set the year, month, and day */
public void setDate(int yy, int mm, int dd){
// System.out.println("Cal::setDate");
this.yy = yy;
this.mm = mm; // starts at 0, like Date
this.dd = dd;
recompute();
}
/** *//** Unset any previously highlighted day */
private void clearDayActive(){
JButton b;
// First un-shade the previously-selected square, if any
if (activeDay > 0){
b = labs[(leadGap + activeDay - 1) / 7][(leadGap + activeDay - 1) % 7];
b.setBackground(b0.getBackground());
b.repaint();
activeDay = -1;
}
}
private int activeDay = -1;
/** *//** Set just the day, on the current month */
public void setDayActive(int newDay){
clearDayActive();
// Set the new one
if (newDay <= 0)
dd = new GregorianCalendar().get(Calendar.DAY_OF_MONTH);
else
dd = newDay;
// Now shade the correct square
Component square = labs[(leadGap + newDay - 1) / 7][(leadGap + newDay - 1) % 7];
square.setBackground(Color.red);
square.repaint();
activeDay = newDay;
}
/** *//** For testing, a main program */
public static void main(String[] av){
JFrame f = new JFrame("Cal");
Container c = f.getContentPane();
c.setLayout(new FlowLayout());
// for this test driver, hardcode 1995/02/10.
c.add(new Cal(1995, 2 - 1, 10));
// and beside it, the current month.
c.add(new Cal());
f.pack();
f.setVisible(true);
}
}
希望本文所述对大家的java程序设计有所帮助。
0
投稿
猜你喜欢
- Java怎么自动添加重写的toString方法,这里我们将给大家介绍详细的解决方法。首先,添加一个任意的类,具体的类型没有要求,然后在主程序
- 本文实例为大家分享了Springboot整合pagehelper分页展示的具体代码,供大家参考,具体内容如下一、添加依赖查找maven中pa
- 随着C语言的学习慢慢结束,博主也要开始学习一门新语言了,那就是java。所以博主将会开启一个新的关于java的专栏,所以想要慢慢和我一起学习
- 我们经常会看到有一些app的banner界面可以实现循环播放多个广告图片和手动滑动循环的效果。看到那样的效果,相信大家都会想到ViewPag
- String 对象是不可改变的。每次使用 System.String 类中的方法之一时,都要在内存中创建一个新的字符串对象,这就需要为该新对
- 本文介绍了Java设计模式之享元模式,供大家参考,具体内容如下1、关于享元模式享元模式有点类似于单例模式,都是只生成一个对象被共享使用。享元
- 前言本文主要讲述如何使用Java + FFmpeg实现对视频文件的信息提取、码率压缩、分辨率转换等功能;之前在网上浏览了一大圈Java使用F
- 一:本文使用范围此文不仅仅局限于spring boot,普通的spring工程,甚至是servlet工程,都是一样的,只不过配置一些 * 的
- 前言:线程安全是并发编程中的重要关注点,造成线程安全问题的主要原因有两点,一是存在共享数据(也称临界资源),二是存在多条线程共同操作共享数据
- 前提: 可以参考文章 SpringBoot 接入 SparkSpringBoot 已经接入 Spark已配置 JavaSparkContex
- 最近在做项目的过程中 需要用JWT做登录和鉴权 查了很多资料 都不甚详细有的是需要在application.yml里进行jwt的配置 但我在
- 本文实例讲述了java实现单词搜索迷宫游戏。分享给大家供大家参考。具体分析如下:我们在杂志上,经常能够看到找单词的小游戏,在一个二维表格中,
- 打个比方:一个object就像一个大房子,大门永远打开。房子里有很多房间(也就是方法)。这些房间有上锁的(synchronized方法),
- 问题(1)自己动手写一个锁需要哪些知识?(2)自己动手写一个锁到底有多简单?(3)自己能不能写出来一个完美的锁?简介本篇文章的目标一是自己动
- 1. 插入排序步骤:1.从第一个元素开始,该元素可以认为已经被排序2.取下一个元素tem,从已排序的元素序列从后往前扫描3.如果该元素大于t
- 简介:Springboot使用Mybatis&Mybatis-plus 两者文件映射配置略有不同,之前我用的是Mybatis,但公司
- 前言最近遇到了这样一个工作场景,需要写一批dubbo接口,再将dubbo接口注册到网关中,但是当dubbo接口异常的时候会给前端返回非常不友
- 初学C++的朋友经常在类中看到public,protected,private以及它们在继承中表示的一些访问范围,很容易搞糊涂。今天本文就来
- 本文实例为大家分享了java导出百万以上数据的excel文件,供大家参考,具体内容如下1.传统的导出方式会消耗大量的内存,2003每个she
- HttpServletResponse.sendRedirect与RequestDispatcher.forward方法都可以实