Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add...
Transcript of Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add...
![Page 1: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/1.jpg)
Brooklyn College
Using stdlib within Netbeans
Lawrence Goetz 10/16/2018
![Page 2: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/2.jpg)
Contents Downloading stdlib ....................................................................................................................................... 2
Setting up stdlib ............................................................................................................................................ 3
Sample program ............................................................................................................................................ 9
Adding stdlib to your project ...................................................................................................................... 10
Alternative way to add stdlib to your project ............................................................................................. 11
![Page 3: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/3.jpg)
Downloading stdlib
https://introcs.cs.princeton.edu/java/stdlib/
Select to download the stdlib-package.jar.
![Page 4: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/4.jpg)
Setting up stdlib
You need to do this for the first time you are installing stdlib on your computer. If you are at a computer that you cannot save settings to, please refer to Alternative way to add stdlib to your project
Place the stdlib-package.jar in your NetBeansProjects folder.
![Page 5: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/5.jpg)
From the Tools menu, select Libraries.
![Page 6: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/6.jpg)
Select to add a New Library
Give it the name stdlib and then press OK.
![Page 7: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/7.jpg)
Select the stdlib from the Libraries panel and then select Add JAR/Folder.
![Page 8: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/8.jpg)
Select the stdlib-package.jar file and press Add JAR/Folder.
![Page 9: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/9.jpg)
Press OK.
That’s it. You have added the stdlib to your Global Libraries. This will allow you to add the stdlib to any project you are working on.
![Page 10: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/10.jpg)
Sample program package righttriangle; public class RightTriangle { public static void main(String[] args) { StdDraw.square(0.5, 0.5, 0.5); StdDraw.setPenColor(StdDraw.BLUE); StdDraw.line(0.5, 0.5, 0.9, 0.5); StdDraw.line(0.9, 0.5, 0.5, 0.8); StdDraw.line(0.5, 0.8, 0.5, 0.5); StdDraw.circle(0.7, 0.65, 0.25); } }
Notice how there are errors on line 12-17 for StdDraw. That class is part of stdlib. We need to add that to our project.
![Page 11: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/11.jpg)
Adding stdlib to your project
In your project, right click on the Libraries menu and select Add Library.
Select the stdlib and then select Add Library.
![Page 12: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/12.jpg)
Alternative way to add stdlib to your project Please skip this if you already have setup stdlib.
In your project, right click on the Libraries menu select Add JAR/Folder.
Select the stdlib-package.jar and take the defaults that say to use the Absolute Path.
![Page 13: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/13.jpg)
You must include the import statement below:
import edu.princeton.cs.introcs.*;
The errors on 12-17 have disappeared. Now you are ready to run your project.
![Page 14: Using stdlib within Netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · Select to add a New Library. Give it the name stdlib and then press OK.](https://reader036.fdocuments.us/reader036/viewer/2022062402/5d183a1988c99313688d4199/html5/thumbnails/14.jpg)
The results from running your project using stdlib.