-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathREADME-exercise-solutions.txt
79 lines (56 loc) · 3.44 KB
/
README-exercise-solutions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
This README explains how to use the solutions to the programming exercises
for "Introduction to Programming Using Java, Version 9, Swing edition",
which is freely available on the web at http://math.hws.edu/javanotes-swing
Although some exercise solutions will work with earlier versions,
Java 17 is required for many of them. Information about getting
Java can be found in Section 2.6 of the book.
Each end-of-chapter exercise has a web page that contains a discussion
of the solution and the source code for a sample solution. The
archive javanotes9-swing-exercise-solutions.zip, which can be downloaded
using a link on the web site, contains all of the source code for
the solutions, extracted from the solution web pages. It also contains
all extra files that are required by the solutions. The solutions
are organized into folders, with one folder for each chapter (except
Chapter 1, which has no exercises.) This is done as a convenience
to help you run the solutions, but please don't just run them! Try
working on the exercises yourself, and read my discussion of the
solutions on the web pages. You'll learn a lot more that way.
You can also get solutions to individual exercises by copy-and-pasting
the code from the solution web page into a text editor. (Copy from
the web page open in a web browser, not from the HTML source of the
web page. The HTML source contains extra markup that will be seen
as errors by the Java compiler.)
You have two options for running the solutions...
---- RUN IN AN IDE ----
If you want to run the examples in an IDE, such as Eclipse, you should
be able to copy-and-paste the entire contents of any one of the chapter folders
into a project in the IDE, and then run the programs. Note: When adding items
to an Eclipse project, do not copy the chapter folder itself; open the
folder and copy the contents into the src folder in the Eclipse project.
You can put the examples from several chapters into the same project if you
want; some files, such as TextIO.java, are duplicated in several chapters,
but any two files with the same name are identical, and you only need one
copy of the file in your project.
---- COMPILE AND RUN ON THE COMMAND LINE ----
If you know how to compile programs on the command line, and if you have
downloaded the examples, you can easily compile and run all the examples.
Just change into one of the chapter directories inside the "sources" directory,
and use a command of the form
javac ExampleClassName.java
For example:
javac HelloWorld.java
As long as your compiler supports Java 17 or higher, there should be no errors.
(You might see some warnings, especially if you use a newer version of Java,
but warnings do not stop a program from being compiled or executed.) You can
then run the compiled program using the java command. For example:
java HelloWorld
There is one exercise in Chapter 12 that uses packages. You can compile the
example with the command
javac netgame/newchat/*.java
on Mac or Linux or
javac netgame\newchat\*.java
on Windows. Then, to use the program, you need to run both the server program
and the client program with the following commands (in separate command windows):
java netgame.newchat.NewChatRoomServer
and
java netgame.newchat.NewChatRoomWindow