using stdlib within netbeans - sci.brooklyn.cuny.edugoetz/java/stdlib-netbeans.pdf · select to add...

14
Brooklyn College Using stdlib within Netbeans Lawrence Goetz 10/16/2018

Upload: trinhdat

Post on 30-Jun-2019

220 views

Category:

Documents


0 download

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The results from running your project using stdlib.