Java Examples in a Nutshell by David Flanagan Here are new changes that appear in the 12/98 reprint: (preface) After the heading and paragraph "Java Examples Online", added a heading entitled "Licensing Inforamtion" with the following information: 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. If you would like to use the code in a commercial product, you may purchase a commercial use license from the author for a nominal fee. Visit http://www.davidflanagan.com/javaexamples/ for information on obtaining such a license. Please note that the examples are provided as-is, with no warranty of any kind. (10) Example 1-8: if (x == 1) return 1; now reads: if (x <= 1) return 1; (27) Example 2-6, lines 32-33: inserted the word "the" between "and specified" (114) Example 6-5, replaced code with new code: import java.applet.*; import java.awt.*; import java.awt.event.*; public class CardLayoutExample2 extends Applet { public void init() { // Create a layout manager, and save a reference to it for future use. // This CardLayout leaves 10 pixels margins around the component. final CardLayout cardlayout = new CardLayout(10, 10); // Specify the layout manager for the applet this.setLayout(cardlayout); // Create a listener to invoke the next() method of cardlayout. ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { // When button is clicked cardlayout.next(CardLayoutExample2.this); // display the next one. } }; for(int i = 1; i <= 9; i++) { Button b = new Button("Button #" + i); b.addActionListener(listener); this.add("Button" + i, b); // Specify a name for each component } } } (118) Example 6-8, header comments: *margin_height -- how much space...left and right *margin_width -- how much space...top and bottom now reads *margin_height -- how much space...top and bottom *margin_width -- how much space...left and right (131) Example 6-13, changed the following line: Frame f = new Frame("InfoDialog Test"); To: Frame f = new Frame("YesNoDialog Test"); (158)Changed the line: // Ask whether to overwrite it System.out.print("Overwrite existing file " + to_name + "? (Y/N): "); To: // Ask whether to overwrite it System.out.print("Overwrite existing file " + to_file.getName() + "? (Y/N): "); Since this adds a line, we removed the blank line (to keep current page breaks) before: // If the destination is a directory, use the source file name (191) Example 9-4, changed the following line: to_server.println("GET " + filename); to: to_server.println("GET " + filename + "\n"); (238) second text paragraph, changed: "manifest.stub" to "manifest" (keep in italics) Also, changed the following line: Name: oreilly/beans/MultiLineLabel.class To: Name: oreilly/beans/yesno/MultiLineLabel.class Finally, changed the following line: % jar cfm MultiLineLabel.jar manifest.stub oreilly/beans/MultiLineLabel.class To: % jar cfm MultiLineLabel.jar manifest oreilly/beans/yesno/MultiLineLabel.class (266) and (267) changed the following line: String filename = f.getFile(); // Get the user's response To: String filename = f.getDirectory() + f.getFile(); // Get response (274) Example 14-1, removed the following line: import java.applet.*; (304) Example 15-4 removed the line: "import Mud.*;" (307) Example 15-5 same change (314) Example 15-6 same change (315) Example 15-7 same change (330) After the line "Object value = rs.getObject(i+1);", added the line: if (value != null) and changed indentation of the next line so the code now reads: Object value = rs.getObject(i+1); if (value != null) overwrite(line, colpos[i] + 1, value.toString().trim()); (Don't change the indent of the second "overwrite" line.) Finally, since we added a line, we cut the blank line before: // Finally, end the table with one last divider line (appendix) completely removed (index) now starts on page 369 and has been rerun to reflect the removal of the appendix