🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8799

Re: How do i get Pixeels per inch from the system ??

#8799
From: John McGrath TeamB
Date: Tue, 27 Feb 2001 10:40
64 lines
3822 bytes
On Mon, 26 Feb 2001 11:42:39 +0100, Asger Joergensen wrote:

> int ScreenRess = Toolkit.getScreenResolution();

Sorry, sometimes I (and others) will refer to a non-static method by 
prefixing it with the class name, but you cannot call it that way.

Since getScreenResolution() is a non-static (i.e. instance) method, you 
must have an instance of Toolkit in order to call it.  So how do you 
get an instance of Toolkit?  Heck, what is a Toolkit?

The Toolkit is the object that AWT uses to interface to the native 
windowing system.  This object knows about things like creating native 
AWT components, fonts, cursors, etc.  And it knows about the screen.

As far as I know, it is not possible to write a Java program today that 
really makes use of more than one Toolkit.  There is just one, and it 
is associated with the screen on which you run your program.  You can 
get this single instance of Toolkit using Toolkit.getDefaultToolkit().  
This method ought to work for you now without any problems.  So you 
could write:

  int screenRes = Toolkit.getDefaultToolkit().getScreenResolution();

However technology changes, and support is being added for handling 
multiple displays, so in the future the code you write today may run in 
an environment where there are multiple Toolkits.  So if you get the 
screen resolution from the default Toolkit, but your dialog is being 
shown on a display associated with a different Toolkit, this could 
cause problems in the future.

Fortunately, the Component class has a getToolkit() method, which will 
presumably return the Toolkit associated with the display on which the 
Component is being shown.  So if you are writing code within a 
component, you probably should try:

  int screenRes = getToolkit().getScreenResolution();

However, I am not sure if this will work before the component is 
"realized", i.e. shown on the screen.  If that is the case, you could 
defer your calculations until the component is displayed, but that 
could turn out to be more complicated than you want it to be.

All of this is up in the air -- the next version of Java should have 
support for multiple displays, as well as "headless" Java (i.e. no 
display).  I always try to write things so that they will work in 
future environments, but it does not make sense to spend a lot of time 
on it.

What I would recommend is to try using getToolkit(), and if that works 
for you, that's great.  However, if it returns a null pointer, just use 
getDefaultToolkit().  That will definitely work for you.

I suppose this may be a little more information that you really needed, 
but I guess that is better than not enough.  Good luck.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID: <MPG.15054911dbdda3c9989fce@forums.borland.com>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!193.190.198.17!newsfeeds.belnet.be!news.belnet.be!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!not-for-mail
References: <3A98DE52.40C56298@get2net.dk> <MPG.15038c1045ad5045989fc1@forums.borland.com> <3A9A331E.DBB09B6F@get2net.dk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,dde485c2b9c97ae9
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-02-27 02:48:34 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!193.190.198.17!newsfeeds.belnet.be!news.belnet.be!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!not-for-mail
From: John McGrath  [TeamB] <ng-b@JPMcGrath.net>
Newsgroups: borland.public.jbuilder.java.language
Subject: Re: How do i get Pixeels per inch from the system ??
Date: Tue, 27 Feb 2001 05:40:16 -0500
Organization: Another Netscape Collabra Server User
Lines: 64
Message-ID: <MPG.15054911dbdda3c9989fce@forums.borland.com>
References: <3A98DE52.40C56298@get2net.dk> <MPG.15038c1045ad5045989fc1@forums.borland.com> <3A9A331E.DBB09B6F@get2net.dk>
NNTP-Posting-Host: dslcv1-60.fast.net
X-Newsreader: MicroPlanet Gravity v2.30