Skip to content

Commit edc137a

Browse files
author
zhanggang13
committed
commit code
1 parent 067f04b commit edc137a

File tree

208 files changed

+22430
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+22430
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010

1111
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
1212
hs_err_pid*
13+
14+
#idea
15+
*.iml
16+
.idea

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE.html

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<html>
2+
<head>
3+
<title>Java Examples in a Nutshell: License</title>
4+
</head>
5+
<body bgcolor="#ffffff">
6+
<font face="helvetica">
7+
<div align=center>
8+
<h1>License for the Examples from the Book<br><i>Java Examples
9+
in a Nutshell, 2nd Edition</i></h1>
10+
</div>
11+
12+
<p><b>0. Definitions</b>
13+
14+
For the purposes of this license, "the book" means the
15+
second edition of the book <i>Java Examples in a
16+
Nutshell</i>. "The examples" means the Java programs and
17+
other source code included in the book, and available for
18+
download from the website
19+
<i>http://www.davidflanagan.com/javaexamples2</i>
20+
21+
22+
<p><b>1. Copyright</b>
23+
24+
The examples are Copyright &copy; 2000 by David Flanagan.
25+
All rights reserved.
26+
27+
<p><b>2. No Warranty</b>
28+
29+
The examples are provided as-is, with NO WARRANTY OF ANY KIND.
30+
The examples were written to teach Java programming concepts
31+
and techniques, and are not intended as production-quality
32+
software. In particular, they have not been carefully
33+
tested. Neither David Flanagan nor the publisher O'Reilly
34+
&amp; Associates is responsible for any loss or damages of
35+
any kind resulting from the use of these examples.
36+
37+
<p><b>3. Non-commercial Use</b>
38+
39+
You may study, use, modify, and distribute these examples
40+
for any non-commercial purpose, as long as the copyright
41+
notice at the top of each example is retained. You may use
42+
the examples in software you develop for personal use, in
43+
software used internally by non-profit institutions, and in
44+
software that is publicly released under an open-source
45+
license.
46+
47+
<p><b>4. Educational Use</b>
48+
49+
If you are an educator at non-profit educational
50+
institution, you may use the examples for educational
51+
purposes in your courses. Please make the book a required
52+
or recommended text for the students in your course.
53+
<p>
54+
If you are an educator at a for-profit educational
55+
institution or at an organization whose primary purpose is
56+
not education, you may also use the examples in your
57+
courses, but you must ensure that each of your students
58+
purchases or is given a copy of the book.
59+
60+
<p><b>5. Commercial Use</b>
61+
62+
The examples were developed to demonstrate Java programming
63+
concepts and techniques. They are not intended as
64+
production code, and have not been through any kind of
65+
rigorous testing or validation. Nevertheless, if you find
66+
the code useful, and would like to use it commercially, you
67+
may purchase a commercial use license for a nominal fee.
68+
Visit http://www.davidflanagan.com/javaexamples2/ for
69+
information on obtaining such a license.
70+
<p>
71+
Upon payment, a commercial use license entitles you to use
72+
the examples and modified versions of the examples in
73+
commercial software. "Commercial software" includes
74+
software written for sale and software written for internal
75+
use by a for-profit organization (including your own
76+
organization) It does not include software that you write
77+
solely for your personal use, software written for internal
78+
use by non-profit organizations, and software that is
79+
publicly released under an open-source license.
80+
<p>
81+
Note that a commercial-use license does not entitle to you
82+
sell or otherwise commercially distribute the examples or
83+
modified versions of the examples as examples. You may only
84+
commercially distribute the examples when they are
85+
integrated into your commercial software.
86+
<p>
87+
Note that purchase of a commercial-use license does not
88+
provide any kind of warranty, expressed or implied, for the
89+
examples
90+
</font>
91+
</body>
92+
</html>

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
# java-examples
22
source code from book java examples in a nutshell
3+
4+
# source README.MD
5+
6+
These are the examples from the book Java Examples in a Nutshell, 2nd
7+
Edition, by David Flanagan.
8+
9+
See the file index.html for more information.

cover.gif

6.32 KB
Loading

index.html

+263
Large diffs are not rendered by default.

pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.dean</groupId>
8+
<artifactId>java-examples</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
12+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<applet code="com/davidflanagan/examples/applet/Clock.class"
2+
codebase="../../../../"
3+
width=150 height=20>
4+
</applet>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2000 David Flanagan. All rights reserved.
3+
* This code is from the book Java Examples in a Nutshell, 2nd Edition.
4+
* It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.
5+
* You may study, use, and modify it for any non-commercial purpose.
6+
* You may distribute it non-commercially as long as you retain this notice.
7+
* For a commercial use license, or to purchase the book (recommended),
8+
* visit http://www.davidflanagan.com/javaexamples2.
9+
*/
10+
package com.davidflanagan.examples.applet;
11+
import java.applet.*; // Don't forget this import statement!
12+
import java.awt.*; // Or this one for the graphics!
13+
import java.util.Date; // To obtain the current time
14+
import java.text.DateFormat; // For displaying the time
15+
16+
/**
17+
* This applet displays the time, and updates it every second
18+
**/
19+
public class Clock extends Applet implements Runnable {
20+
Label time; // A component to display the time in
21+
DateFormat timeFormat; // This object converts the time to a string
22+
Thread timer; // The thread that updates the time
23+
volatile boolean running; // A flag used to stop the thread
24+
25+
/**
26+
* The init method is called when the browser first starts the applet.
27+
* It sets up the Label component and obtains a DateFormat object
28+
**/
29+
public void init() {
30+
time = new Label();
31+
time.setFont(new Font("helvetica", Font.BOLD, 12));
32+
time.setAlignment(Label.CENTER);
33+
setLayout(new BorderLayout());
34+
add(time, BorderLayout.CENTER);
35+
timeFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM);
36+
}
37+
38+
/**
39+
* This browser calls this method to tell the applet to start running.
40+
* Here, we create and start a thread that will update the time each
41+
* second. Note that we take care never to have more than one thread
42+
**/
43+
public void start() {
44+
running = true; // Set the flag
45+
if (timer == null) { // If we don't already have a thread
46+
timer = new Thread(this); // Then create one
47+
timer.start(); // And start it running
48+
}
49+
}
50+
51+
/**
52+
* This method implements Runnable. It is the body of the thread. Once
53+
* a second, it updates the text of the Label to display the current time
54+
**/
55+
public void run() {
56+
while(running) { // Loop until we're stopped
57+
// Get current time, convert to a String, and display in the Label
58+
time.setText(timeFormat.format(new Date()));
59+
// Now wait 1000 milliseconds
60+
try { Thread.sleep(1000); }
61+
catch (InterruptedException e) {}
62+
}
63+
// If the thread exits, set it to null so we can create a new one
64+
// if start() is called again.
65+
timer = null;
66+
}
67+
68+
/**
69+
* The browser calls this method to tell the applet that it is not visible
70+
* and should not run. It sets a flag that tells the run() method to exit
71+
**/
72+
public void stop() { running = false; }
73+
74+
/**
75+
* Returns information about the applet for display by the applet viewer
76+
**/
77+
public String getAppletInfo() {
78+
return "Clock applet Copyright (c) 2000 by David Flanagan";
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<applet code="com/davidflanagan/examples/applet/ColorScribble.class"
2+
codebase="../../../../"
3+
width=400 height=400>
4+
<param name="foreground" value="FF0000">
5+
<param name="background" value="CCFFCC">
6+
</applet>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2000 David Flanagan. All rights reserved.
3+
* This code is from the book Java Examples in a Nutshell, 2nd Edition.
4+
* It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.
5+
* You may study, use, and modify it for any non-commercial purpose.
6+
* You may distribute it non-commercially as long as you retain this notice.
7+
* For a commercial use license, or to purchase the book (recommended),
8+
* visit http://www.davidflanagan.com/javaexamples2.
9+
*/
10+
package com.davidflanagan.examples.applet;
11+
import java.applet.*;
12+
import java.awt.*;
13+
14+
/**
15+
* A version of the Scribble applet that reads two applet parameters
16+
* to set the foreground and background colors. It also returns
17+
* information about itself when queried.
18+
**/
19+
public class ColorScribble extends Scribble {
20+
// Read in two color parameters and set the colors.
21+
public void init() {
22+
super.init(); // Let the superclass initialize itself
23+
Color foreground = getColorParameter("foreground");
24+
Color background = getColorParameter("background");
25+
if (foreground != null) this.setForeground(foreground);
26+
if (background != null) this.setBackground(background);
27+
}
28+
29+
// Read the specified parameter. Interpret it as a hexadecimal
30+
// number of the form RRGGBB and convert it to a color.
31+
protected Color getColorParameter(String name) {
32+
String value = this.getParameter(name);
33+
try { return new Color(Integer.parseInt(value, 16)); }
34+
catch (Exception e) { return null; }
35+
}
36+
37+
// Return information suitable for display in an About dialog box.
38+
public String getAppletInfo() {
39+
return "ColorScribble v. 0.03. Written by David Flanagan.";
40+
}
41+
42+
// Return info about the supported parameters. Web browsers and applet
43+
// viewers should display this information, and may also allow users to
44+
// set the parameter values.
45+
public String[][] getParameterInfo() { return info; }
46+
47+
// Here's the information that getParameterInfo() returns.
48+
// It is an array of arrays of strings describing each parameter.
49+
// Format: parameter name, parameter type, parameter description
50+
private String[][] info = {
51+
{"foreground", "hexadecimal color value", "foreground color"},
52+
{"background", "hexadecimal color value", "background color"}
53+
};
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<applet code="com/davidflanagan/examples/applet/EventTester.class"
2+
codebase="../../../../"
3+
width=400 height=400>
4+
</applet>

0 commit comments

Comments
 (0)