Solved

Two Screens on one Computer (with Java)

Posted on 2000-04-03
9
179 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
  • 4
  • 3
  • 2
9 Comments
 
LVL 2

Expert Comment

by:stalefish
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 2

Author Comment

by:MadMike
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 19

Expert Comment

by:Jim Cakalic
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
;)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now