Java implementation Change file Query method _java

Source: Internet
Author: User

This article describes the Java implementation of the change file Query method. Share to everyone for your reference. Specifically as follows:

When you publish your package frequently, you need to find those files that were updated after the last contract, so write this release package,
Copy Output command, DOS window execution,
Why not copy the file directly, because the Java copy file modifies the file last modified date, so use DOS copy.

* * * Change the generated file template for * window > Preferences > Java > Code generation > Codes and annotations/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 $ * * p
 Ublic 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 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 = Monthchoic
    E.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 (yy) (integer.tostring); 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];
  The 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.getact
    Ioncommand ();
     if (!num.equals ("")) {//Set the current day highlighted setdayactive (Integer.parseint (num));
     When this is becomes a Bean, you can//fire some kind of the 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[] ={,/**//*, Feb-A-June APR * * * *,/**//*,
 /**//* 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 > One) throw new IllegalArgumentException ("Month" + mm + "bad, must to be 0-11");
  Cleardayactive ();
  Calendar = new GregorianCalendar (yy, MM, DD);
  Compute to leave before.
  Getday () returns 0 for Sunday, which are 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, 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 today, only if current month if (Thisyear = yy && mm = = Thismonth) setdayactive (DD);
 Shade the box for today//Say We need to is drawn on the screen repaint ();
  }/** *//** * ISLEAP () returns True if the given is a Leap year. * * "A year are a leap year if it are divisible by 4 but not by", except * years divisible by *are* leap ye
  ARS--Kernighan & Ritchie, * _the C programming Language_, P 37.
  * * Public boolean isleap (int year) {if (year% 4 = 0 && Year%!= 0 | | | year% = 0) return true;
 return false; /** *//** Set The year, month, and day */public void setdate (int yy, int mm, int dd) {//System.out.println ("Cal::s
  Etdate ");
  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; 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);

 }
}

I hope this article will help you with your Java programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.