Results 1 to 6 of 6
  1. #1
    wfsteadman is offline Member
    Join Date
    Jan 2013
    Location
    Texas
    Posts
    45
    Rep Power
    0

    Default 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
    ////////////////////////////////////////////////////////////////

  2. #2
    wfsteadman is offline Member
    Join Date
    Jan 2013
    Location
    Texas
    Posts
    45
    Rep Power
    0

    Default 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
    ////////////////////////////////////////////////////////////////

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Opening a file in Netbean (Is there a more efficient way)

    Quote Originally Posted by wfsteadman View Post
    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.
    Don't do that again. Please go through the Forum Rules, particularly the second paragraph.

    I'm merging the two threads.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Art Vandelay is offline Member
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default 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.

  5. #5
    wfsteadman is offline Member
    Join Date
    Jan 2013
    Location
    Texas
    Posts
    45
    Rep Power
    0

    Default 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

  6. #6
    MackSix is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default 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

  1. Opening an existing project with netbeans.
    By pala in forum NetBeans
    Replies: 1
    Last Post: 01-05-2012, 12:01 PM
  2. Eclipse freezes when opening SVN project
    By kjkrum in forum Eclipse
    Replies: 6
    Last Post: 11-23-2011, 01:21 AM
  3. Trainer Opening for Project
    By runka in forum Jobs Offered
    Replies: 1
    Last Post: 07-14-2011, 04:43 PM
  4. opening project in eclipse
    By keioGirl in forum Eclipse
    Replies: 1
    Last Post: 04-23-2009, 03:09 PM
  5. Opening file, runs in NetBeans but CommandPrompt
    By fauzilhaqqi in forum NetBeans
    Replies: 2
    Last Post: 12-15-2008, 03:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •