Introduction to Programming Using Java, Version 9, JavaFX Edition

Source Code


This page contains links to the source code for examples appearing in the free, on-line textbook Introduction to Programming Using Java, Version 9, JavaFX Edition. The index page has links for downloading the entire web site. If you do that, you will find the source code files in a directory named source. There is also a link for downloading just the source code files. The README file from the download includes some instructions for compiling and running the programs. Note however that some of these examples depend on other source files, such as TextIO.java , that are not built into Java. These are classes that I have written. All necessary files are included in the downloads, and links to the individual files are provided below.

The solutions to end-of-chapter exercises are not listed on this page. Each end-of-chapter exercise has its own Web page, which discusses its solution. The source code of a sample solution of each exercise is given on the solution page for that exercise. If you want to compile the solution, you should be able to copy-and-paste the solution out of a Web browser window and into a text editing program. (You can't copy-and-paste from the HTML source of the solution page, since it contains extra HTML markup commands that the Java compiler won't understand; the HTML markup does not appear when the page is displayed in a Web browser.) Exercise solutions are also available as a download from the front page of the web site. The README file from the download has more information.


Part 1: Text-oriented Examples

Many of the sample programs in the text are based on console-style input/output, where the computer and the user type lines of text back and forth to each other. Almost all of these programs use the standard output object, System.out, for output. Many of them use my non-standard class, TextIO, for input. For the programs that use TextIO, one of the files TextIO.java or TextIO.class must be available when you compile the program, and TextIO.class must be available when you run the program. Since TextIO is defined in a package named textio, this means that TextIO.java and/or TextIO.class must be in a directory named textio, which must be in the same directory as the program. There is also a GUI version of TextIO; you can find information about it at the end of this web page.


Part 2: Graphical Examples from the Text

The following sample programs use a graphical user interface. All of these programs use JavaFX as the GUI toolbox.


Part 3: Auxiliary Files

This section lists some of the extra source files that are required by various examples in the previous sections. The files listed here are those which are general enough to be potentially useful in other programming projects. Links to these files are also given above, along with the programs that use them.

  • TextIO.java defines a class containing some static methods for doing input/output. These methods make it easier to use the standard input stream, System.in. TextIO also has methods for printing to System.out. It also supports other input sources and output destinations, such as files. TextIO is in a package named textio. The TextIO class is only useful in a command-line environment, and it might be inconvenient to use in integrated development environments such as Eclipse in which standard input does not work particularly well. In that case, you might want to use the following file instead.
  • textiogui/TextIO.java , a GUI version of TextIO that opens a window where TextIO I/O operations are performed. This is part of a package named textiogui to distinguish it from the normal TextIO. A companion class in that package, textiogui/System.java , is a fake System class that makes it possible to use System.out and other features of System in the same window. I use these classes to build executable jar files for my text-oriented examples that run in a window instead of on the command line. See the comments in the source code files for more information. (Note that this GUI version of TextIO uses the Swing GUI toolkit rather than JavaFX.)
  • SimpleGraphicsStarter.java and SimpleAnimationStarter.java are small programs that you can edit to make very simple pictures and animations These programs were used in Section 3.9 and in some of the exercises for Chapter 3.
  • Mosaic.java contains subroutines for opening and controlling a window that contains a grid of colored rectangles. It depends on MosaicCanvas.java . It is used in several examples and exercises in Chapter 4.
  • MosaicCanvas defines a subclass of Canvas that shows little rectangles arranged in rows and columns, with many options.
  • StatCalc.java is a simple class that computes some statistics of a set of numbers. It is used only for a couple exercises in Chapter 5 and Chapter 6.
  • Expr.java defines a class Expr that represents mathematical expressions involving the variable x. It is used only in a couple of the exercises in Chapter 8.
  • TextReader.java is not used in this textbook, but it might be useful to some readers. A TextReader reads character data from input streams. Input methods in an object of type TextReader are similar to the static input methods in TextIO.
  • netgame.common is a package that defines a framework for networked games, which is discussed in detail in Section 12.5. The netgame packages also includes several examples.
  • PokerRank.java can be used to assign ranks to hands of cards in poker games. The cards are defined in the class PokerCard.java . There is also a PokerDeck.java All of these classes are part of the package netgame.fivecarddraw , which is discussed in Subsection 12.5.4, but these classes can be used independently of the netgame framework.
  • SimpleDialogs.java contains easy-to-use static methods for showing several kinds of JavaFX dialog box and getting back the results of user interaction when appropriate.

David Eck

AltStyle によって変換されたページ (->オリジナル) /