This site requires JavaScript, please enable it in your browser!
Greenfoot back
joel
joel wrote ...

2013/8/29

what is the use for Import command at the beginning of the source code?

joel joel

2013/8/29

#
why is this command "import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)" places in every Scenarios source code? and when someone want to insert a color to the background they use "import java.awt.Color;" after placing the first command why is that? need help!!!
SPower SPower

2013/8/29

#
Well, the imports allow you to use classes you haven't written yourself. You can think of it like those classes are in a 'folder', but in Java, it's called a package. By doing this:
1
import greenfoot.*;
you import all the classes associated with Greenfoot. This includes Actor, World, GreenfootImage, etc. And doing this:
1
import java.awt.Color;
allows you to use the Color class. For more info about packages, check out this course I made about it: http://www.greenfoot.org/scenarios/5709
davmac davmac

2013/8/29

#
Putting it another way: java.awt.Color is a class which you might want to use. However, you want to refer to it simply as "Color" so you don't need to type "java.awt.Color" each time. The import statement tells the compiler that you want to use "Color" to refer to the "java.awt.Color" class. The other one you mention - "import greenfoot.*;" - is similar. It lets you use just "Actor" to refer to greenfoot.Actor and "World" to refer to greenfoot.World and so on.
joel joel

2013/8/30

#
Thank you both of you!!!! it is helpful!!!
You need to login to post a reply.