-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhanggang13
committed
Feb 13, 2017
1 parent
067f04b
commit edc137a
Showing
208 changed files
with
22,430 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<html> | ||
<head> | ||
<title>Java Examples in a Nutshell: License</title> | ||
</head> | ||
<body bgcolor="#ffffff"> | ||
<font face="helvetica"> | ||
<div align=center> | ||
<h1>License for the Examples from the Book<br><i>Java Examples | ||
in a Nutshell, 2nd Edition</i></h1> | ||
</div> | ||
|
||
<p><b>0. Definitions</b> | ||
|
||
For the purposes of this license, "the book" means the | ||
second edition of the book <i>Java Examples in a | ||
Nutshell</i>. "The examples" means the Java programs and | ||
other source code included in the book, and available for | ||
download from the website | ||
<i>http://www.davidflanagan.com/javaexamples2</i> | ||
|
||
|
||
<p><b>1. Copyright</b> | ||
|
||
The examples are Copyright © 2000 by David Flanagan. | ||
All rights reserved. | ||
|
||
<p><b>2. No Warranty</b> | ||
|
||
The examples are provided as-is, with NO WARRANTY OF ANY KIND. | ||
The examples were written to teach Java programming concepts | ||
and techniques, and are not intended as production-quality | ||
software. In particular, they have not been carefully | ||
tested. Neither David Flanagan nor the publisher O'Reilly | ||
& Associates is responsible for any loss or damages of | ||
any kind resulting from the use of these examples. | ||
|
||
<p><b>3. Non-commercial Use</b> | ||
|
||
You may study, use, modify, and distribute these examples | ||
for any non-commercial purpose, as long as the copyright | ||
notice at the top of each example is retained. You may use | ||
the examples in software you develop for personal use, in | ||
software used internally by non-profit institutions, and in | ||
software that is publicly released under an open-source | ||
license. | ||
|
||
<p><b>4. Educational Use</b> | ||
|
||
If you are an educator at non-profit educational | ||
institution, you may use the examples for educational | ||
purposes in your courses. Please make the book a required | ||
or recommended text for the students in your course. | ||
<p> | ||
If you are an educator at a for-profit educational | ||
institution or at an organization whose primary purpose is | ||
not education, you may also use the examples in your | ||
courses, but you must ensure that each of your students | ||
purchases or is given a copy of the book. | ||
|
||
<p><b>5. Commercial Use</b> | ||
|
||
The examples were developed to demonstrate Java programming | ||
concepts and techniques. They are not intended as | ||
production code, and have not been through any kind of | ||
rigorous testing or validation. Nevertheless, if you find | ||
the code useful, and would like to use it commercially, you | ||
may purchase a commercial use license for a nominal fee. | ||
Visit http://www.davidflanagan.com/javaexamples2/ for | ||
information on obtaining such a license. | ||
<p> | ||
Upon payment, a commercial use license entitles you to use | ||
the examples and modified versions of the examples in | ||
commercial software. "Commercial software" includes | ||
software written for sale and software written for internal | ||
use by a for-profit organization (including your own | ||
organization) It does not include software that you write | ||
solely for your personal use, software written for internal | ||
use by non-profit organizations, and software that is | ||
publicly released under an open-source license. | ||
<p> | ||
Note that a commercial-use license does not entitle to you | ||
sell or otherwise commercially distribute the examples or | ||
modified versions of the examples as examples. You may only | ||
commercially distribute the examples when they are | ||
integrated into your commercial software. | ||
<p> | ||
Note that purchase of a commercial-use license does not | ||
provide any kind of warranty, expressed or implied, for the | ||
examples | ||
</font> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
# java-examples | ||
source code from book java examples in a nutshell | ||
|
||
# source README.MD | ||
|
||
These are the examples from the book Java Examples in a Nutshell, 2nd | ||
Edition, by David Flanagan. | ||
|
||
See the file index.html for more information. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.dean</groupId> | ||
<artifactId>java-examples</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<applet code="com/davidflanagan/examples/applet/Clock.class" | ||
codebase="../../../../" | ||
width=150 height=20> | ||
</applet> |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/davidflanagan/examples/applet/Clock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (c) 2000 David Flanagan. All rights reserved. | ||
* This code is from the book Java Examples in a Nutshell, 2nd Edition. | ||
* It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. | ||
* You may study, use, and modify it for any non-commercial purpose. | ||
* You may distribute it non-commercially as long as you retain this notice. | ||
* For a commercial use license, or to purchase the book (recommended), | ||
* visit http://www.davidflanagan.com/javaexamples2. | ||
*/ | ||
package com.davidflanagan.examples.applet; | ||
import java.applet.*; // Don't forget this import statement! | ||
import java.awt.*; // Or this one for the graphics! | ||
import java.util.Date; // To obtain the current time | ||
import java.text.DateFormat; // For displaying the time | ||
|
||
/** | ||
* This applet displays the time, and updates it every second | ||
**/ | ||
public class Clock extends Applet implements Runnable { | ||
Label time; // A component to display the time in | ||
DateFormat timeFormat; // This object converts the time to a string | ||
Thread timer; // The thread that updates the time | ||
volatile boolean running; // A flag used to stop the thread | ||
|
||
/** | ||
* The init method is called when the browser first starts the applet. | ||
* It sets up the Label component and obtains a DateFormat object | ||
**/ | ||
public void init() { | ||
time = new Label(); | ||
time.setFont(new Font("helvetica", Font.BOLD, 12)); | ||
time.setAlignment(Label.CENTER); | ||
setLayout(new BorderLayout()); | ||
add(time, BorderLayout.CENTER); | ||
timeFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM); | ||
} | ||
|
||
/** | ||
* This browser calls this method to tell the applet to start running. | ||
* Here, we create and start a thread that will update the time each | ||
* second. Note that we take care never to have more than one thread | ||
**/ | ||
public void start() { | ||
running = true; // Set the flag | ||
if (timer == null) { // If we don't already have a thread | ||
timer = new Thread(this); // Then create one | ||
timer.start(); // And start it running | ||
} | ||
} | ||
|
||
/** | ||
* This method implements Runnable. It is the body of the thread. Once | ||
* a second, it updates the text of the Label to display the current time | ||
**/ | ||
public void run() { | ||
while(running) { // Loop until we're stopped | ||
// Get current time, convert to a String, and display in the Label | ||
time.setText(timeFormat.format(new Date())); | ||
// Now wait 1000 milliseconds | ||
try { Thread.sleep(1000); } | ||
catch (InterruptedException e) {} | ||
} | ||
// If the thread exits, set it to null so we can create a new one | ||
// if start() is called again. | ||
timer = null; | ||
} | ||
|
||
/** | ||
* The browser calls this method to tell the applet that it is not visible | ||
* and should not run. It sets a flag that tells the run() method to exit | ||
**/ | ||
public void stop() { running = false; } | ||
|
||
/** | ||
* Returns information about the applet for display by the applet viewer | ||
**/ | ||
public String getAppletInfo() { | ||
return "Clock applet Copyright (c) 2000 by David Flanagan"; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/davidflanagan/examples/applet/ColorScribble.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<applet code="com/davidflanagan/examples/applet/ColorScribble.class" | ||
codebase="../../../../" | ||
width=400 height=400> | ||
<param name="foreground" value="FF0000"> | ||
<param name="background" value="CCFFCC"> | ||
</applet> |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/davidflanagan/examples/applet/ColorScribble.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2000 David Flanagan. All rights reserved. | ||
* This code is from the book Java Examples in a Nutshell, 2nd Edition. | ||
* It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. | ||
* You may study, use, and modify it for any non-commercial purpose. | ||
* You may distribute it non-commercially as long as you retain this notice. | ||
* For a commercial use license, or to purchase the book (recommended), | ||
* visit http://www.davidflanagan.com/javaexamples2. | ||
*/ | ||
package com.davidflanagan.examples.applet; | ||
import java.applet.*; | ||
import java.awt.*; | ||
|
||
/** | ||
* A version of the Scribble applet that reads two applet parameters | ||
* to set the foreground and background colors. It also returns | ||
* information about itself when queried. | ||
**/ | ||
public class ColorScribble extends Scribble { | ||
// Read in two color parameters and set the colors. | ||
public void init() { | ||
super.init(); // Let the superclass initialize itself | ||
Color foreground = getColorParameter("foreground"); | ||
Color background = getColorParameter("background"); | ||
if (foreground != null) this.setForeground(foreground); | ||
if (background != null) this.setBackground(background); | ||
} | ||
|
||
// Read the specified parameter. Interpret it as a hexadecimal | ||
// number of the form RRGGBB and convert it to a color. | ||
protected Color getColorParameter(String name) { | ||
String value = this.getParameter(name); | ||
try { return new Color(Integer.parseInt(value, 16)); } | ||
catch (Exception e) { return null; } | ||
} | ||
|
||
// Return information suitable for display in an About dialog box. | ||
public String getAppletInfo() { | ||
return "ColorScribble v. 0.03. Written by David Flanagan."; | ||
} | ||
|
||
// Return info about the supported parameters. Web browsers and applet | ||
// viewers should display this information, and may also allow users to | ||
// set the parameter values. | ||
public String[][] getParameterInfo() { return info; } | ||
|
||
// Here's the information that getParameterInfo() returns. | ||
// It is an array of arrays of strings describing each parameter. | ||
// Format: parameter name, parameter type, parameter description | ||
private String[][] info = { | ||
{"foreground", "hexadecimal color value", "foreground color"}, | ||
{"background", "hexadecimal color value", "background color"} | ||
}; | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/davidflanagan/examples/applet/EventTester.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<applet code="com/davidflanagan/examples/applet/EventTester.class" | ||
codebase="../../../../" | ||
width=400 height=400> | ||
</applet> |
Oops, something went wrong.