• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

create rectangle?

 
ed jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...).
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic