I'm a complete rookie with NetBeans, and that's unfortunate because this summer our Instructor wants us to use NetBeans throughout the entire course.

I'd just like to know... how do I add existing files to a project? I've tried right-clicking the project folders to see if there was some kind of add command. There were none, but then I simply tried creating a package to hold the projects and still no add project command. Not even in the File option or anywhere else.

It's not that I'm lazy and don't feel like finding the existing project/package in the source files, but I find it somewhat inconvenient to not be able to easily implement classes into one package or project in a Development Kit like NetBeans.

Is there any way to do what I'm asking, or am I SOL and must simply create a shortcut to the sourcefile folder where the projects and packages are located?

Recommended Answers

All 15 Replies

You want to add a library, or just source files to edit? If it is a library (.jar) or something, there should be an add external library option. But I think you want to add source files, you can just drag-drop or do it directly in the filesystem.

You want to add a library, or just source files to edit? If it is a library (.jar) or something, there should be an add external library option. But I think you want to add source files, you can just drag-drop or do it directly in the filesystem.

I created a package in my project manager and then tried opening a file to examine.

From there I tried clicking and holding the tab that had the class information and when i try to drop the file into the package it shows the NOT circle symbol. When I release the mouse, obviously nothing happens.

I found out that you can control the directory that the package is created in so I guess I'll try the second option and simply add the files directly to the package.

Ok that idea worked, but now I'm getting an issue with compiling. It says it cant find the files even through they're in the same package.

I've even tried adding the "package <packagename>" statement at the very top of the java files, but to no avail. What am I doing wrong?

Yeah, you will definitely need the package declarations. It is hard to tell what is going on though, so you have a specific error you can paste? (try google too).

Here's the code that I wanted to add to the project. It's in zip format to make things easier--

Pretty much worked straight away for me. All I did was create a new project, delete the default package and copy in your package instead. DoodleBug.java was missing a package statement, but that was all...

You still having issues?

commented: Thanks a million for your help! +1

Pretty much worked straight away for me. All I did was create a new project, delete the default package and copy in your package instead. DoodleBug.java was missing a package statement, but that was all...

You still having issues?

Can't yet because I'm copying NetBeans IDE to my iPod so I can take it with me wherever I go.

Once that's done I'll give it a shot.

That's severely odd... it worked now. Thanks a million!

Another question--

How do I run a Java Applet using NetBeans?

Just run it like any other java file, from either the right-click menu or the Run menu. Netbeans will start it in the Applet Viewer.

Just run it like any other java file, from either the right-click menu or the Run menu. Netbeans will start it in the Applet Viewer.

I, mistakingly, found out how to do this via GUIFormExamples... to an extent.

In order to run as an Applet must I keep doing this and simply overload the init method for JApplet/Applet or is there something going on in the background that I don't know about?

I don't follow what you mean. If the class extends Applet or JApplet, it runs in the Applet viewer when you run or debug the file.

commented: Hah! I figured it out. I kept trying to create an Applit from a new Project, and not an existing package! I'm such a nub! +1

When I open a new Project, how should I open it? Which option controls Applet-driven classes?

I tried your advice but whenever I make, oh say, a Java Application and decide to make the class extend Applet/JApplet, I get a <No class file> error when I attempt to run, even with the init method overridden and my class extends JApplet and I have no main method implementation.

What am I doing wrong? How should I be loading my projects when creating a new one?

I'm using NetBeans 6.1.

I'm such a nub... finally figured it out. Thank you Ezz

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.