Solved

Two Screens on one Computer (with Java)

Posted on 2000-04-03
9
180 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 36
Eclipse IDE - Cannot copy/paste from console output 8 126
Java Server Faces parameter pass? 6 37
factorial example 4 34
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

919 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

16 Experts available now in Live!

Get 1:1 Help Now