How to write a perpetual calendar in a text box with java
Import? Java . awt . *;
Import? Java . awt . event . *;
Import? Java . util . *;
Import? Java . util . regex . pattern;
Import? javax . swing . *;
Public? Class? Demo28? Extension? JFrame? {
int? m? =? 1;
String []? Monthly choice? =? {? " 1",? "2",? "3",? "4",? "5",? "6",? "7",? "8",? "9",? " 10",
" 1 1",? " 12"? }; ? //? An array of characters used to store the month.
String []? List names? =? {? Sunday Monday Tuesday Wednesday Thursday Friday Saturday; ? //? An array of characters that stores the week.
Calendar? ca? =? calendar . getinstance();
Container? contentPane? =? getContentPane();
Vector & lt string & gt? Vector? =? New? Vector & lt string & gt ();
String【】【】? Dating? =? New? string【6】【7】; ? //? Format of table display data
Text field? TF; ? //? The value of the text box indicates the year.
JComboBox? JB;
JTable? Table; ? //? Display the date in tabular form.
Public? Void? GetDate (string? Year? String? Month? String? Zhou? int? Max_Day)? {
int? n? =? 0,? b? =? 0;
//? Dynamically store the date of next month in the container.
For what? (int? j? =? 1; ? j? & lt=? Max _ Day? j++)? {
vector . add(string . value of(j));
}
//Every time data is added to the table, the original table is put in advance? what's up Data emptying
for(int? x? =? 0; X< date. Length; x++){
for(int? y? =? 0; Y< date [x]. Length; y++ ){
Date [x] [y]? =? null
}
}
//? According to the day of the week on the first day of next month, build a table.
For what? (int? Answer? =? integer . parse int(week)? -? 1; ? Answer? & lt? Date [0]. Length; ? a++)? {
Date [0] [a]? =? New? String ((string)? vector . to array()【n】);
n++;
}
For what? (int? Me? =? 1; ? Me? & lt? Date. Length; ? i++)? {
For what? (int? j? =? 0; ? j? & lt? Date [I] length; ? j++)? {
What if? (n? & lt? Vector. Size ())? {
Date [I] [J]? =? New? String ((string)? vector . to array()【n】);
n++;
}? other
Break;
}
}
//? Clear all data in the container so that new data can be stored next time.
What time? (b? & lt? Vector. Size ())? {
vector . remove(b);
}
}
Public? Void? Select the date (string? God)? {
JLabel? Label? =? New? JLabel();
For what? (int? y? =? 0; ? y? & lt? Date. Length; ? y++)? {
For what? (int? z? =? 0; ? z? & lt? Date [y]. Length; ? z++)? {
system . out . print(date【y】【z】? +? "?" );
system . out . println(day);
What if? (Date [y] [z]? ! =? null)? {
What if? (date [y] [z]. Equal to (days)? {
table . setselectionbackground(color . yellow);
Return;
}
}
}
}
}
Public? Void? Draw a picture ()? {
SetTitle ("calendar");
set bounds(200,? 200,? 350,? 178);
AddWindowListener (new? WindowAdapter(){
Public? Void? Window closed (WindowEvent? e)? {
system . exit(0);
}
});
int? m? =? 0;
String? Year? =? String value (ca.get (calendar. Year); ? //? Gets the year of the current system time and stores the value in the variable year.
String? Month? =? String value (ca.get (calendar. Month)? +? 1); ? //? Gets the month of the current system time and stores the value in the variable month.
String? Day? =? String value (ca.get (calendar. Date); ? //? Gets the date of the current system time and stores the value in the variable day.
Calendar. Date? 1); ? //? Put a calendar? The data of the object is set to 1.
String? A week? =? String value (ca.get (calendar. What day is it)); ? //? According to the set calendar object, calculate the day of the week on the first day of this month.
int? Max_Day? =? Ca.getActualMaximum (calendar. Date); ? //? Gets the number of days in the current system time month.
GetDate (year, month? Zhou? max _ Day);
//? Get the same month value as the current system time from the month array.
For what? (int? Me? =? 0; ? Me? & lt? month choice . length? i++)? {
What if? (month choose【I】。 Equal to (month)? {
m? =? Me;
}
}
JToolBar? Toolbar? =? New? JToolBar();
JButton? b 1? =? New? JButton(“《“);
B 1.addMouseListener (new? my mouse listener 1();
JButton? b2? =? New? JButton(“》“);
B2.addMouseListener (new? my mouse listener 2());
JLabel? j 1? =? New? JLabel ("Year");
JLabel? j2? =? New? JLabel ("month");
tf? =? New? A text field (5);
Tf.addKeyListener (new? mykey listener());
Tf.setText (year);
jb? =? New? JComboBox(month choice);
JB . setselectedindex(m);
Jb.addActionListener (new? myactionlistener 3());
Table? =? New? JTable (date, column name);
//table . addmouse listener(new? table mouse listener());
Table. setPreferred ScrallableViewportSize (new? Dimension (350,? 150));
JScrollPane? jsp? =? New? JScrollPane (table);
content pane . add(JSP,? Boundary layout. Center);
Select the date (day);
toolbar . add(b 1);
toolbar . add(TF);
toolbar . add(B2);
toolbar . add(j 1);
toolbar . add(JB);
toolbar . add(J2);
toolbar . set location(0,0);
toolbar . setsize(400,? 15);
ContentPane.add (toolbar,? Boundary layout. North);
set visible(true);
New? Thread (new? PaintThread()。 start(); ? //? Call the internal class PaintThread and redraw it according to the settings inside.
}