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

📄 wannianli.java

📁 电子万年历的java
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package wannianli;

import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.Dimension;
import javax.swing.JTextField;
import java.util.Date;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JFileChooser;
import java.io.File;
import java.io.FileReader;
import java.io.*;

public class WanNianLi extends JFrame {
    JPanel contentPane;
    JMenuBar jMenuBar1 = new JMenuBar();
    JMenu jMenuFile = new JMenu();
    JMenuItem jMenuFileExit = new JMenuItem();
    JMenu jMenuHelp = new JMenu();
    JMenuItem jMenuHelpAbout = new JMenuItem();
    JToolBar jToolBar = new JToolBar();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JButton jButton3 = new JButton();
    ImageIcon image1 = new ImageIcon(wannianli.WanNianLi.class.getResource(
            "openFile.png"));
    ImageIcon image2 = new ImageIcon(wannianli.WanNianLi.class.getResource(
            "closeFile.png"));
    ImageIcon image3 = new ImageIcon(wannianli.WanNianLi.class.getResource(
            "help.png"));
    JLabel statusBar = new JLabel();
    XYLayout xYLayout1 = new XYLayout();
    Dates nongli;
    JTextField jTextField1 = new JTextField();
    JTextField jTextField2 = new JTextField();
    JTextField jTextField3 = new JTextField();
    JTextField jTextField4 = new JTextField();
    JTextField jTextField5 = new JTextField();
    JTextField jTextField6 = new JTextField();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JLabel jLabel4 = new JLabel();
    JLabel jLabel5 = new JLabel();
    JLabel jLabel6 = new JLabel();
    JLabel jLabel7 = new JLabel();
    JScrollPane jScrollPane1 = new JScrollPane();
    JTextArea jTextArea1 = new JTextArea();
    JButton jButton4 = new JButton();
    JButton jButton5 = new JButton();
    JButton jButton6 = new JButton();
    JButton jButton7 = new JButton();
    JFileChooser jfc = new JFileChooser();
    public WanNianLi() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    /**
     * Component initialization.
     *
     * @throws java.lang.Exception
     */
    private void jbInit() throws Exception {
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(xYLayout1);
        setSize(new Dimension(500, 600));
        setTitle("Frame Title");
        statusBar.setText(" ");
        jMenuFile.setText("File");
        jMenuFileExit.setText("Exit");
        jMenuFileExit.addActionListener(new
                                        WanNianLi_jMenuFileExit_ActionAdapter(this));
        jMenuHelp.setText("Help");
        jMenuHelpAbout.setText("About");
        jMenuHelpAbout.addActionListener(new
                                         WanNianLi_jMenuHelpAbout_ActionAdapter(this));
        jLabel1.setText("阳历:");
        jLabel2.setText("年");
        jLabel3.setText("月");
        jLabel4.setText("日");
        jLabel5.setText("农历年份:");
        jLabel6.setText("农历日期:");
        jLabel7.setText("纪念日:");
        jTextField5.setEditable(false);
        jTextField6.setEditable(false);
        jTextField2.setEditable(false);
        jTextField3.setEditable(false);
        jScrollPane1.setAutoscrolls(true);
        jTextArea1.setLineWrap(true);
        jButton4.setText("万年历");
        jButton4.addActionListener(new WanNianLi_jButton4_actionAdapter(this));
        jButton5.setText("储存纪录");
        jButton5.addActionListener(new WanNianLi_jButton5_actionAdapter(this));
        jButton6.setText("读取备忘");
        jButton6.addActionListener(new WanNianLi_jButton6_actionAdapter(this));
        jButton7.setToolTipText("");
        jButton7.setText("退出程序");
        jButton7.addActionListener(new WanNianLi_jButton7_actionAdapter(this));
        jTextField1.setEditable(false);
        jTextField4.setEditable(false);
        jMenuBar1.add(jMenuFile);
        jMenuFile.add(jMenuFileExit);
        jMenuBar1.add(jMenuHelp);
        jMenuHelp.add(jMenuHelpAbout);
        setJMenuBar(jMenuBar1);
        jButton1.setIcon(image1);
        jButton1.setToolTipText("Open File");
        jButton2.setIcon(image2);
        jButton2.setToolTipText("Close File");
        jButton3.setIcon(image3);
        jButton3.setToolTipText("Help");
        jToolBar.add(jButton1);
        jToolBar.add(jButton2);
        jToolBar.add(jButton3);
        contentPane.add(statusBar, new XYConstraints(0, 585, 800, -1));
        contentPane.add(jToolBar, new XYConstraints(0, 0, 800, -1));
        contentPane.add(jTextField3, new XYConstraints(141, 209, 237, 28));
        contentPane.add(jTextField2, new XYConstraints(141, 169, 237, 28));
        contentPane.add(jTextField1, new XYConstraints(141, 129, 237, 28));
        contentPane.add(jTextField4, new XYConstraints(81, 81, 61, 27));
        contentPane.add(jTextField5, new XYConstraints(178, 81, 61, 27));
        contentPane.add(jTextField6, new XYConstraints(277, 81, 61, 27));
        contentPane.add(jLabel4, new XYConstraints(350, 81, 56, 28));
        contentPane.add(jLabel7, new XYConstraints(72, 211, 56, 28));
        contentPane.add(jLabel6, new XYConstraints(57, 169, 76, 28));
        contentPane.add(jLabel5, new XYConstraints(56, 129, 76, 28));
        contentPane.add(jLabel1, new XYConstraints(34, 81, 56, 28));
        contentPane.add(jLabel2, new XYConstraints(147, 81, 56, 28));
        contentPane.add(jLabel3, new XYConstraints(247, 81, 56, 28));
        contentPane.add(jScrollPane1, new XYConstraints(19, 271, 456, 224));
        contentPane.add(jButton4, new XYConstraints(399, 81, 79, 161));
        contentPane.add(jButton5, new XYConstraints(19, 504, 128, 30));
        contentPane.add(jButton7, new XYConstraints(347, 504, 128, 30));
        contentPane.add(jButton6, new XYConstraints(181, 504, 128, 30));
        jScrollPane1.getViewport().add(jTextArea1);
        nongli = new Dates(this);
        nongli.setVisible(true);
        NongliDates.init();


    }

