Skip to main content
gamedev.net
🔒 Locked

[java] Finding Desktop Resolution

Started by Scylexan Apr 2, 2007 at 7:28 PM 4 replies 950+ views
Original Post
Scylexan
Scylexan
Hopefully you Java fellows can help me with a little issue I'm having. I've used Java quite a bit for console only never really touched Java GUI very much. I am working on a class project which requires me to throw together a simple GUI interface. I'm finding it pretty easy to put together; however, I'm having trouble with one particular issue. I'm looking for a way to get ahold of the desktop's current resolution so that I could set the GUI application's location to certain spot depending on the resolution. Is there a way within the Java API to obtain this type of information or do I have to use a separate API? Thanks. EDIT: Oh and if it helps any, I have to use 1.5 can't use 1.6 so any newer tricks I probably won't be able to do.
STUMP - http://scyanidegaming.com
Scylexan
Scylexan
Oh wow, thank you so much. This is exactly what I was looking for.

You know, when I saw the Toolkit I was thinking to myself, "Now, how come I've never heard of Toolkit before?" A quick gander at the java's api listing showed me that it is listed under AWT. This explains why I have never heard of it. The only professor that I have learned all of my java from refuses to use AWT and claims that it should have been taken out of the framework years ago. So, he never teaches anthing from AWT. Glad to know it actually does still have a use. It always did confuse me on why Sun would leave something "so useless" in the framework since Swing is around.
STUMP - http://scyanidegaming.com
Glass_Knife
Glass_Knife
Quote:
Original post by Scylexan
You know, when I saw the Toolkit I was thinking to myself, "Now, how come I've never heard of Toolkit before?"


The hardest part about learning Java, in my opinon, is finding the Class that does what you want. How in the world would you know to use the Toolkit? Some stuff in java comes from experience. Honestly, I couldn't remember what class had the screen size, but because I remembered it was there somewhere, I found it in a minute.

Here are some other things that I find handy that would be hard to stumble across.

// get image from inside jar fileURL myurl = this.getClass().getResource("/myimage.gif");Toolkit tk = Toolkit.getDefaultToolkit();Image img = tk.getImage(myurl);// The Arrays class is coolint[] array;Arrays.sort( array );// Collections class is also coolList list = Collections.synchronizedList(new ArrayList());      ...synchronized(list) {    Iterator i = list.iterator(); // Must be in synchronized block    while (i.hasNext())        foo(i.next());}// and my personal favorite...ByteBuffer buf = ByteBuffer.wrap( new byte[1024] );byte b = buf.get();// get five bytesbyte[] temp = new byte[5];buf.get(temp);int i = buf.getInt();double d = buf.getDouble();ByteBuffer buf2 = buf.order( ByteOrder.LITTLE_ENDIAN );


CaptainJester
CaptainJester
Quote:
Original post by Scylexan
The only professor that I have learned all of my java from refuses to use AWT and claims that it should have been taken out of the framework years ago. So, he never teaches anthing from AWT.


This professor sounds like an idiot. While there is little use for the visual components in AWT, there is still important classes in there. Also, all Swing components are derived from AWT components. Plus there are several subpackages under AWT. To downplay the importance of the remaining classes just smacks of ignorance.

While you can still use Toolkit, some of its functionality has been reinvented in newer more flexible classes. GraphicsEnvironment, GraphicsDevice, DisplayMode.

You can use GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode();

I realize that is more longwinded, but if you are looking for other functionality as well, you can look in those classes. Escpecially for fullscreen.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Son of Cain
Son of Cain
I agree with the AWT matter, your teacher seem to have a big misunderstanding about it. Capn' said it all, though, no need to step on this subject again.

Capn's "alternative" for Toolkit is what you should pursue to use - that's the way the API is going, since these classes conceptions. Future releases of the SDK will hopefully provide better support for FSEM, but as of now, support is pretty poor.. So I suggest you take a look at LWJGL for that. For more reference on this, see the other thread posted recently about FSEM.
a.k.a javabeats at yahoo.ca

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.