java投屏第九次更新

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.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.sql.ResultSetMetaData;
import java.util.Hashtable;
import java.util.Random;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
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.Timer;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

public class Main {

	private static GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
	private static GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices();

	private static String[] s66 = { "创世记", "出埃及记", "利未记", "民数记", "申命记", "约书亚记", "士师记", "路得记", "撒母耳记上", "撒母耳记下", "列王纪上", "列王纪下", "历代志上", "历代志下", "以斯拉记", "尼希米记", "以斯帖记", "约伯记", "诗篇", "箴言", "传道书", "雅歌", "以赛亚书", "耶利米书", "耶利米哀歌", "以西结书", "但以理书", "何西阿书", "约珥书", "阿摩司书", "俄巴底亚书", "约拿书", "弥迦书", "那鸿书", "哈巴谷书", "西番雅书", "哈该书", "撒迦利亚书", "玛拉基书", "马太福音", "马可福音", "路加福音", "约翰福音", "使徒行传", "罗马书", "哥林多前书", "哥林多后书", "加拉太书", "以弗所书", "腓立比书", "歌罗西书", "帖撒罗尼迦前书", "帖撒罗尼迦后书", "提摩太前书", "提摩太后书", "提多书", "腓利门书", "希伯来书", "雅各书", "彼得前书", "彼得后书", "约翰壹书", "约翰贰书", "约翰叁书", "犹大书", "启示录" };
	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[][] sHolyBible = { s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13 };
	private static Color c = new Color(new Random().nextInt(63), new Random().nextInt(63), new Random().nextInt(63));
	private static Color[] cs = { new Color(255, 127, 127), new Color(127, 255, 127), new Color(127, 255, 255), new Color(255, 255, 127) };
	private static Font f20 = new Font("微软雅黑", Font.BOLD, 20);
	private static Font f100 = new Font("微软雅黑", Font.BOLD, 100);
	private static int speed = 0;
	private static JFrame jf = new JFrame("主屏幕");
	private static JPopupMenu jpm = new JPopupMenu();
	private static JMenu[] jms = new JMenu[s0.length];
	private static JTextPane jtp = new JTextPane();
	private static JScrollPane jsp = new JScrollPane(jtp);
	private static JScrollBar jsb = jsp.getVerticalScrollBar();
	private static JLabel jl = new JLabel("彩虹圣经投屏");

