Reputation: 5
I'm trying to import a file (DrawingPanel for those interested) from one directory (let's call it "Projects") into several Java files in different subdirectories. Is this a possibility without copying the file into each subdirectory individually?
Upvotes: 0
Views: 777
Reputation: 5566
You don't need to copy any files. Just need to specify a correct import. For example, your project structure is:
com
|_projects
|_DrawingPanel.java
|_subdir1
|_Panel1.java
|_Panel2.java
As you can see, DrawingPanel
is located in the parent package.
To import it to the Panel1
and Panel2
classes you need to add import com.projects.DrawingPanel;
to them:
Panel1.java
package com.projects.subdir1;
import com.projects.DrawingPanel;
public class Panel1 {
}
Panel2.java
package com.projects.subdir2;
import com.projects.DrawingPanel;
public class Panel2 {
}
You can read more about packages and imports here.
Upvotes: 1