7 Replies - 1283 Views - Last Post: 26 July 2010 - 05:30 PM Rate Topic: -----

#1 fallenreaper  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 240
  • Joined: 19-June 10

using awt Toolkit and getting Screen size

Posted 26 July 2010 - 12:01 PM

So i wanted to get the screensize for a monitor as each is different. This is what i was doing

Toolkit Screen = new Toolkit();  //<-- says "Cannot instantiate the type Toolkit"
Dimension xy = Screen.getScreenSize();
int xVal = xy.width;
int yval = xy.height;




So i was getting an error as shown above and i dont know how to get around it. Wha-do-i-do?

--Fallen
Is This A Good Question/Topic? 0
  • +

Replies To: using awt Toolkit and getting Screen size

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10333
  • View blog
  • Posts: 38,237
  • Joined: 27-December 08

Re: using awt Toolkit and getting Screen size

Posted 26 July 2010 - 12:02 PM

You need to use the static method in the Toolkit class getDefaultToolkit(), which will return a reference to a Toolkit object for you to use.
Was This Post Helpful? 1
  • +
  • -

#3 fallenreaper  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 240
  • Joined: 19-June 10

Re: using awt Toolkit and getting Screen size

Posted 26 July 2010 - 12:09 PM

so would i have to make a method? the code for it in the api is
public static Toolkit getDefaultToolkit()



and i was unsure how to put it so i could get the default toolkit.

should i just have something like
Toolkit Screen = getDefaultToolkit(); //Maybe?


Was This Post Helpful? 0
  • +
  • -

#4 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1933
  • View blog
  • Posts: 4,015
  • Joined: 11-December 07

Re: using awt Toolkit and getting Screen size

Posted 26 July 2010 - 12:12 PM

Toolkit screen = Toolkit.getDefaultToolkit();

Was This Post Helpful? 1
  • +
  • -

#5 fallenreaper  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 240
  • Joined: 19-June 10

Re: using awt Toolkit and getting Screen size

Posted 26 July 2010 - 12:14 PM

you both get +1 in my book. Thanks guys. When i code, i dont usually call a class and its incorperating method like that. Helped me out! :)

wewt
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10333
  • View blog
  • Posts: 38,237
  • Joined: 27-December 08

Re: using awt Toolkit and getting Screen size

Posted 26 July 2010 - 12:15 PM

Glad we could help! :)
Was This Post Helpful? 0
  • +
  • -

#7 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1933
  • View blog
  • Posts: 4,015
  • Joined: 11-December 07

Re: using awt Toolkit and getting Screen size

Posted 26 July 2010 - 12:20 PM

No problem. There are loads of static methods like that around the API. Check out the Arrays and Collections classes for some examples of what I mean!
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8323
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: using awt Toolkit and getting Screen size

Posted 26 July 2010 - 05:30 PM

View Postfallenreaper, on 26 July 2010 - 01:14 PM, said:

you both get +1 in my book. Thanks guys. When i code, i dont usually call a class and its incorperating method like that. Helped me out! :)

wewt

It is because Toolkit is a singleton (there is only one instance of the object Toolkit). Actually you do not want to create 500 different Toolkits only one will do the job. Thus the static method that returns the only one Toolkit for the whole application
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1