• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

3 simple questions...

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sweeeet, thank you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic