Results 1 to 6 of 6
Thread: Opening a project in NetBeans
- 02-23-2013, 08:01 PM #1
Member
- Join Date
- Jan 2013
- Location
- Texas
- Posts
- 41
- Rep Power
- 0
Opening a project in NetBeans
Greetings all,
I am reading Data Structures & Algorithms in Java by: Robert Lafore and the book comes with Reader Files. So for example, I am looking at the chapter 4 directory where the queue files reside and I have 3 files.
2 .class files and a .java file
queue.class
queueApp.class
queue.java
the queue.java file contains both files it seems as there are two classes as shown in the code below:
What I am trying to figure out is if there is a more efficient way of importing this into NetBeans. Currently I am creating a project and naming it the same as the code with the main function in it and pasting that section of code, then creating another class and pasting that section of code. This just seems cumbersome and maybe I just don't know how to work with these files and get them into NetBeans. Any assistance or guidance would be appreciated.
Wally
Java Code:// Queue.java // demonstrates queue // to run this program: C>java QueueApp //////////////////////////////////////////////////////////////// class Queue { private int maxSize; private long[] queArray; private int front; private int rear; private int nItems; //-------------------------------------------------------------- public Queue(int s) // constructor { maxSize = s; queArray = new long[maxSize]; front = 0; rear = -1; nItems = 0; } //-------------------------------------------------------------- public void insert(long j) // put item at rear of queue { if(rear == maxSize-1) // deal with wraparound rear = -1; queArray[++rear] = j; // increment rear and insert nItems++; // one more item } //-------------------------------------------------------------- public long remove() // take item from front of queue { long temp = queArray[front++]; // get value and incr front if(front == maxSize) // deal with wraparound front = 0; nItems--; // one less item return temp; } //-------------------------------------------------------------- public long peekFront() // peek at front of queue { return queArray[front]; } //-------------------------------------------------------------- public boolean isEmpty() // true if queue is empty { return (nItems==0); } //-------------------------------------------------------------- public boolean isFull() // true if queue is full { return (nItems==maxSize); } //-------------------------------------------------------------- public int size() // number of items in queue { return nItems; } //-------------------------------------------------------------- } // end class Queue //////////////////////////////////////////////////////////////// class QueueApp { public static void main(String[] args) { Queue theQueue = new Queue(5); // queue holds 5 items theQueue.insert(10); // insert 4 items theQueue.insert(20); theQueue.insert(30); theQueue.insert(40); theQueue.remove(); // remove 3 items theQueue.remove(); // (10, 20, 30) theQueue.remove(); theQueue.insert(50); // insert 4 more items theQueue.insert(60); // (wraps around) theQueue.insert(70); theQueue.insert(80); while( !theQueue.isEmpty() ) // remove and display { // all items long n = theQueue.remove(); // (40, 50, 60, 70, 80) System.out.print(n); System.out.print(" "); } System.out.println(""); } // end main() } // end class QueueApp ////////////////////////////////////////////////////////////////
- 02-23-2013, 08:43 PM #2
Member
- Join Date
- Jan 2013
- Location
- Texas
- Posts
- 41
- Rep Power
- 0
Opening a file in Netbean (Is there a more efficient way)
Greetings all,
I am reading Data Structures & Algorithms in Java by: Robert Lafore and the book comes with Reader Files. So for example, I am looking at the chapter 4 directory where the queue files reside and I have 3 files.
2 .class files and a .java file
queue.class
queueApp.class
queue.java
the queue.java file contains both files it seems as there are two classes as shown in the code below:
What I am trying to figure out is if there is a more efficient way of importing this into NetBeans. Currently I am creating a project and naming it the same as the code with the main function in it and pasting that section of code, then creating another class and pasting that section of code. This just seems cumbersome and maybe I just don't know how to work with these files and get them into NetBeans. Any assistance or guidance would be appreciated.
Wally
I did post this in the NetBeans section first, but that forum seems to be read quite less often, so I added it here also.
Java Code:// Queue.java // demonstrates queue // to run this program: C>java QueueApp //////////////////////////////////////////////////////////////// class Queue { private int maxSize; private long[] queArray; private int front; private int rear; private int nItems; //-------------------------------------------------------------- public Queue(int s) // constructor { maxSize = s; queArray = new long[maxSize]; front = 0; rear = -1; nItems = 0; } //-------------------------------------------------------------- public void insert(long j) // put item at rear of queue { if(rear == maxSize-1) // deal with wraparound rear = -1; queArray[++rear] = j; // increment rear and insert nItems++; // one more item } //-------------------------------------------------------------- public long remove() // take item from front of queue { long temp = queArray[front++]; // get value and incr front if(front == maxSize) // deal with wraparound front = 0; nItems--; // one less item return temp; } //-------------------------------------------------------------- public long peekFront() // peek at front of queue { return queArray[front]; } //-------------------------------------------------------------- public boolean isEmpty() // true if queue is empty { return (nItems==0); } //-------------------------------------------------------------- public boolean isFull() // true if queue is full { return (nItems==maxSize); } //-------------------------------------------------------------- public int size() // number of items in queue { return nItems; } //-------------------------------------------------------------- } // end class Queue //////////////////////////////////////////////////////////////// class QueueApp { public static void main(String[] args) { Queue theQueue = new Queue(5); // queue holds 5 items theQueue.insert(10); // insert 4 items theQueue.insert(20); theQueue.insert(30); theQueue.insert(40); theQueue.remove(); // remove 3 items theQueue.remove(); // (10, 20, 30) theQueue.remove(); theQueue.insert(50); // insert 4 more items theQueue.insert(60); // (wraps around) theQueue.insert(70); theQueue.insert(80); while( !theQueue.isEmpty() ) // remove and display { // all items long n = theQueue.remove(); // (40, 50, 60, 70, 80) System.out.print(n); System.out.print(" "); } System.out.println(""); } // end main() } // end class QueueApp ////////////////////////////////////////////////////////////////
- 02-24-2013, 10:11 AM #3
Re: Opening a file in Netbean (Is there a more efficient way)
Don't do that again. Please go through the Forum Rules, particularly the second paragraph.
I'm merging the two threads.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-26-2013, 02:35 PM #4
Member
- Join Date
- May 2012
- Posts
- 18
- Rep Power
- 0
Re: Opening a project in NetBeans
Try this: File --> New Project --> Java project with existing sources. You will see when you can add folders with your existing source code--which will probably be, and probably should be, outside your typical netbeans project folder.
- 02-26-2013, 03:59 PM #5
Member
- Join Date
- Jan 2013
- Location
- Texas
- Posts
- 41
- Rep Power
- 0
Re: Opening a project in NetBeans
Thanks for your reply. The problem is that the author took all the different class files and put them in one .java file so I can do what you suggested, but it doesn't recognize the main. I think I am just stuck creating a project and doing a copy and paste from the combined java file to separate class files. I believe the author did all the work from command line so no consideration for an IDE was taken
- 02-28-2013, 06:37 PM #6
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Re: Opening a project in NetBeans
I can create a new Java project, paste the code in the file and it runs just fine in a file that is named JavaApplication4.
What OS and version of NetBeans are you using?
Did you check Project Properties>>Run>>Main Class? Do you have the package declaration in the file correct?
I have projects full of different class files with main() in them and I just right click the file and choose "run file" and it works. If I add a new file with a class the same name as a class in another file, I just create a new package in the same project and put it there. You could have all of your book source code in the same project in NetBeans and do a "run file" on your program fie of interest. You can have all sorts of dependent class files in the project for any file with main() in it.Last edited by MackSix; 02-28-2013 at 07:04 PM.
Similar Threads
-
Opening an existing project with netbeans.
By pala in forum NetBeansReplies: 1Last Post: 01-05-2012, 12:01 PM -
Eclipse freezes when opening SVN project
By kjkrum in forum EclipseReplies: 6Last Post: 11-23-2011, 01:21 AM -
Trainer Opening for Project
By runka in forum Jobs OfferedReplies: 1Last Post: 07-14-2011, 04:43 PM -
opening project in eclipse
By keioGirl in forum EclipseReplies: 1Last Post: 04-23-2009, 03:09 PM -
Opening file, runs in NetBeans but CommandPrompt
By fauzilhaqqi in forum NetBeansReplies: 2Last Post: 12-15-2008, 03:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks