This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "create rectangle?" Watch "create rectangle?" New topic
Author

create rectangle?

ed jones
Greenhorn

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
Sheriff

Joined: Oct 13, 2005
Posts: 38449
    
  23
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é
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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
Sheriff

Joined: Oct 13, 2005
Posts: 38449
    
  23
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: create rectangle?