package a;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Robot;
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.awt.image.BufferedImage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Hashtable;
import java.util.Random;
import java.util.Vector;
import javax.swing.ImageIcon;
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.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.Timer;
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 GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
private static GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices();
private static int graphicsDevicesLength = graphicsDevices.length;
private static String[] s = { "创世记", "出埃及记", "利未记", "民数记", "申命记", "约书亚记", "士师记", "路得记", "撒母耳记上", "撒母耳记下", "列王纪上",
"列王纪下", "历代志上", "历代志下", "以斯拉记", "尼希米记", "以斯帖记", "约伯记", "诗篇", "箴言", "传道书", "雅歌", "以赛亚书", "耶利米书", "耶利米哀歌",
"以西结书", "但以理书", "何西阿书", "约珥书", "阿摩司书", "俄巴底亚书", "约拿书", "弥迦书", "那鸿书", "哈巴谷书", "西番雅书", "哈该书", "撒迦利亚书", "玛拉基书",
"马太福音", "马可福音", "路加福音", "约翰福音", "使徒行传", "罗马书", "哥林多前书", "哥林多后书", "加拉太书", "以弗所书", "腓立比书", "歌罗西书", "帖撒罗尼迦前书",
"帖撒罗尼迦后书", "提摩太前书", "提摩太后书", "提多书", "腓利门书", "希伯来书", "雅各书", "彼得前书", "彼得后书", "约翰壹书", "约翰贰书", "约翰叁书", "犹大书",
"启示录" };
private static String[] s0 = { "律法书", "王国前历史书", "王国时历史书", "被掳后历史书", "诗歌·智慧书", "大先知书", "王国时小先知书", "被掳后小先知书", "四福音",
"教会历史", "保罗书信", "其他使徒书信", "对约翰的启示" };
private static String[] s1 = { "创世记", "出埃及记", "利未记", "民数记", "申命记" };
private static String[] s2 = { "约书亚记", "士师记", "路得记" };
private static String[] s3 = { "撒母耳记上", "撒母耳记下", "列王纪上", "列王纪下", "历代志上", "历代志下" };
private static String[] s4 = { "以斯拉记", "尼希米记", "以斯帖记" };
private static String[] s5 = { "约伯记", "诗篇", "箴言", "传道书", "雅歌" };
private static String[] s6 = { "以赛亚书", "耶利米书", "耶利米哀歌", "以西结书", "但以理书" };
private static String[] s7 = { "何西阿书", "约珥书", "阿摩司书", "俄巴底亚书", "约拿书", "弥迦书", "那鸿书", "哈巴谷书", "西番雅书" };
private static String[] s8 = { "哈该书", "撒迦利亚书", "玛拉基书" };
private static String[] s9 = { "马太福音", "马可福音", "路加福音", "约翰福音" };
private static String[] s10 = { "使徒行传" };
private static String[] s11 = { "罗马书", "哥林多前书", "哥林多后书", "加拉太书", "以弗所书", "腓立比书", "歌罗西书", "帖撒罗尼迦前书", "帖撒罗尼迦后书",
"提摩太前书", "提摩太后书", "提多书", "腓利门书" };
private static String[] s12 = { "希伯来书", "雅各书", "彼得前书", "彼得后书", "约翰壹书", "约翰贰书", "约翰叁书", "犹大书" };
private static String[] s13 = { "启示录" };
private static String[] sExit = { "退出" };
private static String[][] sHollyBibile = { s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13 };
private static Color[] c4 = { new Color(255, 127, 127), new Color(127, 255, 127), new Color(127, 255, 255),
new Color(255, 255, 127) };
Color[] c7 = { Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.CYAN, Color.magenta, Color.PINK };
private static JLabel jLabel = new JLabel("彩虹圣经投屏");
private static JTextPane jTextPane = new JTextPane();
private static StyledDocument styledDocument = jTextPane.getStyledDocument();
private static Style style = jTextPane.addStyle(null, null);
private static JScrollPane jScrollPane = new JScrollPane(jTextPane);
private static JScrollBar jScrollBar = jScrollPane.getVerticalScrollBar();
private static JMenuBar jMenuBar = new JMenuBar();
private static JPopupMenu jPopupMenu = new JPopupMenu();
private static JMenu[] jMenusjMenuBar = new JMenu[s0.length];
private static JMenu[] jMenusjPopupMenu = new JMenu[s0.length];
private static int speed = 0;
private static Main main = new Main();
private static JFrame jFrame = new JFrame("主屏幕");
private static Timer timer2 = null;
private Random random = new Random();
public Main() {
this.setBounds(0, 0, 1900, 1000);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
Main.jLabel.setOpaque(true);
Main.jLabel
.setBackground(new Color(this.random.nextInt(100), this.random.nextInt(100), this.random.nextInt(100)));
Main.jLabel.setForeground(Color.WHITE);
Main.jLabel.setFont(new Font("黑体", Font.BOLD + Font.ITALIC, 100));
this.add(Main.jLabel, BorderLayout.SOUTH);
Main.jTextPane.setText(
"鼠标右键选择经文的卷、章、节,\nD是向下翻页(按两下速度加快,按三下更快,以此类推),\nE是向上翻页(按两下速度加快,按三下更快,以此类推),\n空格是停止自动翻页,\nESC是退出。");
Main.jTextPane.setEditable(false);
Main.jTextPane.setBackground(Color.BLACK);
Main.jTextPane.setFont(new Font("黑体", Font.BOLD, 70));
this.add(Main.jScrollPane, BorderLayout.CENTER);
Main.jTextPane.addKeyListener(this);
for (int i = 0; i < Main.s0.length; i++) {
Main.jMenusjMenuBar[i] = new JMenu(Main.s0[i]);
Main.jMenusjPopupMenu[i] = new JMenu(Main.s0[i]);
Main.jMenusjMenuBar[i].setFont(new Font("微软雅黑", Font.BOLD, 20));
Main.jMenusjPopupMenu[i].setFont(new Font("微软雅黑", Font.BOLD, 20));
if (i > 7) {
Main.jMenusjMenuBar[i].setForeground(Color.RED);
Main.jMenusjPopupMenu[i].setForeground(Color.RED);
}
Main.jMenuBar.add(Main.jMenusjMenuBar[i]);
Main.jPopupMenu.add(Main.jMenusjPopupMenu[i]);
JMenuItem[] jMenuItemsjMenuBar = new JMenuItem[Main.sHollyBibile[i].length];
JMenuItem[] jMenuItemsjPopupMenu = new JMenuItem[Main.sHollyBibile[i].length];
for (int j = 0; j < Main.sHollyBibile[i].length; j++) {
jMenuItemsjMenuBar[j] = new JMenuItem(Main.sHollyBibile[i][j]);
jMenuItemsjPopupMenu[j] = new JMenuItem(Main.sHollyBibile[i][j]);
if (i > 7) {
jMenuItemsjMenuBar[j].setForeground(Color.RED);
jMenuItemsjPopupMenu[j].setForeground(Color.RED);
}
jMenuItemsjMenuBar[j].setFont(new Font("微软雅黑", Font.BOLD, 20));
jMenuItemsjPopupMenu[j].setFont(new Font("微软雅黑", Font.BOLD, 20));
jMenuItemsjMenuBar[j].addActionListener(this);
jMenuItemsjPopupMenu[j].addActionListener(this);
// jMenuItems[j].addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
//
// String s = e.getActionCommand();
// if (!s.equals("")) {
// String[] slist = input(s);
// jspFill(jTextPane, slist[0], slist[1], slist[2]);
// }
// speed = 0;
// timer(jScrollBar, speed);
// }
// });
Main.jMenusjPopupMenu[i].add(jMenuItemsjMenuBar[j]);
Main.jMenusjMenuBar[i].add(jMenuItemsjPopupMenu[j]);
}
}
this.setJMenuBar(Main.jMenuBar);
Main.jTextPane.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
Main.jPopupMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
public void mousePressed(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
});
}
public static void main(String[] args) {
main.setVisible(true);
}
Timer timer = null;
public void timer(JScrollBar jScrollBar, int speed) {
if (this.timer != null) {
this.timer.stop();
}
this.timer = new Timer(50, new ActionListener() {
public void actionPerformed(ActionEvent e) {
int getValue = jScrollBar.getValue();
jScrollBar.setValue(getValue += speed);
}
});
this.timer.restart();
}
public String[] input(String FullName) {
String ChapterSN = "";
String VerseSN = "";
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();
}
String[] slist = { FullName, ChapterSN, VerseSN };
return slist;
}
public void jspFill(JTextPane jTextPane, String FullName, String ChapterSN, String VerseSN) {
try {
jLabel.setFont(new Font("微软雅黑", Font.BOLD + Font.ITALIC, 100));
this.jLabel.setBackground(new Color(random.nextInt(100), random.nextInt(100), random.nextInt(100)));
jLabel.setText(FullName + " 第" + ChapterSN + "章");
jLabel.setVisible(true);
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setLineSpacing(sas, 0.1f);
styledDocument.setParagraphAttributes(0, styledDocument.getLength(), sas, false);
Vector<Hashtable<String, Object>> vhso = this.selectSqlite3(FullName, ChapterSN, VerseSN);
jTextPane.setText("");
StyleConstants.setForeground(style, new Color(255, 255, 255));
StyleConstants.setFontSize(style, 70);
// sd.insertString(sd.getLength(), FullName + "第" + ChapterSN +
// "章\n", sty);
for (int i = 0; i < vhso.size(); i++) {
// String zhang = alhmss.get(i).get("ChapterSN").toString();
String jie = vhso.get(i).get("VerseSN").toString();
String jingwen = vhso.get(i).get("strjw").toString();
StyleConstants.setForeground(style, this.c4[i % this.c4.length]);
StyleConstants.setFontSize(style, 35);
styledDocument.insertString(styledDocument.getLength(), jie + "\t", style);
StyleConstants.setFontSize(style, 70);
styledDocument.insertString(styledDocument.getLength(), jingwen + "\n", style);
}
styledDocument.insertString(styledDocument.getLength(), "\n\n\n\n\n\n\n\n\n\n", style);
} catch (Exception e) {
e.printStackTrace();
}
jTextPane.setCaretPosition(0);
jTextPane.requestFocusInWindow();
}
public Vector<Hashtable<String, Object>> selectSqlite3(String FullName, String ChapterSN, String VerseSN) {
Vector<Hashtable<String, Object>> vhso = new Vector<Hashtable<String, Object>>();
try {
Class.forName("org.sqlite.JDBC");
try (Connection connection = DriverManager.getConnection("jdbc:sqlite:shengjing.sqlite3");
PreparedStatement preparedStatement = connection.prepareStatement(
"select * from t_shengjing where FullName = ? and ChapterSN = ? and VerseSN >= ? order by rowid asc");) {
preparedStatement.setString(1, FullName);
preparedStatement.setString(2, ChapterSN);
preparedStatement.setString(3, VerseSN);
try (ResultSet resultSet = preparedStatement.executeQuery();) {
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int getColumnCount = resultSetMetaData.getColumnCount();
while (resultSet.next()) {
Hashtable<String, Object> hso = new Hashtable<String, Object>();
for (int i = 1; i <= getColumnCount; i++) {
String getColumnName = resultSetMetaData.getColumnName(i);
Object sCellValue = resultSet.getObject(getColumnName);
if (sCellValue == null) {
sCellValue = "";
}
hso.put(getColumnName, sCellValue);
}
vhso.add(hso);
}
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return vhso;
}
public Vector<Hashtable<String, Object>> selectAccess(String FullName, String ChapterSN, String VerseSN) {
Vector<Hashtable<String, Object>> vhso = new Vector<Hashtable<String, Object>>();
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
try (Connection connection = DriverManager.getConnection("jdbc:ucanaccess://bible7.dat", "admin",
"gqrjabcde");
PreparedStatement preparedStatement = connection.prepareStatement(
"select * from bible, bibleid where bible.VolumeSN = bibleid.SN and FullName = ? and ChapterSN = ? and VerseSN >= ? order by bible.id asc");) {
preparedStatement.setString(1, FullName);
preparedStatement.setString(2, ChapterSN);
preparedStatement.setString(3, VerseSN);
try (ResultSet resultSet = preparedStatement.executeQuery();) {
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int getColumnCount = resultSetMetaData.getColumnCount();
while (resultSet.next()) {
Hashtable<String, Object> hso = new Hashtable<String, Object>();
for (int i = 1; i <= getColumnCount; i++) {
String getColumnName = resultSetMetaData.getColumnName(i);
Object sCellValue = resultSet.getObject(getColumnName);
if (sCellValue == null) {
sCellValue = "";
}
hso.put(getColumnName, sCellValue);
}
vhso.add(hso);
}
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return vhso;
}
Timer timerDisOrVis = null;
public void disOrVis() {
if (timerDisOrVis != null) {
timerDisOrVis.stop();
}
timerDisOrVis = new Timer(100, new ActionListener() {
int i = jLabel.getFont().getSize();
public void actionPerformed(ActionEvent e) {
jLabel.setFont(new Font("微软雅黑", Font.BOLD + Font.ITALIC, i -= 15));
if (i < 20) {
jLabel.setVisible(false);
timerDisOrVis.stop();
timerDisOrVis = null;
}
System.out.println(i);
}
});
timerDisOrVis.restart();
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent e) {
int i = e.getKeyCode();
int getValue = jScrollBar.getValue();
if (i == KeyEvent.VK_E) {
if (speed > -9) {
speed--;
}
if (jLabel.isVisible() || speed != 0) {
// jLabel.setVisible(false);
disOrVis();
} else {
jLabel.setFont(new Font("微软雅黑", Font.BOLD + Font.ITALIC, 100));
jLabel.setBackground(new Color(random.nextInt(100), random.nextInt(100), random.nextInt(100)));
jLabel.setVisible(true);
}
timer(jScrollBar, speed);
} else if (i == KeyEvent.VK_D) {
if (speed < 9) {
speed++;
}
if (jLabel.isVisible() || speed != 0) {
// jLabel.setVisible(false);
disOrVis();
} else {
jLabel.setFont(new Font("微软雅黑", Font.BOLD + Font.ITALIC, 100));
jLabel.setBackground(new Color(random.nextInt(100), random.nextInt(100), random.nextInt(100)));
jLabel.setVisible(true);
}
timer(jScrollBar, speed);
} else if (i == KeyEvent.VK_SPACE) {
speed = 0;
timer(jScrollBar, 0);
if (jLabel.isVisible()) {
jLabel.setVisible(false);
} else {
jLabel.setFont(new Font("微软雅黑", Font.BOLD + Font.ITALIC, 100));
jLabel.setBackground(new Color(random.nextInt(100), random.nextInt(100), random.nextInt(100)));
jLabel.setVisible(true);
}
} else if (i == KeyEvent.VK_F5) {
if (timer2 != null) {
timer2.stop();
}
if (graphicsDevicesLength > 1) {
if (jFrame.isVisible()) {
jFrame.setVisible(false);
return;
}
}
if (graphicsDevicesLength > 1) {
try {
jFrame.setBounds(0, 0, 1600, 1000);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel jPanel = new JPanel();
Robot robot = new Robot();
ImageIcon imageIcon = new ImageIcon();
// Image image = imageIcon.getImage();
// image = image.getScaledInstance(jTextPane.getSize().width, jTextPane.getSize().height,
// Image.SCALE_DEFAULT);
JLabel jLabel2 = new JLabel();
timer2 = new Timer(50, new ActionListener() {
public void actionPerformed(ActionEvent e) {
// BufferedImage bufferedImage2 = robot.createScreenCapture(rectangle);
// ImageIcon imageIcon = new ImageIcon(bufferedImage2
// .getScaledInstance(rectangle.width, rectangle.height, Image.SCALE_FAST));
// Rectangle rectangle2 = new Rectangle(main.getLocationOnScreen().x,
// main.getLocationOnScreen().y, main.getSize().width,
// main.getSize().height + jLabel.getHeight());
// BufferedImage bufferedImage2 = robot.createScreenCapture(rectangle2);
Rectangle rectangle = new Rectangle(main.getLocationOnScreen().x,
main.getLocationOnScreen().y + main.getInsets().top, main.getSize().width,
main.getSize().height - main.getInsets().top);
BufferedImage bufferedImage = robot.createScreenCapture(rectangle);
imageIcon.setImage(bufferedImage.getScaledInstance(jPanel.getWidth(), jPanel.getHeight(),
Image.SCALE_DEFAULT));
paint(jPanel.createImage(getWidth(), getHeight()).getGraphics());
jLabel2.setIcon(imageIcon);
jLabel2.repaint();
main.requestFocus();
main.jTextPane.requestFocusInWindow();
}
});
timer2.restart();
jPanel.add(jLabel2, BorderLayout.CENTER);
jFrame.add(jPanel);
jFrame.setVisible(true);
} catch (Exception exception) {
exception.printStackTrace();
}
}
} else if (i == KeyEvent.VK_UP || i == KeyEvent.VK_DOWN || i == KeyEvent.VK_LEFT || i == KeyEvent.VK_RIGHT) {
e.consume();
} else if (i == KeyEvent.VK_ESCAPE) {
int result = JOptionPane.showConfirmDialog(null, "退出", "退出", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
setVisible(false);
dispose();
System.exit(0);
return;
}
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if (!s.equals("")) {
String[] slist = input(s);
jspFill(jTextPane, slist[0], slist[1], slist[2]);
}
speed = 0;
timer(jScrollBar, speed);
}
}