The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: Place form in center of screen

Do I need an import statement to get it to work?

An import statement is used by the compiler to find a class definition. It specifies a package that contains classes that are being used in the program.
It is not involved with locating methods for a class.

For your posted code, what class is represented by "this"? Is the code in a method in an instance of a class or in the static main method?

Re: Place form in center of screen

Originally Posted by Blackbird

I also tried this:

//frame.setLocationRelativeTo(null); <- by default, it sits NW, but this sends it SE

If you want any more help, you're going to have to tell us what class you're using for 'frame' and what the environment is. The stuff you've been given works fine on standard Java frames & windows in a normal environment.

Re: Place form in center of screen

Originally Posted by dlorde

If you want any more help, you're going to have to tell us what class you're using for 'frame' and what the environment is. The stuff you've been given works fine on standard Java frames & windows in a normal environment.

I guess I'm new enough that I don't understand the question, so I'll just provide the entire class: