GraphicsEnvironment를 검색하면 각 화면의 경계와 위치를 쉽게 찾을 수 있습니다. 그 후에, 그것은 프레임의 위치를 가지고 노는 것에 불과합니다. 그들은 매우 흥미로운 고려 사항을 가지고 있기 때문에 신중하게 The Use of Multiple JFrames, Good/Bad Practice?을 읽는 고려, 그러나
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class TestMultipleScreens {
private int count = 1;
protected void initUI() {
Point p = null;
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
p = gd.getDefaultConfiguration().getBounds().getLocation();
break;
}
createFrameAtLocation(p);
}
private void createFrameAtLocation(Point p) {
final JFrame frame = new JFrame();
frame.setTitle("Frame-" + count++);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
final JButton button = new JButton("Click me to open new frame on another screen (if you have two screens!)");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GraphicsDevice device = button.getGraphicsConfiguration().getDevice();
Point p = null;
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
if (!device.equals(gd)) {
p = gd.getDefaultConfiguration().getBounds().getLocation();
break;
}
}
createFrameAtLocation(p);
}
});
frame.add(button);
frame.setLocation(p);
frame.pack(); // Sets the size of the unmaximized window
frame.setExtendedState(Frame.MAXIMIZED_BOTH); // switch to maximized window
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new TestMultipleScreens().initUI();
}
});
}
}
:
여기에 작은 데모 예제 코드를 참조하십시오.
1) 앱이란 무엇입니까? 구체적으로? [여러 개의 JFrames 사용, 좋고 나쁜 관행?] (http://stackoverflow.com/a/9554657/418556) 2) ['GraphicsEnvironment'] (http://docs.oracle.com/ javase/7/docs/api/java/awt/GraphicsEnvironment.html) 및 ['GraphicsDevice'] (http://docs.oracle.com/javase/7/docs/api/java/awt/GraphicsDevice.html) 개체 그것은 드러낸다. @mKorbel 팁에 따라 수정되었습니다. +1 –