package hb;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.TrayIcon.MessageType;
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.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
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[] lfs = { "创世记", "出埃及记", "利未记", "民数记", "申命记" };
String[] lss = { "约书亚记", "士师记", "路得记", "撒母耳记上", "撒母耳记下", "列王纪上", "列王纪下", "历代志上", "历代志下", "以斯拉记", "尼希米记", "以斯帖记" };
String[] sgzhs = { "约伯记", "诗篇", "箴言", "传道书", "雅歌" };
String[] xzs = { "以赛亚书", "耶利米书", "耶利米哀歌", "以西结书", "但以理书", "何西阿书", "约珥书", "阿摩司书", "俄巴底亚书", "约拿书", "弥迦书", "那鸿书",
"哈巴谷书", "西番雅书", "哈该书", "撒迦利亚书", "玛拉基书" };
String[] sfy = { "马太福音", "马可福音", "路加福音", "约翰福音" };
String stxz = "使徒行传";
String[] sx = { "罗马书", "哥林多前书", "哥林多后书", "加拉太书", "以弗所书", "腓立比书", "歌罗西书", "帖撒罗尼迦前书", "帖撒罗尼迦后书", "提摩太前书", "提摩太后书",
"提多书", "腓利门书", "希伯来书", "雅各书", "彼得前书", "彼得后书", "约翰一书", "约翰二书", "约翰三书", "犹大书" };
String qsl = "启示录";
String pinyin = "拼音首字母查询";
String sqlcx = "sql语句查询";
JMenuBar jmb = new JMenuBar();
JMenu jm_lfs = new JMenu("律法书");
JMenu jm_lss = new JMenu("历史书");
JMenu jm_sgzhs = new JMenu("诗歌·智慧书");
JMenu jm_xzs = new JMenu("先知书");
JMenu jm_sfy = new JMenu("四福音");
JMenu jm_jhls = new JMenu("教会历史");
JMenu jm_sx = new JMenu("书信");
JMenu jm_dyhdqs = new JMenu("启示录");
JMenu jm_pinyin = new JMenu("拼音首字母查询");
JMenu jm_sql = new JMenu("sql语句查询");
JMenu jm_bqsm = new JMenu("版权声明");
JMenuItem[] jmi_lfs = new JMenuItem[5];
JMenuItem[] jmi_lss = new JMenuItem[12];
JMenuItem[] jmi_sgzhs = new JMenuItem[5];
JMenuItem[] jmi_xzs = new JMenuItem[17];
JMenuItem[] jmi_sfy = new JMenuItem[4];
JMenuItem jmi_stxz = new JMenuItem(stxz);
JMenuItem[] jmi_sx = new JMenuItem[21];
JMenuItem jmi_qsl = new JMenuItem(qsl);
JMenuItem jmi_pinyin = new JMenuItem(pinyin);
JMenuItem jmi_sql = new JMenuItem(sqlcx);
JMenuItem jmi_bqsm = new JMenuItem("版权声明");
JTextPane jtp = new JTextPane();
JScrollPane jsp = new JScrollPane(jtp);
public Main() {
this.setTitle("圣经投屏Java+sqlite3极速版");
jtp.setEditable(false);
for (int i = 0; i < lfs.length; i++) {
jmi_lfs[i] = new JMenuItem(lfs[i]);
jm_lfs.add(jmi_lfs[i]);
jmi_lfs[i].addActionListener(this);
}
for (int i = 0; i < lss.length; i++) {
jmi_lss[i] = new JMenuItem(lss[i]);
jm_lss.add(jmi_lss[i]);
jmi_lss[i].addActionListener(this);
}
for (int i = 0; i < sgzhs.length; i++) {
jmi_sgzhs[i] = new JMenuItem(sgzhs[i]);
jm_sgzhs.add(jmi_sgzhs[i]);
jmi_sgzhs[i].addActionListener(this);
}
for (int i = 0; i < xzs.length; i++) {
jmi_xzs[i] = new JMenuItem(xzs[i]);
jm_xzs.add(jmi_xzs[i]);
jmi_xzs[i].addActionListener(this);
}
for (int i = 0; i < sfy.length; i++) {
jmi_sfy[i] = new JMenuItem(sfy[i]);
jm_sfy.add(jmi_sfy[i]);
jmi_sfy[i].addActionListener(this);
}
jm_jhls.add(jmi_stxz);
jmi_stxz.addActionListener(this);
for (int i = 0; i < sx.length; i++) {
jmi_sx[i] = new JMenuItem(sx[i]);
jm_sx.add(jmi_sx[i]);
jmi_sx[i].addActionListener(this);
}
jm_dyhdqs.add(jmi_qsl);
jmi_qsl.addActionListener(this);
jm_pinyin.add(jmi_pinyin);
jmi_pinyin.addActionListener(this);
jm_sql.add(jmi_sql);
jmi_sql.addActionListener(this);
jm_bqsm.add(jmi_bqsm);
jmi_bqsm.addActionListener(this);
jmb.add(jm_lfs);
jmb.add(jm_lss);
jmb.add(jm_sgzhs);
jmb.add(jm_xzs);
jmb.add(jm_sfy);
jmb.add(jm_jhls);
jmb.add(jm_sx);
jmb.add(jm_dyhdqs);
jmb.add(jm_pinyin);
jmb.add(jm_sql);
jmb.add(jm_bqsm);
this.setJMenuBar(jmb);
this.add(jsp);
this.jtp.setBackground(Color.BLACK);
}
public static void main(String[] args) {
Main m = new Main();
m.setSize(1000, 700);
m.setExtendedState(JFrame.MAXIMIZED_BOTH);
m.setVisible(true);
m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae) {
String s = ae.getActionCommand();
if (s.equals("拼音首字母查询")) {
String juanzhangjie = JOptionPane
.showInputDialog("请输入要查询的卷章节(例如查找约翰福音3章16节到30节则输入:yhfy 3 16 30(yhfy必须小写,中间用空格隔开)):");
if (juanzhangjie == null) {
return;
} else if (juanzhangjie.equals("")) {
return;
} else {
try {
String[] fengehou = juanzhangjie.split(" ");
ArrayList<ArrayList<Object>> alalo = this.selectpinyin(fengehou[0], fengehou[1], fengehou[2],
fengehou[3]);
int i = 0;
StyledDocument sd = jtp.getStyledDocument();
jtp.setText("");
for (ArrayList<Object> alo : alalo) {
String jie = alo.get(1).toString() + ":" + alo.get(2).toString() + alo.get(3).toString() + "\n";
Style sty = jtp.addStyle(null, null);
if (i % 3 == 0) {
StyleConstants.setForeground(sty, Color.cyan);
} else if (i % 3 == 1) {
StyleConstants.setForeground(sty, Color.MAGENTA);
} else {
StyleConstants.setForeground(sty, Color.YELLOW);
}
sd.insertString(sd.getLength(), jie, sty);
i++;
// jingwen += jie;
}
this.jtp.setFont(new FontUIResource("黑体", Font.PLAIN, 100));
// this.jtp.setForeground(Color.red);
// this.jtp.setText(jingwen);
this.jtp.setCaretPosition(0);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (s.equals("sql语句查询")) {
String sql = JOptionPane.showInputDialog(
"请输入要查询的卷章节sql语句(例如查找创世记3章1节到31节则输入:select juan, zhang, jie, jingwen from t_hb where juan = 'csj' and zhang = 1 and jie between 1 and 31(yhfy必须小写,慎用delete insert update!)):",
"select juan, zhang, jie, jingwen from t_hb where pinyin = 'csj' and zhang = 1 and jie between 1 and 31");
if (sql == null) {
return;
} else if (sql.equals("")) {
return;
} else {
try {
ArrayList<ArrayList<Object>> alalo = this.selectsql(sql);
int i = 0;
StyledDocument sd = jtp.getStyledDocument();
jtp.setText("");
for (ArrayList<Object> alo : alalo) {
String jie = alo.get(1).toString() + ":" + alo.get(2).toString() + alo.get(3).toString() + "\n";
Style sty = jtp.addStyle(null, null);
if (i % 3 == 0) {
StyleConstants.setForeground(sty, Color.cyan);
} else if (i % 3 == 1) {
StyleConstants.setForeground(sty, Color.MAGENTA);
} else {
StyleConstants.setForeground(sty, Color.YELLOW);
}
sd.insertString(sd.getLength(), jie, sty);
i++;
// jingwen += jie;
}
this.jtp.setFont(new FontUIResource("黑体", Font.PLAIN, 100));
// this.jtp.setForeground(Color.red);
// this.jtp.setText(jingwen);
this.jtp.setCaretPosition(0);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (s.equals("版权声明")) {
JOptionPane.showMessageDialog(null, "圣经投屏Java+sqlite3极速版:可供青岛市各大教会免费使用,禁止用作商业用途。开发者:丁林弟兄", "版权声明", 1);
} else {
String zhangjie = JOptionPane.showInputDialog("请输入要查询的章节(例如查找3章16节到30节则输入:3 16 30(中间用空格隔开)):");
if (zhangjie == null) {
return;
} else if (zhangjie.equals("")) {
return;
} else {
try {
String[] fengehou = zhangjie.split(" ");
ArrayList<ArrayList<Object>> alalo = this.select(s, fengehou[0], fengehou[1], fengehou[2]);
// String jingwen = "";
int i = 0;
StyledDocument sd = jtp.getStyledDocument();
jtp.setText("");
for (ArrayList<Object> alo : alalo) {
String jie = alo.get(1).toString() + ":" + alo.get(2).toString() + alo.get(3).toString() + "\n";
Style sty = jtp.addStyle(null, null);
if (i % 3 == 0) {
StyleConstants.setForeground(sty, Color.cyan);
} else if (i % 3 == 1) {
StyleConstants.setForeground(sty, Color.MAGENTA);
} else {
StyleConstants.setForeground(sty, Color.YELLOW);
}
sd.insertString(sd.getLength(), jie, sty);
i++;
// jingwen += jie;
}
this.jtp.setFont(new FontUIResource("黑体", Font.PLAIN, 100));
// this.jtp.setForeground(Color.red);
// this.jtp.setText(jingwen);
this.jtp.setCaretPosition(0);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public static ArrayList<ArrayList<Object>> select(String juan, String zhang, String jie_start, String jie_end) {
ArrayList<ArrayList<Object>> alalo = new ArrayList<ArrayList<Object>>();
try {
Class.forName("org.sqlite.JDBC");
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:hb.sqlite3")) {
try (PreparedStatement ps = conn.prepareStatement(
"select juan, zhang, jie, jingwen from t_hb where juan = ? and zhang = ? and jie between ? and ?")) {
ps.setString(1, juan);
ps.setString(2, zhang);
ps.setString(3, jie_start);
ps.setString(4, jie_end);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
ArrayList<Object> alo = new ArrayList<>();
alo.add(rs.getString("juan"));
alo.add(rs.getInt("zhang"));
alo.add(rs.getInt("jie"));
alo.add(rs.getString("jingwen"));
alalo.add(alo);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return alalo;
}
public static ArrayList<ArrayList<Object>> selectpinyin(String pinyin, String zhang, String jie_start,
String jie_end) {
ArrayList<ArrayList<Object>> alalo = new ArrayList<ArrayList<Object>>();
try {
Class.forName("org.sqlite.JDBC");
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:hb.sqlite3")) {
try (PreparedStatement ps = conn.prepareStatement(
"select juan, zhang, jie, jingwen from t_hb where pinyin = ? and zhang = ? and jie between ? and ?")) {
ps.setString(1, pinyin);
ps.setString(2, zhang);
ps.setString(3, jie_start);
ps.setString(4, jie_end);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
ArrayList<Object> alo = new ArrayList<>();
alo.add(rs.getString("juan"));
alo.add(rs.getInt("zhang"));
alo.add(rs.getInt("jie"));
alo.add(rs.getString("jingwen"));
alalo.add(alo);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return alalo;
}
public static ArrayList<ArrayList<Object>> selectsql(String sql) {
ArrayList<ArrayList<Object>> alalo = new ArrayList<ArrayList<Object>>();
try {
Class.forName("org.sqlite.JDBC");
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:hb.sqlite3")) {
try (PreparedStatement ps = conn.prepareStatement(sql)) {
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
ArrayList<Object> alo = new ArrayList<>();
alo.add(rs.getString("juan"));
alo.add(rs.getInt("zhang"));
alo.add(rs.getInt("jie"));
alo.add(rs.getString("jingwen"));
alalo.add(alo);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return alalo;
}
}