Java圣经,带缩写左右菜单版本

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

public class Main extends JFrame implements ActionListener {
    String[] jiuyue = {"创", "出", "利", "民", "申", "书", "士", "得", "撒上", "撒下", "王上", "王下", "代上", "代下", "拉", "尼", "斯", "伯", "诗", "箴", "传", "歌", "赛", "耶", "哀", "结", "但", "何", "珥", "摩", "俄", "拿", "弥", "鸿", "哈", "番", "该", "亚", "玛"};
    String[] xinyue = {"太", "可", "路", "约", "徒", "罗", "林前", "林后", "加", "弗", "腓", "西", "帖前", "帖后", "提前", "提后", "多", "门", "来", "雅", "彼前", "彼后", "约壹", "约贰", "约叁", "犹", "启"};

    String[] lei = {"律法书", "历史书", "诗歌·智慧书", "先知书", "四福音", "教会历史", "书信", "对约翰的启示"};
    String[] lfs = {"创世记", "出埃及记", "利未记", "民数记", "申命记"};
    String[] lss = {"约书亚记", "士师记", "路得记", "撒母耳记上", "撒母耳记下", "列王纪上", "列王纪下", "历代志上", "历代志下", "以斯拉记", "尼希米记", "以斯帖记"};
    String[] sgzhs = {"约伯记", "诗篇", "箴言", "传道书", "雅歌"};
    String[] xzs = {"以赛亚书", "耶利米书", "耶利米哀歌", "以西结书", "但以理书", "何西阿书", "约珥书", "阿摩司书", "俄巴底亚书", "约拿书", "弥迦书", "那鸿书", "哈巴谷书", "西番雅书", "哈该书", "撒迦利亚书", "玛拉基书"};
    String[] sfy = {"马太福音", "马可福音", "路加福音", "约翰福音"};
    String[] jhls = {"使徒行传"};
    String[] sx = {"罗马书", "哥林多前书", "哥林多后书", "加拉太书", "以弗所书", "腓立比书", "歌罗西书", "帖撒罗尼迦前书", "帖撒罗尼迦后书", "提摩太前书", "提摩太后书", "提多书", "腓利门书", "希伯来书", "雅各书", "彼得前书", "彼得后书", "约翰一书", "约翰二书", "约翰三书", "犹大书"};
    String[] dyhdqs = {"启示录"};
    String[][] hb = {lfs, lss, sgzhs, xzs, sfy, jhls, sx, dyhdqs};

    JMenuBar jmb = new JMenuBar();
    JButton[] jb_jiuyue = new JButton[jiuyue.length];
    JButton[] jb_xinyue = new JButton[xinyue.length];

    JTextPane jtp = new JTextPane();
    JScrollPane jsp = new JScrollPane(jtp);
    FontUIResource fuir = new FontUIResource("微软雅黑", Font.BOLD, 88);
    StyledDocument sd = jtp.getStyledDocument();
    Style sty = jtp.addStyle(null, null);
    JPanel jp_jiuyue = new JPanel();
    JPanel jp_xinyue = new JPanel();

    public Main() {
        jp_jiuyue.setLayout(new GridLayout(39, 1));
        for (int i = 0; i < jiuyue.length; i++) {
            jb_jiuyue[i] = new JButton(jiuyue[i]);
            if (i < 5) {
                jb_jiuyue[i].setBackground(new Color(255, 102, 102));
            } else if (i < 17) {
                jb_jiuyue[i].setBackground(new Color(153, 204, 102));
            } else if (i < 22) {
                jb_jiuyue[i].setBackground(new Color(0, 153, 204));
            } else if (i < 39) {
                jb_jiuyue[i].setBackground(new Color(255, 255, 102));
            }
            jb_jiuyue[i].addActionListener(this);
            jp_jiuyue.add(jb_jiuyue[i]);
        }
        jp_xinyue.setLayout(new GridLayout(27, 1));
        for (int i = 0; i < xinyue.length; i++) {
            jb_xinyue[i] = new JButton(xinyue[i]);
            if (i < 4) {
                jb_xinyue[i].setBackground(new Color(255, 102, 102));
            } else if (i < 5) {
                jb_xinyue[i].setBackground(new Color(153, 204, 102));
            } else if (i < 26) {
                jb_xinyue[i].setBackground(new Color(0, 153, 204));
            } else if (i < 27) {
                jb_xinyue[i].setBackground(new Color(255, 255, 102));
            }
            jb_xinyue[i].addActionListener(this);
            jp_xinyue.add(jb_xinyue[i]);
        }
        jtp.setEditable(false);
        jtp.setBackground(Color.BLACK);
        jtp.setFont(fuir);
        jtp.setText("请选择菜单中的卷,再输入要查询的章节数字,中间用空格隔开.例如查询创世记第1章第1节则先选择律法书菜单里面的创世记,接下来在弹出的提示框中输入1 1(注:1 1之间中间用空格隔开)");


        this.add(jp_jiuyue, BorderLayout.WEST);
        this.add(jp_xinyue, BorderLayout.EAST);
        this.add(jsp, BorderLayout.CENTER);
    }

