You give no details but I am guessing that when you scale the object moves as well as scales. You will need to know something about graphics transformations. There are two main approaches:
If you are using Graphics2D (http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Graphics2D.html) you will have access to transformations.
When you resize the window you will want to work out which dimension (width or height) has most effect on the scale and take the others one - this will stop the object expanding too much. Calculate a single scale and apply it equally to X and Y.
You will probably not have the object on the origin. In this case you need to carry out three operations:
- translate the object to the origin
- rescale it
- translate it back to where it was
These operations can be combined into a single matrix.
I cannot be more definite as I do not know the details of your problem but this should give you some pointers.
Try out the examples in:
http://www.java2s.com/Code/Java/2D-Graphics-GUI/Linetransformationrotationshearscale.htm
which should show you some of the effects.