?? datefrom.java~1~
字號:
package testsystem;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.*;
import java.awt.Font;
import javax.swing.BorderFactory;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.awt.GridLayout;
import java.awt.Color;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
public class DateFrom extends JFrame {
private JPanel contentPane;
private JButton jButton1 = new JButton();
private JTextField textYear = new JTextField();
private JButton jButton2 = new JButton();
private JTextField textMonth = new JTextField();
private JScrollPane jScrollPane1 = new JScrollPane();
private JButton jButton3 = new JButton();
private JTextArea textrizhi = new JTextArea();
private JPanel jPanel1 = new JPanel();
private Calendar date = Calendar.getInstance();
private GridLayout gridLayout1 = new GridLayout(7, 7);
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
private JLabel jLabel4 = new JLabel();
private JLabel jLabel5 = new JLabel();
private JLabel jLabel6 = new JLabel();
private JLabel jLabel7 = new JLabel();
private JLabel jLabel8 = new JLabel();
private JLabel jLabel9 = new JLabel();
private JLabel jLabel10 = new JLabel();
private JLabel jLabel11 = new JLabel();
private JLabel jLabel12 = new JLabel();
private JLabel jLabel13 = new JLabel();
private JLabel jLabel14 = new JLabel();
private JLabel jLabel15 = new JLabel();
private JLabel jLabel16 = new JLabel();
private JLabel jLabel17 = new JLabel();
private JLabel jLabel18 = new JLabel();
private JLabel jLabel19 = new JLabel();
private JLabel jLabel20 = new JLabel();
private JLabel jLabel21 = new JLabel();
private JLabel jLabel22 = new JLabel();
private JLabel jLabel23 = new JLabel();
private JLabel jLabel24 = new JLabel();
private JLabel jLabel25 = new JLabel();
private JLabel jLabel26 = new JLabel();
private JLabel jLabel27 = new JLabel();
private JLabel jLabel28 = new JLabel();
private JLabel jLabel29 = new JLabel();
private JLabel jLabel30 = new JLabel();
private JLabel jLabel31 = new JLabel();
private JLabel jLabel32 = new JLabel();
private JLabel jLabel33 = new JLabel();
private JLabel jLabel34 = new JLabel();
private JLabel jLabel35 = new JLabel();
private JLabel jLabel36 = new JLabel();
private JLabel jLabel37 = new JLabel();
private JLabel jLabel38 = new JLabel();
private JLabel jLabel39 = new JLabel();
private JLabel jLabel40 = new JLabel();
private JLabel jLabel41 = new JLabel();
private JLabel jLabel42 = new JLabel();
private JLabel jLabel43 = new JLabel();
private JLabel jLabel44 = new JLabel();
private JLabel jLabel45 = new JLabel();
private JLabel jLabel46 = new JLabel();
private JLabel jLabel47 = new JLabel();
private JLabel jLabel48 = new JLabel();
private JLabel jLabel49 = new JLabel();
private JLabel jLabel50 = new JLabel();
private JLabel[] day = {jLabel9, jLabel10, jLabel11, jLabel12, jLabel13,
jLabel14, jLabel15, jLabel16,
jLabel17, jLabel18, jLabel19, jLabel20,
jLabel21, jLabel22, jLabel23, jLabel24, jLabel25,
jLabel26,
jLabel27, jLabel28, jLabel29, jLabel30, jLabel31,
jLabel32,
jLabel33, jLabel34, jLabel35, jLabel36, jLabel37,
jLabel38,
jLabel39, jLabel40, jLabel41, jLabel42, jLabel43,
jLabel45, jLabel46, jLabel47, jLabel48, jLabel49,
jLabel50};
private JButton jButton4 = new JButton();
private JButton jButton5 = new JButton();
private int week; //星期幾
private int Day; //今天是幾號
public DateFrom() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public void finalize() {
System.gc();
}
public void display(int year, int month) { //顯示日歷
int tempday = 0;
GregorianCalendar gr = new GregorianCalendar(year, month - 1, 1);
week = gr.get(Calendar.DAY_OF_WEEK);
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 ||
month == 10 || month == 12) {
tempday = 31;
}
else if (month == 4 || month == 6 || month == 9 || month == 11) {
tempday = 30;
}
else if (month == 2) {
if (year % 400 == 0) {
tempday = 28;
} else {
tempday = 29;
}
}
for (int i = week, j = 1; j <= tempday; i++, j++) {
day[i].setHorizontalAlignment(SwingConstants.CENTER);
day[i].setText(String.valueOf(j));
// if(Day+week-1==j)
// {
// day[j].setForeground(Color.cyan);
// }
}
}
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(569, 390));
setTitle("日歷");
this.addWindowListener(new DateFrom_this_windowAdapter(this));
jButton1.setBounds(new Rectangle(1, 22, 83, 25));
jButton1.setText("上一年");
jButton1.addActionListener(new DateFrom_jButton1_actionAdapter(this));
textYear.setEnabled(false);
textYear.setFont(new java.awt.Font("宋體", Font.PLAIN, 20));
textYear.setHorizontalAlignment(SwingConstants.CENTER);
textYear.setBounds(new Rectangle(92, 21, 79, 25));
jButton2.setBounds(new Rectangle(183, 23, 83, 25));
jButton2.setText("下一年");
jButton2.addActionListener(new DateFrom_jButton2_actionAdapter(this));
textMonth.setEnabled(false);
textMonth.setFont(new java.awt.Font("宋體", Font.PLAIN, 20));
textMonth.setHorizontalAlignment(SwingConstants.CENTER);
textMonth.setBounds(new Rectangle(359, 23, 80, 25));
textMonth.addActionListener(new DateFrom_textMonth_actionAdapter(this));
jScrollPane1.setBounds(new Rectangle(317, 76, 240, 238));
jButton3.setBounds(new Rectangle(407, 322, 111, 33));
jButton3.setText("保存日志");
jButton3.addActionListener(new DateFrom_jButton3_actionAdapter(this));
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(13, 76, 293, 263));
jPanel1.setLayout(gridLayout1);
jLabel2.setForeground(Color.red);
jLabel2.setBorder(null);
jLabel2.setText("星期日");
jLabel3.setText("星期一");
jLabel4.setText("星期二");
jLabel5.setText("星期三");
jLabel6.setText("星期五");
jLabel7.setForeground(Color.red);
jLabel7.setText("星期六");
jLabel8.setText("星期四");
textrizhi.setText("請寫上今天的心情!");
jLabel16.setForeground(Color.red);
jLabel23.setForeground(Color.red);
jLabel30.setForeground(Color.red);
jLabel37.setForeground(Color.red);
jLabel45.setForeground(Color.red);
jLabel50.setForeground(Color.red);
jLabel10.setForeground(Color.red);
jLabel17.setForeground(Color.red);
jLabel24.setForeground(Color.red);
jLabel31.setForeground(Color.red);
jLabel38.setForeground(Color.red);
jLabel46.setForeground(Color.red);
jButton4.setBounds(new Rectangle(270, 23, 83, 25));
jButton4.setText("上一月");
jButton4.addActionListener(new DateFrom_jButton4_actionAdapter(this));
jButton5.setBounds(new Rectangle(455, 23, 83, 25));
jButton5.setText("下一月");
jButton5.addActionListener(new DateFrom_jButton5_actionAdapter(this));
contentPane.add(jScrollPane1);
jScrollPane1.getViewport().add(textrizhi);
contentPane.add(jButton3);
contentPane.add(jPanel1);
jPanel1.add(jLabel2);
jPanel1.add(jLabel3);
jPanel1.add(jLabel4);
jPanel1.add(jLabel5);
jPanel1.add(jLabel8);
jPanel1.add(jLabel6);
jPanel1.add(jLabel7);
jPanel1.add(jLabel10);
jPanel1.add(jLabel11);
jPanel1.add(jLabel12);
jPanel1.add(jLabel13);
jPanel1.add(jLabel14);
jPanel1.add(jLabel15);
jPanel1.add(jLabel16);
jPanel1.add(jLabel17);
jPanel1.add(jLabel18);
jPanel1.add(jLabel19);
jPanel1.add(jLabel20);
jPanel1.add(jLabel21);
jPanel1.add(jLabel22);
jPanel1.add(jLabel23);
jPanel1.add(jLabel24);
jPanel1.add(jLabel25);
jPanel1.add(jLabel26);
jPanel1.add(jLabel27);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -