传统写法彩虹圣经

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.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.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);
	private static JPopupMenu jpm = new JPopupMenu("圣经目录");
	private final JTextPane jtp = new JTextPane();
	private final JScrollPane jsp = new JScrollPane(jtp);

	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);

		JMenuBar jmb = new JMenuBar();

		jmb.setBackground(Color.BLACK);
		JMenu[] jmJMB = new JMenu[Dao.s0.length];
		for (int i = 0; i < Dao.s0.length; i++) {
			jmJMB[i] = new JMenu(Dao.s0[i]);
			jmJMB[i].setFont(this.f20);
			jmJMB[i].setForeground(Dao.c[i % 8]);
			jmb.add(jmJMB[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(Dao.c[j % 8]);
				jmi[j].addActionListener(this);
				jmJMB[i].add(jmi[j]);
				jmJMB[i].addSeparator();
			}
		}
		this.setJMenuBar(jmb);

		jpm.setBackground(Color.BLACK);
		JMenu[] jmJPM = new JMenu[Dao.s0.length];
		for (int i = 0; i < Dao.s0.length; i++) {
			if (i == 0) {
				jpm.addSeparator();
				JLabel jl = new JLabel("旧约");
				jl.setForeground(Color.WHITE);
				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.WHITE);
				jl.setFont(this.f20);
				jpm.add(jl);
				jpm.addSeparator();
			}
			jmJPM[i] = new JMenu(Dao.s0[i]);
			jmJPM[i].setBackground(Color.BLACK);
			jmJPM[i].setForeground(Dao.c[i % 8]);
			jmJPM[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].setBackground(Color.BLACK);
				jmi[j].setForeground(Dao.c[j % 8]);
				jmi[j].setFont(this.f20);
				jmi[j].addActionListener(this);
				jmJPM[i].add(jmi[j]);
			}
			jpm.add(jmJPM[i]);
		}

		this.jtp.setEditable(false);
		this.jtp.setBackground(Color.BLACK);
		this.jtp.setFont(this.f70);
		this.jtp.setText("选择菜单或鼠标右键打开菜单选择卷名,在弹出的框输入章数按回车,再输入开始小结后按回车,即可显示经文。按大键盘1,2,3,4,5,6,7,8,9,0向下翻页,1速度最慢,2速度更快,以此类推,0速度最快,D和空格也是向下翻页,E向上翻页,ESC退出");
		this.jtp.addKeyListener(this);
		this.jtp.addMouseListener(this);
		this.jsp.addMouseListener(this);

		this.add(jsp);
	}

	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(String FullName, String ChapterSN, String VerseSN) {
		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);

			ArrayList<HashMap<String, Object>> alhmss = Dao.selectSqlite3(FullName, 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(), FullName + "第" + 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 void mouseClicked(MouseEvent me) {
	}

	public void mouseEntered(MouseEvent me) {
	}

	public void mouseExited(MouseEvent me) {
	}

	public void mousePressed(MouseEvent me) {
	}

	@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();
		System.out.println(i);

		JScrollBar jsb = jsp.getVerticalScrollBar();

		int j = jsb.getValue();

		if (i == KeyEvent.VK_E || i == KeyEvent.VK_BACK_SPACE) {
			jsb.setValue(j -= 5);
		} else if (i == KeyEvent.VK_D || i == KeyEvent.VK_SPACE) {
			jsb.setValue(j += 5);
		} else if (i == KeyEvent.VK_1) {
			jsb.setValue(j += 1);
		} else if (i == KeyEvent.VK_2) {
			jsb.setValue(j += 2);
		} else if (i == KeyEvent.VK_3) {
			jsb.setValue(j += 3);
		} else if (i == KeyEvent.VK_4) {
			jsb.setValue(j += 4);
		} else if (i == KeyEvent.VK_5) {
			jsb.setValue(j += 5);
		} else if (i == KeyEvent.VK_6) {
			jsb.setValue(j += 6);
		} else if (i == KeyEvent.VK_7) {
			jsb.setValue(j += 7);
		} else if (i == KeyEvent.VK_8) {
			jsb.setValue(j += 8);
		} else if (i == KeyEvent.VK_9) {
			jsb.setValue(j += 9);
		} else if (i == KeyEvent.VK_0) {
			jsb.setValue(j += 10);
		} else if (i == KeyEvent.VK_ESCAPE) {
			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 e) {
		String s = e.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("")) {
			String[] slist = this.input(s);
			this.jspFill(slist[0], slist[1], slist[2]);
		}
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值