<< Chapter < Page Chapter >> Page >

Using the library, you could write a program that would compute and also draw the trajectory in a single operation. In myopinion, that would be a much cleaner solution to the assignment.

Sample program

A complete listing of the program named Svg21a.java , that was used to produce the drawing shown in Figure 2 is provided in Listing 25 near the end of the module.

This program requires access to the SVG graphics library in the file named SvgLib21.java . A complete listing of this program is shown in Listing 26 near the end of the module.

This program also requires access to the free Java Development Kit , version 6 or later, which I will also discuss later.

Finally, this program also requires access to JDOM 1.1.1 , which is free, and which I will alsodiscuss later.

Purpose of the program

The primary purpose of this program is to demonstrate the use of my SVG graphics library in the file named SvgLib21 . It uses that library to draw an abbreviated version of a mass-pulley system shown in Figure 4 of the module thatyou will find here .

The drawing in that module contains several lines of text. However, this program draws only one line of text. Otherwise,the drawing produced by this program is the same as the drawing used inthat module titled Force and Motion -- Units of Force .

I created the original drawing using Inkscape . I created this drawing usingmy SVG graphics library and the program that I am about to discuss.

This program was tested using J2SE 6, JDOM 1.1.1, and Firefox 5 running under Windows Vista Home Premium Edition.

Beginning of the program named Svg21a.java

I will explain this program in fragments and explain how you can write similar programs to create the SVG drawing files that you need. The firstfragment, which shows the beginning of the program, is shown in Listing 2 .

(Note that complete listings are provided in Listing 25 , Listing 26 , and Listing 27 . That code is ready to copy into your editor, save as Java source code files, compile, and run as explained under Writing, compiling, and running Java programs .)

Listing 2 . Beginning of the program named Svg21a.java.
import java.io.*; import org.jdom.*;public class Svg21a{ public static void main(String[]args){ //DO NOT MODIFY ANY OF THE CODE ABOVE THIS LINE.//##################################################//

Java comments

Whenever you see the following character sequence, //, in a Java program, the text that follows to the end of the line is a comment. That is to say, that textis meant to provide information to a human reader and is ignored by the computer.

Listing 2 contains two comments. I will use many more comments in subsequent listings to help explain the code.

Java program files

Java programs are simply text files with the file name of your choice and an extension of .java. You can create those files using any plain text editor. I will explain later how youcan "compile" those files to createexecutable programs.

If this were a module on computer programming, I would explain what is meant by the program code in Listing 2 . However, since this is not a module on computer program, I will simply tell you to replicate the text shown in Listing 2 at the beginning of your Java program file with one exception. That exception has to do with the name of the program and the name of the file.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Accessible physics concepts for blind students. OpenStax CNX. Oct 02, 2015 Download for free at https://legacy.cnx.org/content/col11294/1.36
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Accessible physics concepts for blind students' conversation and receive update notifications?

Ask