⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendarframe.java~548~

📁 该系统是一个关于电子时钟的系统,他是用Java开发的一个小系统.
💻 JAVA~548~
📖 第 1 页 / 共 2 页
字号:
package calendar;

import java.awt.event.*;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.BoxLayout;
import java.util.Calendar;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import com.borland.jbcl.layout.BoxLayout2;
import java.awt.FlowLayout;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import javax.swing.border.EtchedBorder;
import java.awt.GridLayout;
import javax.swing.JButton;
import com.borland.jbcl.layout.*;
import java.awt.Dimension;

public class CalendarFrame extends JFrame implements Runnable {
    //定义面板 主面板contentPane;
    JPanel contentPane;
    //定义主面板的布局管理器;
    BorderLayout borderLayout1 = new BorderLayout();
    //定义放置组件面板;
    JPanel jPanel2 = new JPanel();
    //定义边框颜色;
    Border border1 = BorderFactory.createCompoundBorder(BorderFactory.
            createLineBorder(SystemColor.textHighlight, 2),
            BorderFactory.createEmptyBorder(2, 2, 2, 2));
    Border border2 = BorderFactory.createCompoundBorder(BorderFactory.
            createEtchedBorder(EtchedBorder.RAISED, Color.white,
                               new Color(165, 163, 151)),
            BorderFactory.createEmptyBorder(3, 3, 3, 3));
    //定义放置按钮的面板
    JPanel jPanel8 = new JPanel();
    Border border3 = BorderFactory.createCompoundBorder(BorderFactory.
            createLineBorder(SystemColor.controlText, 2),
            BorderFactory.createEmptyBorder(3, 3, 3, 3));
    JPanel jPanel9 = new JPanel();
    //定义放置日期的面板
    JPanel jPanel10 = new JPanel();
    JPanel jPanel11 = new JPanel();
    //定义放置时间的面板
    JPanel jPanel12 = new JPanel();
    JPanel jPanel13 = new JPanel();
    JLabel jLabel4 = new JLabel();
    JLabel jLabel5 = new JLabel();
    JLabel jLabel6 = new JLabel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JButton jButton3 = new JButton();
    JLabel jLabel7 = new JLabel();
    JPanel jPanel14 = new JPanel();
    JLabel jLabel8 = new JLabel();
    JPanel jPanel15 = new JPanel();
    JLabel jLabel9 = new JLabel();
    JPanel jPanel16 = new JPanel();
    JPanel jPanel17 = new JPanel();
    JLabel jLabel10 = new JLabel();
    JPanel jPanel18 = new JPanel();
    JLabel jLabel11 = new JLabel();
    JPanel jPanel19 = new JPanel();
    JLabel jLabel12 = new JLabel();
    JLabel jLabel13 = new JLabel();
    JLabel jLabel14 = new JLabel();
    JLabel jLabel15 = new JLabel();
    JLabel jLabel16 = new JLabel();
    JLabel jLabel17 = new JLabel();
    JLabel jLabel18 = new JLabel();
    JLabel jLabel19 = new JLabel();
    GridLayout gridLayout2 = new GridLayout();
    JLabel jLabel20 = new JLabel();
    JLabel jLabel21 = new JLabel();
    JLabel jLabel22 = new JLabel();
    JLabel jLabel23 = new JLabel();
    GridLayout gridLayout3 = new GridLayout();
    GridLayout gridLayout4 = new GridLayout();
    GridLayout gridLayout5 = new GridLayout();
    JLabel jLabel24 = new JLabel();
    JLabel jLabel25 = new JLabel();
    GridLayout gridLayout6 = new GridLayout();
    JLabel jLabel26 = new JLabel();
    JLabel jLabel27 = new JLabel();
    GridLayout gridLayout7 = new GridLayout();
    JLabel jLabel28 = new JLabel();
    JLabel jLabel29 = new JLabel();
    JPanel jPanel20 = new JPanel();
    //定义放置星期的面板
    JPanel jPanel21 = new JPanel();
    GridLayout gridLayout8 = new GridLayout();
    BoxLayout2 boxLayout23 = new BoxLayout2();
    FlowLayout flowLayout1 = new FlowLayout();
    static SimpleDateFormat chineseDateFormat = new SimpleDateFormat(
            "yyyy年MM月dd日");
    ImageIcon ic[] = new ImageIcon[11]; //创建图片数组对象
    Calendar ca = Calendar.getInstance(); //初始化各时间变量
    //取得时,分,秒,年,月,日
    public int hour = ca.get(Calendar.HOUR_OF_DAY);
    public int minute = ca.get(Calendar.MINUTE);
    public int second = ca.get(Calendar.SECOND);
    public int year = ca.get(Calendar.YEAR);
    public int month = ca.get(Calendar.MONTH) + 1;
    public int day = ca.get(Calendar.DAY_OF_MONTH);
    int lj = 1;
    //累计面板焦点秒数,不超过15s
    public JPanel jp[] = {jPanel16, jPanel15, jPanel14, jPanel19, jPanel18,
                         jPanel17};
    //定义面板的数组
    int jps = -1; //当前哪个面板有焦点,-1表无任何面板有焦点,作为面板数组的下标
    Border border7 = BorderFactory.createLineBorder(SystemColor.textHighlight,
            2); //获得焦点时的面板边框
    Border border9 = BorderFactory.createLineBorder(SystemColor.window, 2);
    //未获得焦点时的面板边框

