Greetings!
I'm using NetBeans 6.5 and the textbook Java How To Program 7th edition by Deitel & Deitel. I created two new projects: PanelFrame.java (p. 590) and PanelDemo.java (p. 591). PanelFrame.java doesn't contain method main.
The book says to compile both classes at once -
javac.PanelFrame.java PanelDemo.java
How do I accomplish the same thing with NetBeans?
When I create a new project in NetBeans I do the following:
File, New Project, Category: Java,
Projects: Java Application, Project Name: PanelFrame,
Create Main Class: panelframe.PanelFrame ( Create Main Class - checked),
Set as Main Project (checked)
Maybe I'm not doing something right when I create a new project.
Thanks in advance!
Mark
Compiling an Application with Multiple Classes
Started by neophyte, Jun 28 2009 06:23 PM
4 replies to this topic
#1
Posted 28 June 2009 - 06:23 PM
|
|
|
#2
Posted 29 June 2009 - 10:02 AM
You can create classes in java that contain fields, properties, and methods but when you compile the compiler is looking for a class called "Main." It looks for this because the "Main" is where the code is actually ran. Inside of Main you can create instances of objects, use methods, and have output to the user. Does that make sense?
for example
Feel free to ask more questions.
for example
import java.util.*;
public class User
{
private String Name;
public static int Age = 0;
public User( String name, int age)
{
this.Name = name;
this.Age = age;
}
public String getName()
{
return this.Name;
}
public int getAge()
{
return this.Age;
}
public static void main(String[] args)
{
User student = new User( "James", 23 );
System.out.println( student.getName() );
System.out.println( student.getAge() );
}
}
Feel free to ask more questions.
#3
Posted 29 June 2009 - 11:01 AM
Thanks for the reply! It makes sense to me that the compiler is looking for class main (I thought it was a method). The book states that you have to compile the applications at the same time. That doesn't make sense to me because what if I want to use my new class in ten applications. Does that mean I have to compile eleven applications at the same time?
I'm new at this so I'm confused. My understanding of this so far is that I should be able to compile my new class one time and then I'll be able to use it with any other application as long as that application knows where to find it on the computer. Do I have to create a package which includes my new class in order to do this?
Thanks in advance for any help!
I'm new at this so I'm confused. My understanding of this so far is that I should be able to compile my new class one time and then I'll be able to use it with any other application as long as that application knows where to find it on the computer. Do I have to create a package which includes my new class in order to do this?
Thanks in advance for any help!
#4
Posted 29 June 2009 - 03:11 PM
neophyte said:
I'm new at this so I'm confused. My understanding of this so far is that I should be able to compile my new class one time and then I'll be able to use it with any other application as long as that application knows where to find it on the computer. Do I have to create a package which includes my new class in order to do this?
Yes.
#5
Posted 29 June 2009 - 07:16 PM
Each class should be in its own file, properly named, for organization purposes.


Sign In
Create Account

Back to top









