Java Date Time selection control (code)

Source: Internet
Author: User
A project in the development of the need for date and time to select the control, the Internet to provide a few, and the quality of general, so have to do their own, reference to the work of a classmate online Jave date selection control Datechooser.

The current code will be a date-time selection encapsulated in a button component, should be very useful, support application, applets

CODE:

Import Java.util.Date;
Import Java.util.Calendar;
Import Java.text.DateFormat;
Import Java.text.SimpleDateFormat;
Import java.text.ParseException;
Import Java.awt.Color;
Import Java.awt.Font;
Import Java.awt.Point;
Import java.awt.Dimension;
Import Java.awt.BorderLayout;
Import Java.awt.FlowLayout;
Import Java.awt.GridLayout;
Import java.awt.Component;
Import Java.awt.Cursor;
Import Java.awt.Frame;

Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import Java.awt.event.MouseListener;
Import Java.awt.event.MouseAdapter;
Import java.awt.event.MouseEvent;
Import Javax.swing.JFrame;
Import Javax.swing.JButton;
Import Javax.swing.JDialog;
Import Javax.swing.JPanel;
Import Javax.swing.JLabel;
Import Javax.swing.JSpinner;
Import Javax.swing.JSpinner.NumberEditor;
Import Javax.swing.SpinnerNumberModel;
Import javax.swing.SwingUtilities;
Import javax.swing.SwingConstants;
Import Javax.swing.event.ChangeListener;
Import javax.swing.event.ChangeEvent;
Import Javax.swing.border.LineBorder;

public class Datechooserjbutton extends JButton {

Private Datechooser Datechooser =null;

Private String Prelabel = "";

Public Datechooserjbutton () {
This (Getnowdate ());
}

Public Datechooserjbutton (SimpleDateFormat DF, String datestring) {
This ();
SetText (df,datestring);
}

Public Datechooserjbutton (date date) {
This ("", date);
}

Public Datechooserjbutton (String Prelabel, date date) {
if (prelabel!=null) This.prelabel = Prelabel;
Setdate (date);
SetBorder (NULL);
SetCursor (New Cursor (cursor.hand_cursor));
Super.addactionlistener (new ActionListener () {
public void actionperformed (ActionEvent e) {
if (datechooser==null) Datechooser = new Datechooser ();
Point P = Getlocationonscreen ();
P.Y = p.y+30;
Datechooser.showdatechooser (P);
}
}) ;
}

private static Date getnowdate () {
Return Calendar.getinstance (). GetTime ();
}

private static SimpleDateFormat Getdefaultdateformat () {
Return to the new SimpleDateFormat ("YYYY year mm month DD Day hh");
}

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.