    public static void main(String[] args) {
        Main m = new Main();
        m.setSize(1900, 1000);
        m.setExtendedState(MAXIMIZED_BOTH);
        m.setDefaultCloseOperation(EXIT_ON_CLOSE);
        m.setVisible(true);

    }

    public static ArrayList<HashMap<String, String>> select(String juan, String zhang, String jie) {
        ArrayList<HashMap<String, String>> alhmss = new ArrayList<HashMap<String, String>>();
        try {
            Class.forName("org.sqlite.JDBC");
            try (Connection conn = DriverManager.getConnection("jdbc:sqlite:hb.sqlite3")) {
                try (PreparedStatement ps = conn.prepareStatement("select juan, jianxie, zhang, jie, jingwen from t_hb where jianxie = ? and zhang = ? and jie between ? and 200")) {
                    ps.setString(1, juan);
                    ps.setString(2, zhang);
                    ps.setString(3, jie);
                    try (ResultSet rs = ps.executeQuery()) {
                        while (rs.next()) {
                            HashMap<String, String> hmss = new HashMap<String, String>();
                            hmss.put("juan", rs.getString("juan"));
                            hmss.put("jianxie", rs.getString("jianxie"));
                            hmss.put("zhang", rs.getString("zhang"));
                            hmss.put("jie", rs.getString("jie"));
                            hmss.put("jingwen", rs.getString("jingwen"));
                            alhmss.add(hmss);
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return alhmss;
    }

    public void actionPerformed(ActionEvent ae) {
        String s = ae.getActionCommand();
        String shuru = JOptionPane.showInputDialog("请输入要查询的章节(例如查找所在卷1章1节到最后1节则输入:1 1(中间用空格隔开,不用输入结束的章节)):", "1 1").trim();
        if (shuru == null) {
            return;
        }
        if (shuru.equals("")) {
            return;
        }
        String[] zhangjie = shuru.split(" ");
        if (!zhangjie[0].trim().matches("^[0-9]*$") || !zhangjie[1].trim().matches("^[0-9]*$")) {
            return;
        }
        ArrayList<HashMap<String, String>> alhmss = this.select(s, zhangjie[0], zhangjie[1]);
        jtp.setText("");

        for (int i = 0; i < alhmss.size(); i++) {
            String zhang = alhmss.get(i).get("zhang");
            String jie = alhmss.get(i).get("jie");
            String jingwen = alhmss.get(i).get("jingwen");
            String zhangjiejingwen = zhang + ":" + jie + jingwen + "\n";
            if (i % 3 == 0) {
                StyleConstants.setForeground(sty, Color.CYAN);
            } else if (i % 3 == 1) {
                StyleConstants.setForeground(sty, Color.MAGENTA);
            } else if (i % 3 == 2) {
                StyleConstants.setForeground(sty, Color.YELLOW);
            } else {
                StyleConstants.setForeground(sty, Color.WHITE);
            }
            try {
                sd.insertString(sd.getLength(), zhangjiejingwen, sty);
            } catch (Exception e) {
                e.printStackTrace();
            }

            this.jtp.setCaretPosition(0);
        }

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值