Solved

Two Screens on one Computer (with Java)

Posted on 2000-04-03
9
184 Views
Last Modified: 2012-05-04
I'm looking for a library that gives me the possibility to access two Screens on a Windows (9x or NT) Machine. I'd need to create one Frame on one screen and the other on the other screen.

Okay, I know that technically it would be possible to do something with JNI and that the solution won't be pure Java. Please, what I'm looking for a library that does this or some lines of code I can copy and compile. I don't know anything of JNI or of the Win-API to implement this myself. I can even envision to *pay* someone to get this working. E-Mail me if you think you are able to do this. We'll discuss then further details.
0
Comment
Question by:MadMike
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 2

Expert Comment

by:stalefish
ID: 2680663
Are you trying to write two "screens" to show two frames on two seperate monitors? Or are you just attempting to display two Frames on one montor? If this is the first option, then you first need a dual monitor graphics card. When you have this installed, the dual monitor just acts like an extension to your primary monitor. That means that if your screen resolution both monitors is 800x600, then the first monitor has the bound <0,0>X<800,600> and the second has <800, 0>x<1600, 600>.

If the answer is the latter, then this is a very simple task to display to frames simultaneously. This shows how easy:

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

public class Test{
  public static void main(String[] args) {            

  JFrame frame1 = new JFrame("Frame 1");
  JFrame frame2 = new JFrame("Frame 2");
  frame1.setBounds(0, 0, 200, 200);
  frame2.setBounds(200,0,200, 200);
  frame1.show();
  frame2.show();
            
  }//Close Main

}

If I'm still not understanding what you need, please describe it with a little more detail and I'd be happy to help.
0
 
LVL 2

Expert Comment

by:stalefish
ID: 2680667
By the way, I'm always open for small contract jobs... I don't think you'll need to pay someone for this though.
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2680908
The JDK 1.3 includes 2D API changes for multiple monitor support. If you can use JDK 1.3 (now in release candidate 2), this looks like your solution. Here is a description of the new feature from the JDK release notes:

You can now render on multiple screens by creating Frame, JFrame, Window, or JWindow objects with the GraphicsConfiguration of the target GraphicsDevice.
The new Frame constructor, Frame(GraphicsConfiguration), enables creation of a Frame object on a different screen device.

The new Window constructor, Window(Window, GraphicsConfiguration), constructs a new invisible window with the specified window as its owner and the GraphicsConfiguration of a screen device.

The new GraphicsConfiguration getBounds method returns the bounds of the GraphicsConfiguration in device coordinates. If you have a virtual device, then the device coordinates returned from getBounds are virtual device coordinates.

Finally, the new Component getGraphicsConfiguration method returns the GraphicsConfiguration with which the Component was created.

In a virtual device configuration consisting of more than one physical screen device, the GraphicsConfiguration objects' coordinates are relative to the virtual coordinate system. For this reason, virtual coordinates must be used when calling the setLocation method of a Frame or Window. Similarly, calling getBounds of a GraphicsConfiguration in a virtual device environment returns virtual device coordinates.

The following code sample creates a JFrame object for each GraphicsConfiguration on each screen device in the GraphicsEnvironment. It offsets the coordinates of the intended location of the JFrame with the bounds of the GraphicsConfiguration to ensure that the JFrame appears on the screen of the specified GraphicsConfiguration.

        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.setSize(300, 150);
                    f.setLocation((i*50)+xoffs, (i*60)+yoffs);
                    f.show();
          }
      }
      
If the bounds of a GraphicsConfiguration is not taken into account in this sample, a JFrame would appear at location (i*50, i*60) on the primary screen, which might be different than the screen of the specified GraphicsConfiguration.
For more information on how the Java 2D API supports multi-screen environments, see Rendering in a Multi-Screen Environment in the Programmer's Guide to the Java 2D API.

Best regards,
Jim Cakalic
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 2

Author Comment

by:MadMike
ID: 2681346
Good job, jim_cakalic. You'll get the points.

Just a last thing I'd really like to know before I close this Question as answered. Has anyone actually *used* two screens ('monitors' if you like that better, althought then you can confuse it with the term from the synchronization mechanism... ;) or was this "just" a research job you did?
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2681435
Sorry, no, I haven't used this capability. I've only been using JDK 1.3 for a month or so and haven't had the resources (time or hardware) to investigate this new functionality.

Jim Cakalic
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2681440
Because this was "just a research job", I'll understand if you choose to reduce the points for the answer :)

Jim
0
 
LVL 2

Author Comment

by:MadMike
ID: 2681846
no.. i'll give you all 400 points, promised is promised. But I'll give a 'D' Grade afterwards...

   *evil-grin*   ;)
0
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 400 total points
ID: 2682289
Ouch -- there goes my GPA! Guess I won't make site valedictorian this year. Oh well ... maybe I still have a chance to win Mister Universe if I start taking those steroids today.
0
 
LVL 2

Author Comment

by:MadMike
ID: 2685536
;)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question