Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

3 simple questions...  RSS feed

 
Martin Vietor
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I have 3 simple questions:

1. How can I get the current (Windows XP) screen resolution, so that I can center my JFrame no matter what machine my program runs on?

2. How can I set an icon in said JFrame? I realize how it BASICALLY works - setIconImage(Image). BUT I don't know how to tell the program where my gif is at on the harddrive.

3. How can I turn it into an exe-file that will run on any platform. Or any Windows Computer, if that makes a difference.

Thank you for your help, Martin
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin Vietor wrote:1. How can I get the current (Windows XP) screen resolution, so that I can center my JFrame no matter what machine my program runs on?

Call
With this method you can center a window around any component, but by using null you center it on the screen (without taskbars!)

If you really need the actual screen size take a look at java.awt.Toolkit.
2. How can I set an icon in said JFrame? I realize how it BASICALLY works - setIconImage(Image). BUT I don't know how to tell the program where my gif is at on the harddrive.

Check out javax.swing.ImageIcon as an intermediate class. With this you can load an image from any file (using the String constructor) or any URL, including those from resources.

3. How can I turn it into an exe-file that will run on any platform. Or any Windows Computer, if that makes a difference.

That question has been answered many times already, so if you just do a search you can find many similar threads.
Please note that "exe" is a Windows-only mechanism. Other platforms do offer executables but they are quite different from EXE files. If you want a platform independent "exe" you should check out JAR files.
 
Martin Vietor
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sweeeet, thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!