Solved

Two Screens on one Computer (with Java)

Posted on 2000-04-03
9
182 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
configure dependency in POM for new database 3 25
servlet web applications   metadata-complete="true" or false 3 40
throw exception 21 44
jboss wildfly 10.1 10 88
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

770 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