	private static Timer t = new Timer(50, new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			int getValue = Main.jsb.getValue();
			System.out.println(e.getSource());
			Main.jsb.setValue(getValue += speed);
		}
	});

	public static void main(String[] args) {

		jf.setBounds(0, 0, 1000, 700);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setExtendedState(JFrame.MAXIMIZED_BOTH);
		// jf.setUndecorated(true);

		jtp.setBackground(Color.BLACK);
		jtp.setFont(f100);
		jtp.setEditable(false);
		jtp.setText("选择章节:鼠标右键\n手动翻页:按住E或D不松手\n自动翻页:1~9(数值越大速度越快)\n停止自动翻页:0\n显示或隐藏当前章节:空格\n退出:ESC");
		jf.add(jsp, BorderLayout.CENTER);
		jtp.addKeyListener(new KeyListener() {
			@Override
			public void keyTyped(KeyEvent e) {
			}

			@Override
			public void keyReleased(KeyEvent e) {
			}

			@Override
			public void keyPressed(KeyEvent e) {
				int i = e.getKeyCode();
				int getValue = Main.jsb.getValue();
				if (i == KeyEvent.VK_E) {
					Main.jsb.setValue(getValue -= 4);
				} else if (i == KeyEvent.VK_D) {
					Main.jsb.setValue(getValue += 4);
				} else if (i == KeyEvent.VK_1 || i == KeyEvent.VK_NUMPAD1) {
					Main.speed = 1;
					t.restart();
					jl.setVisible(false);
				} else if (i == KeyEvent.VK_2 || i == KeyEvent.VK_NUMPAD2) {
					Main.speed = 2;
					t.restart();
					jl.setVisible(false);
				} else if (i == KeyEvent.VK_3 || i == KeyEvent.VK_NUMPAD3) {
					Main.speed = 3;
					t.restart();
					jl.setVisible(false);
				} else if (i == KeyEvent.VK_4 || i == KeyEvent.VK_NUMPAD4) {
					Main.speed = 4;
					t.restart();
					jl.setVisible(false);
				} else if (i == KeyEvent.VK_5 || i == KeyEvent.VK_NUMPAD5) {
					Main.speed = 5;
					t.restart();
					jl.setVisible(false);
				} else if (i == KeyEvent.VK_6 || i == KeyEvent.VK_NUMPAD6) {
					Main.speed = 6;
					t.restart();
					jl.setVisible(false);
				} else if (i == KeyEvent.VK_7 || i == KeyEvent.VK_NUMPAD7) {
					Main.speed = 7;
					t.restart();
					jl.setVisible(false);
				} else if (i == KeyEvent.VK_8 || i == KeyEvent.VK_NUMPAD8) {
					Main.speed = 8;
					t.restart();
					jl.setVisible(false);
				} else if (i == KeyEvent.VK_9 || i == KeyEvent.VK_NUMPAD9) {
					Main.speed = 9;
					t.restart();
					jl.setVisible(false);
				} else if (i == KeyEvent.VK_0 || i == KeyEvent.VK_NUMPAD0) {
					Main.speed = 0;
					Main.t.stop();
					jl.setBackground(c);
					jl.setVisible(true);
				} else if (i == KeyEvent.VK_SPACE) {
					jl.setBackground(c);
					if (jl.isVisible()) {
						jl.setVisible(false);
					} else {
						jl.setVisible(true);
					}
				} else if (i == KeyEvent.VK_UP || i == KeyEvent.VK_DOWN || i == KeyEvent.VK_LEFT || i == KeyEvent.VK_RIGHT || i == KeyEvent.VK_PAGE_UP || i == KeyEvent.VK_PAGE_DOWN) {
					e.consume();// 限定某些按键不可用
				} else if (i == KeyEvent.VK_ESCAPE) {
					int result = JOptionPane.showConfirmDialog(jf, "退出", "退出", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
					if (result == JOptionPane.OK_OPTION) {
						jf.setVisible(false);
						jf.dispose();
						System.exit(0);
						return;
					}
				}
			}
		});

		for (int i = 0; i < s0.length; i++) {
			jms[i] = new JMenu(s0[i]);
			jms[i].setFont(f20);
			if (i > 7) {
				jms[i].setForeground(Color.RED);
			}
			jpm.add(jms[i]);
			JMenuItem[] jmi = new JMenuItem[sHolyBible[i].length];

			for (int j = 0; j < sHolyBible[i].length; j++) {
				jmi[j] = new JMenuItem(sHolyBible[i][j]);
				if (i > 7) {
					jmi[j].setForeground(Color.RED);
				}
				jmi[j].setFont(f20);
				jmi[j].addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent actionEvent) {
						String s = actionEvent.getActionCommand();
						if (!s.equals("")) {
							Main.jspFill(input(s));
						}
						Main.speed = 0;
						Main.t.stop();
					}
				});
				jms[i].add(jmi[j]);
			}
		}

		Main.jtp.addMouseListener(new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {
				if (e.isPopupTrigger()) {
					jpm.show(e.getComponent(), e.getX(), e.getY());
				}
			}

			@Override
			public void mousePressed(MouseEvent e) {
			}

			@Override
			public void mouseExited(MouseEvent e) {
			}

			@Override
			public void mouseEntered(MouseEvent e) {
			}

			@Override
			public void mouseClicked(MouseEvent e) {
			}

		});

		jl.setBackground(c);
		jl.setFont(f100);
		jl.setForeground(Color.WHITE);
		jl.setOpaque(true);
		jf.add(jl, BorderLayout.SOUTH);

		jf.setVisible(true);

	}

	public static String[] input(String FullName) {
		String ChapterSN = "";
		String VerseSN = "";

		while (ChapterSN.equals("")) {
			String s = JOptionPane.showInputDialog("请输入要查询的章数", "1");
			if (s == null || s.equals("") || s.length() > 3 || !s.trim().matches("^[0-9]*$")) {
				continue;
			}
			ChapterSN = s.trim();
		}

		while (VerseSN.equals("")) {
			String s = JOptionPane.showInputDialog("请输入要查询的节数", "1");
			if (s == null || s.equals("") || s.length() > 3 || !s.trim().matches("^[0-9]*$")) {
				continue;
			}
			VerseSN = s.trim();
		}
		String[] slist = { FullName, ChapterSN, VerseSN };
		return slist;
	}

	public static void jspFill(String[] slist) {

		Main.jtp.setText("");
		try {
			Main.jl.setBackground(c);
			Main.jl.setText(slist[0] + "    第" + slist[1] + "章");
			Main.jl.setVisible(true);
			SimpleAttributeSet sas = new SimpleAttributeSet();
			StyleConstants.setLineSpacing(sas, 0.05f);
			StyledDocument sd = jtp.getStyledDocument();
			Style s = jtp.addStyle(null, null);
			sd.setParagraphAttributes(0, sd.getLength(), sas, false);

			Vector<Hashtable<String, Object>> vhso = Main.selectSqlite3(slist);

			StyleConstants.setForeground(s, new Color(255, 255, 255));
			StyleConstants.setFontSize(s, 70);

			for (int i = 0; i < vhso.size(); i++) {
				String jie = vhso.get(i).get("VerseSN").toString();
				String jingwen = vhso.get(i).get("strjw").toString();

				StyleConstants.setForeground(s, cs[i % cs.length]);
				StyleConstants.setFontSize(s, 35);
				sd.insertString(sd.getLength(), jie + "\t", s);
				StyleConstants.setFontSize(s, 70);
				sd.insertString(sd.getLength(), jingwen + "\n", s);

			}
			sd.insertString(sd.getLength(), "\n\n\n\n\n\n\n\n\n\n", s);
		} catch (Exception e) {
			e.printStackTrace();
		}
		Main.jtp.setCaretPosition(0);
		Main.jtp.requestFocusInWindow();

	}

	public static Vector<Hashtable<String, Object>> selectSqlite3(String slist[]) {

		String className = "org.sqlite.JDBC";
		String connectionString = "jdbc:sqlite:HolyBible.sqlite3";
		String sql = "select * from t_HolyBible where FullName = ? and ChapterSN = ? and VerseSN >= ? order by rowid asc";

		Vector<Hashtable<String, Object>> vhso = new Vector<Hashtable<String, Object>>();

		try {
			Class.forName(className);
			try (Connection c = DriverManager.getConnection(connectionString); PreparedStatement ps = c.prepareStatement(sql);) {
				for (int i = 0; i < slist.length; i++) {
					ps.setString(i + 1, slist[i]);
				}
				try (ResultSet rs = ps.executeQuery();) {
					ResultSetMetaData rsmd = rs.getMetaData();
					int gcc = rsmd.getColumnCount();

					while (rs.next()) {
						Hashtable<String, Object> hso = new Hashtable<String, Object>();
						for (int i = 1; i <= gcc; i++) {
							String s = rsmd.getColumnName(i);
							Object o = rs.getObject(s);
							if (o == null) {
								o = "";
							}
							hso.put(s, o);
						}
						vhso.add(hso);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vhso;
	}

	public static Vector<Hashtable<String, Object>> selectAccess(String slist[]) {

		String className = "net.ucanaccess.jdbc.UcanaccessDriver";
		String connectionString = "jdbc:ucanaccess://bible7.dat";
		String user = "admin";
		String password = "gqrjabcde";
		String sql = "select * from bible, bibleid where bible.VolumeSN = bibleid.SN and FullName = ? and ChapterSN = ? and VerseSN >= ? order by bible.id asc";

		Vector<Hashtable<String, Object>> vhso = new Vector<Hashtable<String, Object>>();

		try {
			Class.forName(className);
			try (Connection c = DriverManager.getConnection(connectionString, user, password); PreparedStatement ps = c.prepareStatement(sql);) {
				for (int i = 0; i < slist.length; i++) {
					ps.setString(i + 1, slist[i]);
				}
				try (ResultSet rs = ps.executeQuery();) {
					ResultSetMetaData rsmd = rs.getMetaData();
					int gcc = rsmd.getColumnCount();

					while (rs.next()) {
						Hashtable<String, Object> hso = new Hashtable<String, Object>();
						for (int i = 1; i <= gcc; i++) {
							String s = rsmd.getColumnName(i);
							Object o = rs.getObject(s);
							if (o == null) {
								o = "";
							}
							hso.put(s, o);
						}
						vhso.add(hso);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vhso;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值