    /**
     * File | Exit action performed.
     *
     * @param actionEvent ActionEvent
     */
    void jMenuFileExit_actionPerformed(ActionEvent actionEvent) {
        System.exit(0);
    }

    /**
     * Help | About action performed.
     *
     * @param actionEvent ActionEvent
     */

    void showDateMessage(NongliDates nld){
        this.jTextField4.setText(nld.curYear+"");
        this.jTextField5.setText(""+nld.curMonth+"");
        this.jTextField6.setText(nld.curDate+"");
        this.jTextField1.setText(nld.NongliStr);
        this.jTextField2.setText(nld.NongliDayStr);
        this.jTextField3.setText(nld.JieRi);
    }

    void jMenuHelpAbout_actionPerformed(ActionEvent actionEvent) {
        WanNianLi_AboutBox dlg = new WanNianLi_AboutBox(this);
        Dimension dlgSize = dlg.getPreferredSize();
        Dimension frmSize = getSize();
        Point loc = getLocation();
        dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                        (frmSize.height - dlgSize.height) / 2 + loc.y);

        dlg.setModal(true);
        dlg.pack();
        dlg.setVisible(true);
    }

    private String openFile() {
        String message = "";
        if (JFileChooser.APPROVE_OPTION == jfc.showOpenDialog(this)) {
            try {
                String filename1 = jfc.getSelectedFile().getPath();
                DataInputStream dos=new DataInputStream(new FileInputStream(filename1));
                this.jTextField1.setText(dos.readUTF());
                this.jTextField2.setText(dos.readUTF());
                this.jTextField3.setText(dos.readUTF());
                this.jTextField4.setText(dos.readUTF());
                this.jTextField5.setText(dos.readUTF());
                this.jTextField6.setText(dos.readUTF());
                this.jTextArea1.setText(dos.readUTF());
                dos.close();

            } catch (Exception e) {
                message = e.getMessage();
            }
        }
        return message;
    }


    private String saveFile() {
        String message = "";
        if (JFileChooser.APPROVE_OPTION == jfc.showSaveDialog(this)) {
            try {
                String filename1 = jfc.getSelectedFile().getPath();
                DataOutputStream dos=new DataOutputStream(new FileOutputStream(filename1,false));
                dos.writeUTF(this.jTextField1.getText());
                dos.writeUTF(this.jTextField2.getText());
                dos.writeUTF(this.jTextField3.getText());
                dos.writeUTF(this.jTextField4.getText());
                dos.writeUTF(this.jTextField5.getText());
                dos.writeUTF(this.jTextField6.getText());
                dos.writeUTF(this.jTextArea1.getText());
                dos.close();
            } catch (Exception e) {
                message = e.getMessage();
            }
        }
        return message;
    }


    public void jButton4_actionPerformed(ActionEvent e) {
            nongli.setVisible(true);
    }

    public void jButton7_actionPerformed(ActionEvent e) {
        System.exit(0);
    }

    public void jButton5_actionPerformed(ActionEvent e) {
        saveFile();
    }

    public void jButton6_actionPerformed(ActionEvent e) {
        openFile();
    }
}