    public CalendarFrame() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        border9 = BorderFactory.createLineBorder(SystemColor.inactiveCaption, 2);
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(borderLayout1);
        contentPane.setBackground(new Color(157, 185, 235));
        contentPane.setPreferredSize(new Dimension(105, 100));
        jLabel4.setText("时间:");
        jLabel5.setText("日期:");
        jButton1.setText("减少-");
        jButton1.addActionListener(new CalendarFrame_jButton1_actionAdapter(this));
        jButton2.setText("增加+");
        jButton2.addActionListener(new CalendarFrame_jButton2_actionAdapter(this));
        jButton3.setText(" 修改 ");
        jButton3.addActionListener(new CalendarFrame_jButton3_actionAdapter(this));
        jLabel7.setText("农历:");
        jLabel8.setText("  : ");
        jLabel9.setText("  :  ");
        jLabel10.setText("  -  ");
        jLabel11.setText("  -   ");
        jPanel16.setLayout(gridLayout2);
        jPanel19.setLayout(gridLayout3);
        jPanel15.setLayout(gridLayout4);
        jPanel14.setLayout(gridLayout5);
        jPanel18.setLayout(gridLayout6);
        jPanel17.setLayout(gridLayout7);
        jLabel29.setToolTipText("");
        jLabel29.setText(" 星期:");
        jPanel9.setLayout(gridLayout8);
        jLabel28.setText("MON"); //设置默认值为MON
        jPanel20.setLayout(boxLayout23);
        jPanel21.setLayout(flowLayout1);
        jPanel2.setBackground(SystemColor.inactiveCaption);
        jPanel2.setPreferredSize(new Dimension(105, 150));
        //设置面板的背景色
        jPanel13.setBackground(SystemColor.inactiveCaption);
        jPanel12.setBackground(SystemColor.inactiveCaption);
        jPanel11.setBackground(SystemColor.inactiveCaption);
        jPanel10.setBackground(SystemColor.inactiveCaption);
        jPanel9.setBackground(SystemColor.inactiveCaption);
        jPanel21.setBackground(SystemColor.inactiveCaption);
        jPanel20.setBackground(SystemColor.inactiveCaption);
        jPanel8.setBackground(SystemColor.inactiveCaption);
        jPanel8.setBorder(null);
        jPanel2.add(jPanel13);
        jPanel2.add(jPanel12);
        jPanel12.add(jLabel4);
        jPanel12.add(jPanel16);
        jPanel16.add(jLabel15);
        jPanel16.add(jLabel14);
        jPanel16.add(jLabel13);
        jPanel16.add(jLabel12);
        jPanel12.add(jLabel9);
        jPanel12.add(jPanel15);
        jPanel15.add(jLabel16);
        jPanel15.add(jLabel17);
        jPanel12.add(jLabel8);
        jPanel12.add(jPanel14);
        jPanel14.add(jLabel18);
        jPanel14.add(jLabel19);
        jPanel2.add(jPanel11);
        jPanel2.add(jPanel10);
        jPanel10.add(jLabel5);
        jPanel10.add(jPanel19);
        jPanel19.add(jLabel20);
        jPanel19.add(jLabel21);
        jPanel19.add(jLabel22);
        jPanel19.add(jLabel23);
        jPanel10.add(jLabel11);
        jPanel10.add(jPanel18);
        jPanel18.add(jLabel25);
        jPanel18.add(jLabel24);
        jPanel10.add(jLabel10);
        jPanel10.add(jPanel17);
        jPanel17.add(jLabel26);
        jPanel17.add(jLabel27);
        jPanel2.add(jPanel9);
        jPanel21.add(jLabel29);
        jPanel21.add(jLabel28);
        jPanel20.add(jLabel7);
        jPanel20.add(jLabel6);
        jPanel2.setLayout(new BoxLayout(jPanel2, BoxLayout.PAGE_AXIS));
        jPanel2.add(jPanel8);
        jPanel8.add(jButton3);
        jPanel8.add(jButton2);
        jPanel8.add(jButton1);
        jPanel9.add(jPanel21, null);
        jPanel9.add(jPanel20, null);
        contentPane.add(jPanel2, java.awt.BorderLayout.NORTH);
        for (int i = 0; i <= 9; i++) {
            ic[i] = new ImageIcon(CalendarFrame.class.getResource(
                    String.valueOf(i) + ".png"));
        }
        //取得图片的路径,定义图片数组.
        ic[10] = new ImageIcon(CalendarFrame.class.getResource("k.png"));
        //初始化各显示时间label的图片为k.png
        jLabel15.setIcon(ic[10]);
        jLabel14.setIcon(ic[10]);
        jLabel13.setIcon(ic[10]);
        jLabel12.setIcon(ic[10]);
        jLabel16.setIcon(ic[10]);
        jLabel17.setIcon(ic[10]);
        jLabel18.setIcon(ic[10]);
        jLabel19.setIcon(ic[10]);
        jLabel20.setIcon(ic[10]);
        jLabel21.setIcon(ic[10]);
        jLabel22.setIcon(ic[10]);
        jLabel23.setIcon(ic[10]);
        jLabel24.setIcon(ic[10]);
        jLabel25.setIcon(ic[10]);
        jLabel26.setIcon(ic[10]);
        jLabel27.setIcon(ic[10]);
        //初始化TAB各要切换面板的边框
        for (int i = 0; i <= 5; i++) {
            jp[i].setBorder(border9);
        }
    }

    public void run() {
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            setimageview(); //设置各时间的图片显示
            setnexttime(); //计算下一个时间、日期,即计算下一个year,month,day,hour,minute,second
            //如果存在焦点面板lj加一,如果秒数已到15秒重置边框,即去除焦点面板的焦点
            if (jps != -1 && ++lj >= 15) {
                lj = 1; // 重新赋值累计秒数为初始值1
                //重新初始化jp[jps]面板的边框,即去除焦点
                jp[jps].setBorder(border9);
                jps = -1; //设置无焦点面板
            }
        }
    }
    //计算下一个时间

    public void setnexttime() {
        //设置下一秒时间
        second++;
        if (second > 59) {
            minute++;
            second = 0;
            if (minute > 59) {
                hour++;
                minute = 0;
                if (hour > 23) {
                    hour = 0;
                }
            }
        }
        //设置下一个日期
        if (second == 0 && minute == 0 && hour == 0) {
            boolean rn = false; //是否闰年
            if (month == 1 || month == 3 || month == 5 || month == 7 ||
                month == 8 || month == 10 ||
                month == 12) {
                if (day == 31) {
                    if (month == 12) {
                        year++;
                        month = 1;
                        day = 1;
                        return;
                    } else {
                        month++;
                        day = 1;
                        return;
                    }
                } else {
                    day++;
                    return;
                }
            }
            if (month == 4 || month == 6 || month == 9 || month == 11) {
                if (day == 30) {
                    month++;
                    day = 1;
                    return;
                } else {
                    day++;
                    return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -