File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes create rectangle? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "create rectangle?" Watch "create rectangle?" New topic

create rectangle?

ed jones

Joined: Oct 01, 2008
Posts: 11
new nooob here / using eclipse

would like to create a standard window, then put a rectangle in it

I am confused as to what header files (imports) I would need

thanks for your time
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46362
Welcome to JavaRanch

There is no such thing as a header file in Java; you only get them in C and C++. Whenever you use a class you have to import it; you might draw on a JPanel inside a JFrame using Graphics so you would have to declare imports for javax.swing.JPanel javax.swing.JFrame and java.awt.Graphics. If you go to the API for the paintComponent method you see it has a link to Graphics, so you know you need to import Graphics; if you click on the link you see which package it is in. If you can't work that out from the link name, you open the Graphics page and at the top left it says "java.awt" then Graphics, then an inheritance tree with java.awt.Graphics underneath java.lang.Object; you can use both of those to work out that its fully-qualified name is "java.awt.Graphics."
If you use a changeBackground call in your drawing, you can use a similar technique to find out how to import Color.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

using eclipse

Pressing CTRL+SHIFT+O will import all necessary classes automatically. Of course, you have to type the name of the class in the source first (JPanel, Graphics...).

[My Blog]
All roads lead to JavaRanch
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46362
I didn't notice he was using Eclipse. I usually write the first few letters of the class name, push ctrl-space, and select the class from the drop-down list which appears. That imports the class automatically.
I agree. Here's the link:
subject: create rectangle?
It's not a secret anymore!