Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JFrame questions

Status
Not open for further replies.

progbass8

Programmer
Dec 11, 2003
5
US
Ok, ive looked through the java documentation and have a few questions.

1)How can i destroy a JFrame without ending an application? I noticed that it has a .destroy() method, but it contains no code. Would .dispose() and .setVisible(false) work (or the other way around)?

2)Is it possible to set the Background of a JFrame to an image such as a gif, jpg or bmp?

3)How can i place an image(gif,jpg,bmp) at a certain point in my JFrame and size it?

4)Finally, how can i position and size the JFrame to my liking? Is it possible to have the window automatically maximized upon its creation? Can the minimize option be disabled?
 
1.) A window closing is not the end of a program, unless you set the default close operation... It will, however, kill that windows thread.
look for:
Code:
 void setDefaultCloseOperation(int operation)
and:
Code:
 static int EXIT_ON_CLOSE
in the javadoc.

2.) yes. I suppose you want to know how now too? The background is painted in a final method, which means that you can't change it... You can however use AWT's methods to paint a rectangle over the component's background... or... use
Code:
setBackground(Color)[/color] which is inherited from class java.awt.Component.

3.) abstract  boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) in the graphics class... note, that this is to be called in a paint() method

4.) setSize(), setLocation(), ect.  check the javadoc.  Basically, set size is width heith and Location is the location on the screen... there is are also function to maximize/minimize with setExtendedState.
 
Thanks for the response jstreich.

1) so i would use setDefaultCloseOperation(EXIT_ON_CLOSE)?
2) if i had a derived class of JFrame could this be changed?
3) pretty obvious i guess.
4) what i was looking for is probably this setExtendedState().

-Thanks again!
 
I think you may have misunderstood my first question about destroying a JFrame. What i am looking for is a way to destroy the JFrame w/in the code....not upon an action by the user.

3) what exactly is the ImageObserver? Ive seen things like this that could be set to null if they werent desired, but what is its purpose and is it required for what im looking to do?
 
1.) How about hide() -- It makes it invisable... Or a Destroy... then set an ActionListener or some such to activate it at a given time...
2.) Err, changed how? change the default background or make it so that it cannot be changed?
3.) There should be a version that doesn't require an ImageObserver, but as always check the JavaDoc first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top