package a;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
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.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
public class Main extends JFrame implements ActionListener, KeyListener, MouseListener {
private static Main m = new Main();
private Font f70 = new Font("微软雅黑", Font.BOLD, 70);
private Font f20 = new Font("微软雅黑", Font.BOLD, 20);
public static void main(String[] args) {
m.setBounds(0, 0, 1000, 700);
m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
m.setExtendedState(JFrame.MAXIMIZED_BOTH);
m.setTitle("彩虹圣经-----E向上滚动,D向下滚动,空格向下滚动,1~9向后滚动,1速度最慢,9速度最快");
m.setUndecorated(true);
m.setVisible(true);
}
public Main() {
UIManager.put("OptionPane.messageFont", this.f20);
UIManager.put("OptionPane.buttonFont", this.f20);
UIManager.put("TextField.font", this.f20);
this.setJMenuBar(this.jmb());
this.add(this.jspCenter());
}
private final JMenuBar jmb = new JMenuBar();
private final JTextPane jtp = new JTextPane();
private final JScrollPane jsp = new JScrollPane(jtp);
public JMenuBar jmb() {
this.jmb.setBackground(Color.BLACK);
JMenu[] jm = new JMenu[Dao.s0.length];
for (int i = 0; i < Dao.s0.length; i++) {
jm[i] = new JMenu(Dao.s0[i]);
jm[i].setFont(this.f20);
jm[i].setForeground(Color.WHITE);
jmb.add(jm[i]);
JMenuItem[] jmi = new JMenuItem[Dao.sShengJing[i].length];
for (int j = 0; j < Dao.sShengJing[i].length; j++) {
jmi[j] = new JMenuItem(Dao.sShengJing[i][j]);
jmi[j].setFont(this.f20);
jmi[j].setBackground(Color.BLACK);
jmi[j].setForeground(Color.WHITE);
jmi[j].addActionListener(this);
jm[i].add(jmi[j]);
// jm[i].addSeparator();
}
}
return jmb;
}
public JScrollPane jspCenter() {
this.jtp.setEditable(false);
this.jtp.setBackground(Color.BLACK);
this.jtp.setFont(this.f70);
this.jtp.addKeyListener(this);
this.jtp.addMouseListener(this);
this.jsp.addMouseListener(this);
return this.jsp;
}
public JPopupMenu jpm() {
final JPopupMenu jpm = new JPopupMenu("圣经目录");
JMenu[] jm = new JMenu[Dao.s0.length];
for (int i = 0; i < jm.length; i++) {
if (i == 0) {
jpm.addSeparator();
JLabel jl = new JLabel("旧约");
jl.setForeground(Color.RED);
jl.setFont(this.f20);
jpm.add(jl);
jpm.addSeparator();
}
if (i == 1 || i == 4 || i == 5 || i == 8 || i == 9 || i == 10 || i == 12) {
jpm.addSeparator();
}
if (i == 8) {
jpm.addSeparator();
JLabel jl = new JLabel("新约");
jl.setForeground(Color.RED);
jl.setFont(this.f20);
jpm.add(jl);
jpm.addSeparator();
}
jm[i] = new JMenu(Dao.s0[i]);
jm[i].setFont(this.f20);
JMenuItem[] jmi = new JMenuItem[Dao.sShengJing[i].length];
for (int j = 0; j < Dao.sShengJing[i].length; j++) {
jmi[j] = new JMenuItem(Dao.sShengJing[i][j]);
jmi[j].setFont(this.f20);
jmi[j].addActionListener(this);
jm[i].add(jmi[j]);
}
jpm.add(jm[i]);
}
return jpm;
}
public void jspFill(String s) {
try {
StyledDocument sd = jtp.getStyledDocument();
Style sty = jtp.addStyle(null, null);
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setLineSpacing(sas, 0.1f);
sd.setParagraphAttributes(0, sd.getLength(), sas, false);
String ChapterSN = "";
String VerseSN = "";
// UIManager.put("OptionPane.messageFont", this.f20);
// UIManager.put("OptionPane.buttonFont", this.f20);
// UIManager.put("TextField.font", this.f20);
while (ChapterSN.equals("")) {
String jopid = JOptionPane.showInputDialog("请输入要查询的章数", "1");
if (jopid == null || jopid.equals("") || jopid.length() > 3 || !jopid.trim().matches("^[0-9]*$")) {
continue;
}
ChapterSN = jopid.trim();
}
while (VerseSN.equals("")) {
String jopid = JOptionPane.showInputDialog("请输入要查询的节数", "1");
if (jopid == null || jopid.equals("") || jopid.length() > 3 || !jopid.trim().matches("^[0-9]*$")) {
continue;
}
VerseSN = jopid.trim();
}
ArrayList<HashMap<String, Object>> alhmss = Dao.select(s, ChapterSN, VerseSN);
this.jtp.setText("");
Color[] c = { new Color(255, 0, 0), new Color(255, 128, 64), new Color(255, 255, 0),
new Color(128, 255, 128), new Color(0, 255, 255), new Color(0, 128, 255), new Color(255, 0, 255),
new Color(255, 128, 255) };
StyleConstants.setForeground(sty, new Color(255, 255, 255));
StyleConstants.setFontSize(sty, 100);
sd.insertString(sd.getLength(), s + "第" + ChapterSN + "章\n", sty);
for (int i = 0; i < alhmss.size(); i++) {
// String zhang = alhmss.get(i).get("ChapterSN").toString();
String jie = alhmss.get(i).get("VerseSN").toString();
String jingwen = alhmss.get(i).get("strjw").toString();
if (i % 8 == 0) {
StyleConstants.setForeground(sty, new Color(255, 64, 64));
} else if (i % 8 == 1) {
StyleConstants.setForeground(sty, new Color(255, 128, 64));
} else if (i % 8 == 2) {
StyleConstants.setForeground(sty, new Color(255, 255, 0));
} else if (i % 8 == 3) {
StyleConstants.setForeground(sty, new Color(128, 255, 128));
} else if (i % 8 == 4) {
StyleConstants.setForeground(sty, new Color(128, 255, 255));
} else if (i % 8 == 5) {
StyleConstants.setForeground(sty, new Color(0, 152, 255));
} else if (i % 8 == 6) {
StyleConstants.setForeground(sty, new Color(255, 0, 255));
} else if (i % 8 == 7) {
StyleConstants.setForeground(sty, new Color(255, 128, 255));
} else {
StyleConstants.setForeground(sty, Color.WHITE);
}
StyleConstants.setFontSize(sty, 40);
sd.insertString(sd.getLength(), jie + "\t", sty);
StyleConstants.setFontSize(sty, 70);
sd.insertString(sd.getLength(), jingwen + "\n", sty);
}
} catch (Exception e) {
e.printStackTrace();
}
this.jtp.setCaretPosition(0);
this.jtp.requestFocusInWindow();
}
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, suoxie, 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("suoxie", rs.getString("suoxie"));
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;
}
@Override
public void mouseClicked(MouseEvent me) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent me) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent me) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent me) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent me) {
if (me.isPopupTrigger()) {
this.jpm().show(me.getComponent(), me.getX(), me.getY());
}
}
@Override
public void keyPressed(KeyEvent ke) {
int i = ke.getKeyCode();
char c = ke.getKeyChar();
System.out.println(i);
System.out.println(c);
JScrollBar jsb = jsp.getVerticalScrollBar();
int j = jsb.getValue();
if (c == 'e' || c == 'E') {
jsb.setValue(j -= 5);
} else if (c == 'd' || c == 'D' || i == 32) {
jsb.setValue(j += 5);
} else if (c == '1') {
jsb.setValue(j += 1);
} else if (c == '2') {
jsb.setValue(j += 2);
} else if (c == '3') {
jsb.setValue(j += 3);
} else if (c == '4') {
jsb.setValue(j += 4);
} else if (c == '5') {
jsb.setValue(j += 5);
} else if (c == '6') {
jsb.setValue(j += 6);
} else if (c == '7') {
jsb.setValue(j += 7);
} else if (c == '8') {
jsb.setValue(j += 8);
} else if (c == '9') {
jsb.setValue(j += 9);
} else if (i == 27) {
int result = JOptionPane.showConfirmDialog(m, "退出", "退出", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
m.setVisible(false);
m.dispose();
System.exit(0);
return;
}
}
}
@Override
public void keyReleased(KeyEvent ke) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent ke) {
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent ae) {
String s = ae.getActionCommand();
System.out.println(s);
if (s.equals("退出")) {
int result = JOptionPane.showConfirmDialog(m, "退出", "退出", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
m.setVisible(false);
m.dispose();
System.exit(0);
return;
}
return;
}
if (!s.equals("")) {
this.jspFill(s);
}
}
}
彩虹圣经投屏
最新推荐文章于 2024-08-10 10:46:00 发布