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

📄 mycalendar.java

📁 带有备忘录功能的日历
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            public void mouseClicked(java.awt.event.MouseEvent evt) {                labAllCountMouseClicked(evt);            }        });        labTime.setForeground(java.awt.SystemColor.controlDkShadow);        labTime.setText("09点21分00秒");        panLunar.setBackground(new java.awt.Color(204, 204, 255));        panLunar.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));        labLunar.setFont(new java.awt.Font("宋体", 0, 14));        labLunar.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);        labLunar.setText("<html><div align='center'><b>2008</b>年<b>5</b>月<b>27</b>日</div><div align='center'><font size='6' color='red'><b>星期二</b></font></div><div align='center'><font size='7' color='blue'><b>农历</b></font></div><p><div align='center'><font size='6'><b>2008年</b></font></div><p><div align='center' color='green'><b>四月廿三</b></div></html>");        labLunar.setVerticalAlignment(javax.swing.SwingConstants.TOP);        javax.swing.GroupLayout panLunarLayout = new javax.swing.GroupLayout(panLunar);        panLunar.setLayout(panLunarLayout);        panLunarLayout.setHorizontalGroup(            panLunarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addComponent(labLunar, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)        );        panLunarLayout.setVerticalGroup(            panLunarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addComponent(labLunar, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)        );        javax.swing.GroupLayout contentPaneLayout = new javax.swing.GroupLayout(contentPane);        contentPane.setLayout(contentPaneLayout);        contentPaneLayout.setHorizontalGroup(            contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(contentPaneLayout.createSequentialGroup()                .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addGroup(contentPaneLayout.createSequentialGroup()                        .addGap(10, 10, 10)                        .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                            .addGroup(contentPaneLayout.createSequentialGroup()                                .addComponent(labYear)                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                                .addComponent(spYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                                .addComponent(cboMonths, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                                .addComponent(labTime))                            .addGroup(contentPaneLayout.createSequentialGroup()                                .addComponent(labCount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                                .addGap(18, 18, 18)                                .addComponent(labAllCount, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE))))                    .addComponent(spTab, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(panLunar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                .addContainerGap())        );        contentPaneLayout.setVerticalGroup(            contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(contentPaneLayout.createSequentialGroup()                .addContainerGap()                .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addComponent(panLunar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                    .addGroup(contentPaneLayout.createSequentialGroup()                        .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                            .addComponent(labYear)                            .addComponent(spYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                            .addComponent(cboMonths, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                            .addComponent(labTime))                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(spTab, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                        .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                            .addComponent(labCount, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)                            .addComponent(labAllCount, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))))                .addContainerGap())        );        mb.setBackground(java.awt.SystemColor.inactiveCaptionText);        mMemo.setBackground(java.awt.SystemColor.inactiveCaptionText);        mMemo.setMnemonic('M');        mMemo.setText("备忘录(M)");        miThatDayMemo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK));        miThatDayMemo.setText("查该日备忘录");        miThatDayMemo.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                miThatDayMemoActionPerformed(evt);            }        });        mMemo.add(miThatDayMemo);        miAllMemo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));        miAllMemo.setText("查看全部备忘录");        miAllMemo.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                miAllMemoActionPerformed(evt);            }        });        mMemo.add(miAllMemo);        mMemo.add(sep);        miWriteMemo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));        miWriteMemo.setText("写备忘录");        miWriteMemo.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                miWriteMemoActionPerformed(evt);            }        });        mMemo.add(miWriteMemo);        mb.add(mMemo);        mHelp.setBackground(java.awt.SystemColor.inactiveCaptionText);        mHelp.setMnemonic('H');        mHelp.setText("帮助(H)");        miHelp.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));        miHelp.setMnemonic('C');        miHelp.setText("帮助内容(C)");        miHelp.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                miHelpActionPerformed(evt);            }        });        mHelp.add(miHelp);        miAbout.setMnemonic('A');        miAbout.setText("关于(A)");        miAbout.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                miAboutActionPerformed(evt);            }        });        mHelp.add(miAbout);        mb.add(mHelp);        setJMenuBar(mb);        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addComponent(contentPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addComponent(contentPane, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)        );        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();        setBounds((screenSize.width-389)/2, (screenSize.height-252)/2, 389, 252);    }// </editor-fold>//GEN-END:initComponents    private void labCountMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labCountMouseClicked        // TODO add your handling code here:        if (evt.getClickCount() >= 2) {            if (labCount.getText().trim().equals("<html><div align='center'><font corlor='black'>该天备忘录:</font><font color='red'>0个</font></div></html>")) {                JOptionPane.showMessageDialog(this, "该日没记录");                return;            }            new MemoRecord(today, finalToday).setVisible(true);        }    }//GEN-LAST:event_labCountMouseClicked    private void labAllCountMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labAllCountMouseClicked        // TODO add your handling code here:        if (evt.getClickCount() >= 2) {            if (labAllCount.getText().trim().equals("<html><div align='center'><font color='black'>全部备忘录:</font><font color='red'>0个</font></div></html>")) {                JOptionPane.showMessageDialog(this, "系统备忘录为空");                return;            }            new MemoRecord("allMemo", finalToday).setVisible(true);        }}//GEN-LAST:event_labAllCountMouseClicked    private void miWriteDayMemoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miWriteDayMemoActionPerformed        // TODO add your handling code here:        if (tabDays.getSelectedColumn() == -1) {            JOptionPane.showMessageDialog(this, "请选择日期");            return;        }        String date = "";        if (((cboMonths.getSelectedIndex() + 1) + "").length() == 1) {            date = spYear.getValue().toString() + "-" + 0 + (cboMonths.getSelectedIndex() + 1) +                    "-" + tabDays.getValueAt(tabDays.getSelectedRow(), tabDays.getSelectedColumn());        } else {            date = spYear.getValue().toString() + "-" + (cboMonths.getSelectedIndex() + 1) +                    "-" + tabDays.getValueAt(tabDays.getSelectedRow(), tabDays.getSelectedColumn());        }        if (tabDays.getValueAt(tabDays.getSelectedRow(), tabDays.getSelectedColumn()) == null) {            JOptionPane.showMessageDialog(this, "日期无效,请选择正确日期!");            return;        }        new WriteMemo(date).setVisible(true);    }//GEN-LAST:event_miWriteDayMemoActionPerformed    private void miWriteMemoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miWriteMemoActionPerformed        // TODO add your handling code here:        new WriteMemo(today).setVisible(true);    }//GEN-LAST:event_miWriteMemoActionPerformed    private void miAllMemoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAllMemoActionPerformed        // TODO add your handling code here:        if (labAllCount.getText().trim().equals("<html><div align='center'><font color='black'>全部备忘录:</font><font color='red'>0个</font></div></html>")) {            JOptionPane.showMessageDialog(this, "系统备忘录为空");            return;        }        new MemoRecord("allMemo", finalToday).setVisible(true);    }//GEN-LAST:event_miAllMemoActionPerformed    private void miThatDayMemoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miThatDayMemoActionPerformed        // TODO add your handling code here:        if (labCount.getText().trim().equals("<html><div align='center'><font corlor='black'>该天备忘录:</font><font color='red'>0个</font></div></html>")) {            JOptionPane.showMessageDialog(this, "该日没记录");            return;        }        new MemoRecord(today, finalToday).setVisible(true);    }//GEN-LAST:event_miThatDayMemoActionPerformed    private void tabDaysMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabDaysMouseClicked        // TODO add your handling code here:        if (tabDays.getValueAt(tabDays.getSelectedRow(), tabDays.getSelectedColumn()) == null) {            return;        }        calendar.set(Calendar.DAY_OF_MONTH, ((Integer) (tabDays.getValueAt(tabDays.getSelectedRow(), tabDays.getSelectedColumn()))).intValue());        updateTable();        setLunar();    }//GEN-LAST:event_tabDaysMouseClicked    private void miAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAboutActionPerformed        // TODO add your handling code here:        JOptionPane.showMessageDialog(this, "------啊正作品------\r\nE-mail:h20020654@126.com\r\nQQ:229159701",                "关于",JOptionPane.INFORMATION_MESSAGE);    }//GEN-LAST:event_miAboutActionPerformed    private void miHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miHelpActionPerformed        // TODO add your handling code here:        JOptionPane.showMessageDialog(this, "由于时间和个人能力有限,\r\n若需要请求帮助,请发送E-mail到本人邮箱。" +                "\r\n或者可以加我QQ联系,\r\n不常在线,请见谅!","帮助内容",JOptionPane.INFORMATION_MESSAGE);    }//GEN-LAST:event_miHelpActionPerformed    private void setLunar() {       //这里如果在表格中点击空白处 则会出现异常 但不会影响程序的运行        calendar.set(Calendar.YEAR, ((Integer) spYear.getValue()).intValue());        calendar.set(Calendar.MONTH, cboMonths.getSelectedIndex());        calendar.set(Calendar.DAY_OF_MONTH, ((Integer) tabDays.getValueAt(tabDays.getSelectedRow(), tabDays.getSelectedColumn())).intValue());        Lunar lunar = new Lunar(calendar);        String lunarStr = lunar.toString();        String year = lunarStr.substring(0, 5);        String lunarMonthAndDay = lunarStr.substring(5);        labLunar.setText("<html><div align='center'><b>" + calendar.get(Calendar.YEAR) + "</b>年<b>" + (cboMonths.getSelectedIndex() + 1) +                "</b>月<b>" + calendar.get(Calendar.DAY_OF_MONTH) + "</b>日</div><div align='center'><font size='6' color='red'>" +                "<b><b>星期" + tabDays.getColumnName(tabDays.getSelectedColumn()) + "</b></b></font></div>" +                "<div align='center'><font size='7' color='blue'><b>农历</b></font></div><p>" +                "<div align='center'><font size='6'><b>" + year + "</b></font></div><p>" +                "<div align='center' color='green'><b>" + lunarMonthAndDay + "</b></div></html>");    }    /**     * @param args the command line arguments     */    public static void main(String args[]) {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                try {                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");                } catch (Exception e) {                    e.printStackTrace();                }                new MyCalendar().setVisible(true);            }        });    }    // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JComboBox cboMonths;    private javax.swing.JPanel contentPane;    public static javax.swing.JLabel labAllCount;    public static javax.swing.JLabel labCount;    private javax.swing.JLabel labLunar;    private javax.swing.JLabel labTime;    private javax.swing.JLabel labYear;    private javax.swing.JMenu mHelp;    private javax.swing.JMenu mMemo;    private javax.swing.JMenuBar mb;    private javax.swing.JMenuItem miAbout;    private javax.swing.JMenuItem miAllMemo;    private javax.swing.JMenuItem miHelp;    private javax.swing.JMenuItem miThatDayMemo;    private javax.swing.JMenuItem miWriteDayMemo;    private javax.swing.JMenuItem miWriteMemo;    private javax.swing.JPanel panLunar;    private javax.swing.JPopupMenu pm;    private javax.swing.JSeparator sep;    private javax.swing.JScrollPane spTab;    private javax.swing.JSpinner spYear;    private javax.swing.JTable tabDays;    // End of variables declaration//GEN-END:variables}

⌨️ 快捷键说明

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