2012-11-15 2 views
4

이중 화면 모드에서 응용 프로그램을 실행해야합니다. 두 화면 모두에서 독립적 인 창으로 실행하지만 동일한 애플리케이션 모델을 공유하려면 어떻게해야합니까?이중 화면 응용 프로그램

답변

8

내가 잘못 아니에요 경우이 예를 들어, 당신이 도움이 될 수 있습니다. 첫 번째 위치는 각 화면의 프레임입니다.

frame1.setLocation(pointOnFirstScreen); 
frame2.setLocation(pointOnSecondScreen); 

은 극대화 :

frame.setExtendedState(Frame.MAXIMIZED_BOTH); 

작업 예 :

import java.awt.BorderLayout; 
import java.awt.Color; 
import java.awt.Frame; 
import java.awt.GraphicsDevice; 
import java.awt.GraphicsEnvironment; 
import java.awt.Point; 
import javax.swing.BorderFactory; 
import javax.swing.JFrame; 
import javax.swing.JPanel; 
import javax.swing.JTextArea; 
import javax.swing.SwingUtilities; 

public class GuiApp1 { 
protected void twoscreen() { 
    Point p1 = null; 
    Point p2 = null; 
    for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { 
     if (p1 == null) { 
      p1 = gd.getDefaultConfiguration().getBounds().getLocation(); 
     } else if (p2 == null) { 
      p2 = gd.getDefaultConfiguration().getBounds().getLocation(); 
     } 
    } 
    if (p2 == null) { 
     p2 = p1; 
    } 
    createFrameAtLocation(p1); 
    createFrameAtLocation(p2); 
} 

private void createFrameAtLocation(Point p) { 
    final JFrame frame = new JFrame(); 
    frame.setTitle("Test frame on two screens"); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    JPanel panel = new JPanel(new BorderLayout()); 
    final JTextArea textareaA = new JTextArea(24, 80); 
    textareaA.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1)); 
    panel.add(textareaA, BorderLayout.CENTER); 
    frame.setLocation(p); 
    frame.add(panel); 
    frame.pack(); 
    frame.setExtendedState(Frame.MAXIMIZED_BOTH); 
    frame.setVisible(true); 
} 

public static void main(String[] args) { 
    SwingUtilities.invokeLater(new Runnable() { 


     public void run() { 
      new GuiApp1().twoscreen(); 
     } 
    }); 
} 

} 
2

GraphicsDevice API를 살펴볼 필요가 있습니다. 좋은 예가 있습니다. 오라클에서 공급

: 멀티 스크린 환경에서

는, GraphicsConfiguration 오브젝트는 여러 화면에 구성 요소를 렌더링하는 데 사용할 수 있습니다. 다음 코드 샘플은 GraphicsEnvironment의 각 스크린 디바이스 GraphicsConfiguration마다 JFrame 객체를 생성하는 방법을 보여줍니다

GraphicsEnvironment ge = GraphicsEnvironment. 
    getLocalGraphicsEnvironment(); 
    GraphicsDevice[] gs = ge.getScreenDevices(); 
    for (int j = 0; j < gs.length; j++) { 
     GraphicsDevice gd = gs[j]; 
     GraphicsConfiguration[] gc = 
     gd.getConfigurations(); 
     for (int i=0; i < gc.length; i++) { 
     JFrame f = new 
     JFrame(gs[j].getDefaultConfiguration()); 
     Canvas c = new Canvas(gc[i]); 
     Rectangle gcBounds = gc[i].getBounds(); 
     int xoffs = gcBounds.x; 
     int yoffs = gcBounds.y; 
      f.getContentPane().add(c); 
      f.setLocation((i*50)+xoffs, (i*60)+yoffs); 
     f.show(); 
     } 
} 
+0

+1을 제공하는 정보에. 그러나 당신의 답을 혼란스럽게하는 것은,'MSDN '이'Java'에 대한 도움말을 제공하기 시작한 이래로, 당신의 대답에 ** MSDN의 정보원으로 ** 표시 되었기 때문입니다. –

관련 문제