class WanNianLi_jButton5_actionAdapter implements ActionListener {
    private WanNianLi adaptee;
    WanNianLi_jButton5_actionAdapter(WanNianLi adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton5_actionPerformed(e);
    }
}


class WanNianLi_jButton7_actionAdapter implements ActionListener {
    private WanNianLi adaptee;
    WanNianLi_jButton7_actionAdapter(WanNianLi adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton7_actionPerformed(e);
    }
}


class WanNianLi_jButton4_actionAdapter implements ActionListener {
    private WanNianLi adaptee;
    WanNianLi_jButton4_actionAdapter(WanNianLi adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton4_actionPerformed(e);
    }
}


class WanNianLi_jMenuFileExit_ActionAdapter implements ActionListener {
    WanNianLi adaptee;

    WanNianLi_jMenuFileExit_ActionAdapter(WanNianLi adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent actionEvent) {
        adaptee.jMenuFileExit_actionPerformed(actionEvent);
    }
}


class WanNianLi_jMenuHelpAbout_ActionAdapter implements ActionListener {
    WanNianLi adaptee;

    WanNianLi_jMenuHelpAbout_ActionAdapter(WanNianLi adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent actionEvent) {
        adaptee.jMenuHelpAbout_actionPerformed(actionEvent);
    }
}















//万年历窗口类=======================================
class Dates extends JFrame implements ActionListener {

    TextField year = new TextField(5);
    TextField month = new TextField(2);
    Button button1 = new Button("确认");
    Button button2 = new Button("关闭窗口");
    Container cp = getContentPane();
    JTextField[] day = new JTextField[49];
    JButton[] dayB = new JButton[42];
    JPanel jp = new JPanel();
    JFrame owner;

    public Dates(JFrame owner) {
        setTitle("电子万年历");
        setSize(470, 500);
        this.setLocation(0, 200);
        cp.setLayout(new FlowLayout());
        cp.add(new Label("请输入所需要查询的年份与月份,之后按“确认”"));
        jp.setLayout(new GridLayout(13, 7));
        year.setText("");
        month.setText("");
        cp.add(year);
        cp.add(new Label("年"));
        cp.add(month);
        cp.add(new Label("月"));
        cp.add(button1);
        cp.add(button2);
        for (int i = 0; i < 7; i++) {
            day[i] = new JTextField(3);
            day[i].setEditable(false);
            jp.add(day[i]);
        }
        for (int i = 1; i < 7; i++) {
            for (int j = 0; j < 7; j++) {
                day[i * 7 + j] = new JTextField(5);
                day[i * 7 + j].setEditable(false);
                jp.add(day[i * 7 + j]);
            }
            for (int j = 0; j < 7; j++) {
                dayB[i * 7 + j - 7] = new JButton();
                dayB[i * 7 + j - 7].setText("View");
                dayB[i * 7 + j - 7].setEnabled(false);
                dayB[i * 7 + j - 7].addActionListener(this);
                jp.add(dayB[i * 7 + j - 7]);
            }
        }
        cp.add(jp);
        this.owner = owner;
        button1.addActionListener(this);
        button2.addActionListener(this);
        //setResizable(false);
        //jp.setSize(300,300);
    }

    void building(Date date) {
        Date date1 = new Date();
        int year = Integer.parseInt(date.toString().substring(24, 28)) - 1900;
        int month = date.getMonth();
        int day1 = date.getDay();
        int error = 0;
        day[0].setText("日");
        day[1].setText("一");
        day[2].setText("二");
        day[3].setText("三");
        day[4].setText("四");
        day[5].setText("五");
        day[6].setText("六");
        try {
            int m = 1;
            for (int i = 7; i < day1 + 7; i++) {
                day[i].setText("");
                dayB[i - 7].setEnabled(false);
            }
            for (int i = day1 + 7; i < 49; i++) {
                day[i].setText(m + "");
                m++;
                dayB[i - 7].setEnabled(true);

⌨️ 快捷键说明

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