双屏没有测试

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.Toolkit;
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.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

public class Main {
	static GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	static GraphicsDevice[] gds = ge.getScreenDevices();

	public static void main(String[] args) {
		JF jf = new JF("主屏幕", 80);
		jf.setBounds(0, 0, 985, 700);
		jf.setVisible(true);
		System.out.println("显示器个数:" + gds.length);
		if (gds.length > 1) {
			System.out.println("显示器个数:" + gds.length);
			JF jf2 = new JF("副屏幕", 80);
			jf2.setBounds(0, 0, 1000, 1000);

			jf2.ChapterSN = jf.ChapterSN;
			jf2.VerseSN = jf.VerseSN;
			jf2.jsp.setVerticalScrollBar(jf.jsp.getVerticalScrollBar());
			jf2.setLocation(gds[1].getDefaultConfiguration().getBounds().getLocation());
			jf2.setVisible(true);
		}

	}

}

class JF extends JFrame implements ActionListener, KeyListener, MouseListener {

	public JTextPane jtp = new JTextPane();
	public JScrollPane jsp = new JScrollPane(jtp);

	public JF(String title, int size) {
		this.setBounds(0, 0, 1000, 700);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setExtendedState(JFrame.MAXIMIZED_BOTH);
		this.setTitle(title);

		this.jtp.addKeyListener(this);
		this.jtp.addMouseListener(this);
		this.jtp.setEditable(false);
		this.jtp.setFont(new Font("微软雅黑", Font.BOLD, size));
		this.jtp.setBackground(Color.BLACK);

		this.add(this.jsp, BorderLayout.CENTER);
		this.jpm();
		this.jtp.setCaretPosition(0);
		this.jtp.requestFocusInWindow();
	}

	private JPopupMenu jpm = new JPopupMenu();

	public void jpm() {
		JMenu[] jm = new JMenu[14];
		for (int i = 0; i < 14; i++) {
			if (i == 0) {
				JLabel jl = new JLabel("旧约");
				jl.setForeground(Color.RED);
				jl.setFont(new Font("微软雅黑", Font.BOLD, 30));
				this.jpm.add(jl);
				this.jpm.addSeparator();
			}

			if (i == 1 || i == 4 || i == 5 || i == 8 || i == 9 || i == 10 || i == 12) {
				this.jpm.addSeparator();
			}
			if (i == 8) {
				JLabel jl = new JLabel("新约");
				jl.setForeground(Color.RED);
				jl.setFont(new Font("微软雅黑", Font.BOLD, 30));
				this.jpm.add(jl);
				this.jpm.addSeparator();
			}
			jm[i] = new JMenu(S.s0[i]);
			jm[i].setFont(new Font("微软雅黑", Font.BOLD, 20));

			JMenuItem[] jmi = new JMenuItem[S.sShengJing[i].length];
			for (int j = 0; j < S.sShengJing[i].length; j++) {
				jmi[j] = new JMenuItem(S.sShengJing[i][j]);
				jmi[j].setFont(new Font("微软雅黑", Font.BOLD, 20));
				jmi[j].addActionListener(this);
				jm[i].add(jmi[j]);
			}
			this.jpm.add(jm[i]);
		}
	}

	public StyledDocument sd = jtp.getStyledDocument();
	public Style sty = jtp.addStyle(null, null);
	public String ChapterSN = "";
	public String VerseSN = "";

	public void jspFill(String s) {
		try {
			SimpleAttributeSet sas = new SimpleAttributeSet();
			StyleConstants.setLineSpacing(sas, 0.0f);
			sd.setParagraphAttributes(0, sd.getLength(), sas, false);

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

			ArrayList<HashMap<String, String>> alhmss = Dao.select(s, ChapterSN, VerseSN);
			this.jtp.setText("");

			for (int i = 0; i < alhmss.size(); i++) {
				String zhang = alhmss.get(i).get("zhang");
				String jie = alhmss.get(i).get("jie");
				String jingwen = alhmss.get(i).get("jingwen");
				String zhangjiejingwen = "【" + s + "】" + zhang + ":" + jie + jingwen + "\n";

				StyleConstants.setForeground(sty, C.c[i % 8]);

				sd.insertString(sd.getLength(), zhangjiejingwen, sty);

				this.jtp.setCaretPosition(0);
				this.jtp.requestFocusInWindow();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public void keyPressed(KeyEvent e) {
		char c = e.getKeyChar();
		int i = e.getKeyCode();
		System.out.println(c);
		System.out.println(i);
		JScrollBar jsb = jsp.getVerticalScrollBar();

		int j = jsb.getValue();

		if (c == 'd' || c == 'D' || i == 32) {
			jsb.setValue(j + 5);

		} else if (c == 'e' || c == 'E') {
			jsb.setValue(j - 5);

		} else if (c == 'k' || c == 'K' || i == 10) {
			this.jpm.show(this.jtp, 400, 100);
		}
	}

	@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 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) {
		if (e.isPopupTrigger()) {
			this.jpm.show(e.getComponent(), e.getX(), e.getY());
		}

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String s = e.getActionCommand();
		if (s.equals("退出投屏或按ESC键退出投屏")) {
			int result = JOptionPane.showConfirmDialog(this, "退出投屏", "退出投屏", JOptionPane.YES_NO_OPTION,
					JOptionPane.QUESTION_MESSAGE);
			if (result == JOptionPane.OK_OPTION) {
				this.setVisible(false);
				this.dispose();
				System.exit(0);
				return;
			} else {
				return;
			}
		}
		jspFill(s);

	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值