package g;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
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.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
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[] hb = { "创世记", "出埃及记", "利未记", "民数记", "申命记", "约书亚记", "士师记", "路得记", "撒母耳记上", "撒母耳记下", "列王纪上", "列王纪下", "历代志上", "历代志下", "以斯拉记", "尼希米记", "以斯帖记", "约伯记", "诗篇", "箴言", "传道书", "雅歌", "以赛亚书", "耶利米书", "耶利米哀歌", "以西结书", "但以理书", "何西阿书", "约珥书", "阿摩司书",
"俄巴底亚书", "约拿书", "弥迦书", "那鸿书", "哈巴谷书", "西番雅书", "哈该书", "撒迦利亚书", "玛拉基书", "马太福音", "马可福音", "路加福音", "约翰福音", "使徒行传", "罗马书", "哥林多前书", "哥林多后书", "加拉太书", "以弗所书", "腓立比书", "歌罗西书", "帖撒罗尼迦前书", "帖撒罗尼迦后书", "提摩太前书", "提摩太后书", "提多书", "腓利门书", "希伯来书", "雅各书",
"彼得前书", "彼得后书", "约翰一书", "约翰二书", "约翰三书", "犹大书", "启示录" };
JButton[] jb = new JButton[66];
JPanel jp = new JPanel(new GridLayout(11, 6));
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);
public Main() {
for (int i = 0; i < hb.length; i++) {
jb[i] = new JButton(hb[i]);
jp.add(jb[i]);
jb[i].addActionListener(this);
if (i < 5) {
jb[i].setBackground(new Color(255, 191, 191));
} else if (i < 17) {
jb[i].setBackground(new Color(191, 255, 191));
} else if (i < 22) {
jb[i].setBackground(new Color(127, 191, 255));
} else if (i < 39) {
jb[i].setBackground(new Color(255, 255, 0));
} else if (i < 43) {
jb[i].setBackground(new Color(255, 191, 191));
} else if (i < 44) {
jb[i].setBackground(new Color(191, 255, 191));
} else if (i < 65) {
jb[i].setBackground(new Color(127, 192, 255));
} else if (i < 66) {
jb[i].setBackground(new Color(255, 255, 0));
} else {
jb[i].setBackground(Color.WHITE);
}
}
jtp.setEditable(false);
jtp.setBackground(Color.BLACK);
jtp.setFont(fuir);
jtp.setText("请选择菜单中的卷,再输入要查询的章节数字,中间用空格隔开.例如查询创世记第1章第1节则先选择律法书菜单里面的创世记,接下来在弹出的提示框中输入1 1(注:1 1之间中间用空格隔开)\n");
this.add(jp, BorderLayout.WEST);
this.add(jsp);
this.setSize(1000, 700);
this.setTitle("圣经投屏");
}
public static void main(String[] args) {
Main m = new Main();
m.setExtendedState(MAXIMIZED_BOTH);
m.setDefaultCloseOperation(EXIT_ON_CLOSE);
m.setVisible(true);
}
@Override
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);
}
}
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, zhang, jie, jingwen from t_hb where juan = ? 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("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;
}
}
java grid卡片按钮圣经
最新推荐文章于 2024-09-03 17:22:28 发布