package info.junius.test;
import java.awt.Desktop;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class DesktopScreens {
public static void main(String[] args) {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
if (!env.isHeadless()) {
GraphicsDevice[] devices = env.getScreenDevices();
int p = 0;
for (GraphicsDevice gd : devices) {
System.out.println(gd);
System.out.println(gd.getIDstring());
System.out.println(gd.getDisplayMode().getWidth() + "/" + gd.getDisplayMode().getHeight());
placeFramesOn(gd, p);
++p;
}
}
}
private static void placeFramesOn(GraphicsDevice device, int p) {
GraphicsConfiguration[] gc = device.getConfigurations();
for (int i = 0; i < gc.length; ++i) {
System.out.println(gc[i]);
JFrame frame = new JFrame(device.getDefaultConfiguration());
JLabel label = new JLabel(device.toString());
Rectangle gcBounds = gc[i].getBounds();
int xoffs = gcBounds.x;
int yoffs = gcBounds.y;
frame.getContentPane().add(label);
frame.setLocation(i * 100 + xoffs, i*150 + yoffs);
frame.setSize(200, 80);
frame.setVisible(true);
// die Idee: das Programmfenster geht da auf, wo der Frame den Focus hat
// Problem: es funktioniert nicht
// Anderer Ansatz: nutze die Process API to run shell script that does the job
frame.requestFocusInWindow();
if (p == 0) {
try {
Desktop.getDesktop().browse(new URI("http://example.com"));
Thread.sleep(5000);
} catch (IOException | URISyntaxException | InterruptedException e) {
e.printStackTrace();
}
}
if (p == 1) {
try {
Desktop.getDesktop().edit(new File("test.txt"));
Thread.sleep(5000);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
}
}