import java.awt.AWTException;
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.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
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 {
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices();
int graphicsDevicesLength = graphicsDevices.length;
String[] s = { "创世记", "出埃及记", "利未记", "民数记", "申命记", "约书亚记", "士师记", "路得记", "撒母耳记上", "撒母耳记下", "列王纪上", "列王纪下", "历代志上",
"历代志下", "以斯拉记", "尼希米记", "以斯帖记", "约伯记", "诗篇", "箴言", "传道书", "雅歌", "以赛亚书", "耶利米书", "耶利米哀歌", "以西结书", "但以理书",
"何西阿书", "约珥书", "阿摩司书", "俄巴底亚书", "约拿书", "弥迦书", "那鸿书", "哈巴谷书", "西番雅书", "哈该书", "撒迦利亚书", "玛拉基书", "马太福音", "马可福音",
"路加福音", "约翰福音", "使徒行传", "罗马书", "哥林多前书", "哥林多后书", "加拉太书", "以弗所书", "腓立比书", "歌罗西书", "帖撒罗尼迦前书", "帖撒罗尼迦后书",
"提摩太前书", "提摩太后书", "提多书", "腓利门书", "希伯来书", "雅各书", "彼得前书", "彼得后书", "约翰壹书", "约翰贰书", "约翰叁书", "犹大书", "启示录" };
String[] s0 = { "律法书", "王国前历史书", "王国时历史书", "被掳后历史书", "诗歌·智慧书", "大先知书", "王国时小先知书", "被掳后小先知书", "四福音", "教会历史", "保罗书信",
"其他使徒书信", "对约翰的启示" };
String[] s1 = { "创世记", "出埃及记", "利未记", "民数记", "申命记" };
String[] s2 = { "约书亚记", "士师记", "路得记" };
String[] s3 = { "撒母耳记上", "撒母耳记下", "列王纪上", "列王纪下", "历代志上", "历代志下" };
String[] s4 = { "以斯拉记", "尼希米记", "以斯帖记" };
String[] s5 = { "约伯记", "诗篇", "箴言", "传道书", "雅歌" };
String[] s6 = { "以赛亚书", "耶利米书", "耶利米哀歌", "以西结书", "但以理书" };
String[] s7 = { "何西阿书", "约珥书", "阿摩司书", "俄巴底亚书", "约拿书", "弥迦书", "那鸿书", "哈巴谷书", "西番雅书" };
String[] s8 = { "哈该书", "撒迦利亚书", "玛拉基书" };
String[] s9 = { "马太福音", "马可福音", "路加福音", "约翰福音" };
String[] s10 = { "使徒行传" };
String[] s11 = { "罗马书", "哥林多前书", "哥林多后书", "加拉太书", "以弗所书", "腓立比书", "歌罗西书", "帖撒罗尼迦前书", "帖撒罗尼迦后书", "提摩太前书", "提摩太后书",
"提多书", "腓利门书" };
String[] s12 = { "希伯来书", "雅各书", "彼得前书", "彼得后书", "约翰壹书", "约翰贰书", "约翰叁书", "犹大书" };
String[] s13 = { "启示录" };
String[] sExit = { "退出" };
String[][] sShengJing = { s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13 };
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 };
JLabel jLabel = new JLabel("彩虹圣经投屏");
JTextPane jTextPane = new JTextPane();
JScrollPane jScrollPane = new JScrollPane(jTextPane);
JScrollBar jScrollBar = jScrollPane.getVerticalScrollBar();
JPopupMenu jPopupMenu = new JPopupMenu();
JMenu[] jMenus = new JMenu[s0.length];
int speed = 0;
static Main main = new Main();
JFrame jFrame = new JFrame("彩虹圣经投屏-大屏幕");
static Timer timer2 = null;
Random random = new Random();
Color[] c4t = { new Color(200 + random.nextInt(55), 100 + random.nextInt(27), 100 + random.nextInt(27)),
new Color(100 + random.nextInt(27), 200 + random.nextInt(55), 200 + random.nextInt(27)),
new Color(100 + random.nextInt(27), 200 + random.nextInt(55), 200 + random.nextInt(55)),
new Color(200 + random.nextInt(55), 200 + random.nextInt(55), 100 + random.nextInt(27)) };
public Main() {
this.jLabel.setOpaque(true);
this.jLabel.setBackground(new Color(random.nextInt(100), random.nextInt(100), random.nextInt(100)));
this.jLabel.setForeground(Color.WHITE);
this.jLabel.setFont(new Font("微软雅黑", Font.BOLD + Font.ITALIC, 100));
this.add(jLabel, BorderLayout.SOUTH);
this.jTextPane.setText(
"鼠标右键选择经文的卷、章、节,\nD是向下翻页(按两下速度加快,按三下更快,以此类推),\nE是向上翻页(按两下速度加快,按三下更快,以此类推),\n空格是停止自动翻页,\nESC是退出。");
this.jTextPane.setEditable(false);
this.jTextPane.setBackground(Color.BLACK);
this.jTextPane.setFont(new Font("微软雅黑", Font.BOLD, 70));
this.add(this.jScrollPane, BorderLayout.CENTER);
this.jTextPane.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
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 (jFrame.isVisible()) {
jFrame.setVisible(false);
return;
}
if (graphicsDevicesLength > 0) {
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;
}
}
}
});
for (int i = 0; i < s0.length; i++) {
jMenus[i] = new JMenu(s0[i]);
jMenus[i].setFont(new Font("微软雅黑", Font.BOLD, 20));
if (i > 7) {
jMenus[i].setForeground(Color.RED);
}
jPopupMenu.add(jMenus[i]);
JMenuItem[] jMenuItems = new JMenuItem[sShengJing[i].length];
for (int j = 0; j < sShengJing[i].length; j++) {
jMenuItems[j] = new JMenuItem(sShengJing[i][j]);
if (i > 7) {
jMenuItems[j].setForeground(Color.RED);
}
jMenuItems[j].setFont(new Font("微软雅黑", Font.BOLD, 20));
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);
}
});
jMenus[i].add(jMenuItems[j]);
}
}
jTextPane.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
jPopupMenu.show(e.getComponent(), e.getX(), e.getY());
System.out.println(jScrollPane.getBounds());
System.out.println(jTextPane.getBounds());
System.out.println(jTextPane.getLocationOnScreen());
}
}
public void mousePressed(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
});
this.setBounds(0, 0, 1900, 1050);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setTitle("彩虹圣经投屏-主屏幕");
// this.setUndecorated(true);
}
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 -= 5));
if (i < 20) {
jLabel.setVisible(false);
timerDisOrVis.stop();
timerDisOrVis = null;
}
System.out.println(i);
}
});
timerDisOrVis.restart();
}
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)));
// Timer timerNorth = new Timer(5000, new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// Timer timer2 = new Timer(50, new ActionListener() {
// public void actionPerformed(ActionEvent e2) {
// int i = jLabel.getFont().getSize();
// i -= 5;
// jLabel.setFont(new Font("微软雅黑", Font.ITALIC, i));
// if (i < 1) {
// jLabel.setVisible(false); // 设置标签不可见
// ((Timer) e2.getSource()).stop(); // 停止计时器
// }
// }
// });
// ((Timer) e.getSource()).stop();
// timer2.restart();
// }
// });
// timerNorth.restart();
jLabel.setText(FullName + " 第" + ChapterSN + "章");
jLabel.setVisible(true);
StyledDocument sd = jTextPane.getStyledDocument();
Style sty = jTextPane.addStyle(null, null);
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setLineSpacing(sas, 0.1f);
sd.setParagraphAttributes(0, sd.getLength(), sas, false);
Vector<Hashtable<String, Object>> vhso = this.selectSqlite3(FullName, ChapterSN, VerseSN);
jTextPane.setText("");
StyleConstants.setForeground(sty, new Color(255, 255, 255));
StyleConstants.setFontSize(sty, 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(sty, this.c4[i % this.c4.length]);
StyleConstants.setFontSize(sty, 35);
sd.insertString(sd.getLength(), jie + "\t", sty);
StyleConstants.setFontSize(sty, 70);
sd.insertString(sd.getLength(), jingwen + "\n", sty);
}
sd.insertString(sd.getLength(), "\n\n\n\n\n\n\n\n\n\n", sty);
} 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;
}
}
java圣经投屏每次都变色
最新推荐文章于 2024-08-29 18:44:48 发布