multimonitorexample2.java

来自「一个用java开发界面的程序集(jfc核心编程)」· Java 代码 · 共 38 行

JAVA
38
字号
package JFCBook.Chapter3.jdk13;

import java.awt.*;
import javax.swing.*;

public class MultiMonitorExample2 {

	public static void main(String[] args) {
		GraphicsEnvironment ge = GraphicsEnvironment.
									getLocalGraphicsEnvironment();
		GraphicsDevice[] gd = ge.getScreenDevices();
		System.out.println("There are " + gd.length + " screen device(s)");

		ImageIcon image = new ImageIcon(
				MultiMonitorExample2.class.getResource("images/lem.jpg"));

		for (int i = 0; i < gd.length; i++) {
			GraphicsConfiguration[] gcs = gd[i].getConfigurations();
			System.out.println("Device " + i + " has " + gcs.length +
													" configuration(s)");

			for (int j = 0; j < gcs.length; j++) {
				System.out.println("\tConfig " + j + " bounds: " +
													gcs[j].getBounds());
			}
			JFrame f = new JFrame("Screen " + i);
			JLabel l = new JLabel(image);
			f.getContentPane().add(l);
			f.pack();

			GraphicsConfiguration gc = gd[i].getDefaultConfiguration();
			Rectangle pt = gc.getBounds();
			f.setLocation(pt.x + 100, pt.y + 100);
			f.setVisible(true);
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?