diff --git a/.cvsignore b/.cvsignore index 469286194..179498038 100644 --- a/.cvsignore +++ b/.cvsignore @@ -2,3 +2,4 @@ err.log index-byname.html jabadot +oreilly diff --git a/QCam.java b/QCam.java deleted file mode 100644 index 5b2f00265..000000000 --- a/QCam.java +++ /dev/null @@ -1,112 +0,0 @@ -import java.awt.*; -import java.awt.image.*; -import java.io.*; - -/** Try to display the contents of the QuickCam camera. */ -public class QCam extends Component implements Runnable { - /** frames/second */ - protected final int FPS = 10; - - /** The Camera's Device name (UNIX-specific) */ - protected static final String DEVNAME = "/dev/qcam0"; - /** A File object used to open a RandomAccessFile from the dev name */ - protected final File fileObj = new File(DEVNAME); - /** The file to access the Camera */ - protected RandomAccessFile camFile; - - /** The data buffer */ - protected byte data[]; - - /** A MemoryImageSource */ - protected MemoryImageSource source; - - /** An Image */ - Image im; - - /** The default image sizes from the QuickCam */ - protected final int WIDTH = 160, HEIGHT = 120, SIZE = WIDTH * HEIGHT; - - /** Construct a QCam object */ - public QCam() { - super(); - // adapted from the MemoryAnimationSourceDemo by Garth Dickie): - data = new byte[SIZE]; - - int value = 0; - for (int i = 0; i < SIZE; i++) { - data[i] = (byte)value; - } - - // try { - // camFile = new RandomAccessFile(fileObj, "r"); - // } catch (IOException e) { - // System.err.println("open: " + e); - // return; - // } - byte[] gray = new byte[64]; - for (byte i=0; i<64; i++) - gray[i] = i; - source = new MemoryImageSource(WIDTH, HEIGHT, - new IndexColorModel(8, 64, gray, gray, gray), data, 0, WIDTH); - source.setAnimated(true); - // im = createImage(source); - - // And start the animator Thread... - new Thread(this).start(); - } - - public Dimension getPreferredSize() { - return new Dimension(WIDTH, HEIGHT); - } - - public static void main(String[] args) { - Frame f = new Frame(DEVNAME); - f.add(new QCam()); - f.pack(); - f.setVisible(true); - } - - /** The run method: sleep a bit, take another picture, ... */ - public void run() { - Thread me = Thread.currentThread( ); - me.setPriority(Thread.MIN_PRIORITY); - - while (true) { - try { - Thread.sleep(2000 /* 60*FPS/1000 */); //XXX - } catch( InterruptedException e ) { - return; - } - - System.out.println("tick"); - - // Modify the values in the data array - try { - camFile = new RandomAccessFile(fileObj, "r"); - camFile.read(data); - camFile.close(); - } catch(IOException e) { - System.err.println("seek/read: " + e); - return; - } - - // Send the new data to the interested ImageConsumers - source.newPixels(0, 0, WIDTH, HEIGHT); - - // reload the image. - im = createImage(source); - - // Update the screen - repaint(); - } - } - - public void paint(Graphics g) { - if (im != null) { - System.out.println("paint()"); - g.drawImage(im, 0, 0, this); - } else { - throw new IllegalStateException("paint(): im == null!"); - } - } -} diff --git a/buildindex.xml b/buildindex.xml new file mode 100644 index 000000000..737ead974 --- /dev/null +++ b/buildindex.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/compat/ArrayList.java b/src/main/java/compat/ArrayList.java index 1eff2f77f..321d98286 100644 --- a/src/main/java/compat/ArrayList.java +++ b/src/main/java/compat/ArrayList.java @@ -1,6 +1,9 @@ package java.util; -/** Crudely map Vector to ArrayList, for compatibility. */ +/** Crudely map Vector to ArrayList, for "compatibility", + * that is, for use with ArrayList-based code on really ancient JDK. + * Don't do that anymore; this is really olde code. Time to upgrade. + */ public class ArrayList { Vector v; diff --git a/src/main/java/database/jdbc/TypeMapDemo.java b/src/main/java/database/jdbc/TypeMapDemo.java new file mode 100644 index 000000000..63440fa45 --- /dev/null +++ b/src/main/java/database/jdbc/TypeMapDemo.java @@ -0,0 +1,81 @@ + import java.sql.*; + import java.util.*; + import java.io.*; + + * Following up on the javadoc for java.sql.Connection, + * make a TypeMap that maps a *structured* UDT into a + * MusicRecording "automatically". + * @author Ian Darwin + */ +public class TypeMapDemo { + public static void main(String[] args) + throws IOException, ClassNotFoundException, SQLException { + + Properties p = new Properties(); + p.load(new FileInputStream("db.properties")); + Class c = Class.forName(p.getProperty("db.driver")); + System.out.println("Loaded driverClass " + c.getName()); + + Connection con = DriverManager.getConnection( + p.getProperty("db.url"), + "student", "student"); + System.out.println("Got Connection " + con); + + Statement s = con.createStatement(); + int ret; + try { + s.executeUpdate("drop table MR"); + s.executeUpdate("drop type MUSICRECORDING"); + } catch (SQLException andDoNothingWithIt) { + // Should use "if defined" but not sure it works for UDTs... + } + ret = s.executeUpdate( + "create type MUSICRECORDING as object (" + + " id integer," + + " title varchar(20), " + + " artist varchar(20) " + + ")"); + System.out.println("Created TYPE! Ret=" + ret); + + ret = s.executeUpdate( + "create table MR of MUSICRECORDING"); + System.out.println("Created TABLE! Ret=" + ret); + + int nRows = s.executeUpdate( + "insert into MR values(123, 'Greatest Hits', 'Ian')"); + System.out.println("inserted " + nRows + " rows"); + + + // Put the data class into the connection's Type Map + // If the data class were not an inner class, + // this would likely be done with Class.forName(...); + Map map = con.getTypeMap(); + map.put("MUSICRECORDING", MusicRecording.class); + con.setTypeMap(map); + + ResultSet rs = s.executeQuery( + "select * from MR where id = 123"); + //"select musicrecording(id,artist,title) from mr"); + rs.next(); + for (int i=1; i<=rs.getMetaData().getColumnCount(); i++) { + Object o = rs.getObject(i); + System.out.print(o + "(Type " + + o.getClass().getName() + ")\t"); + } + System.out.println(); + } + + /** + * Simplified local copy of MusicRecording, so this pgm can stand alone. + * This is an inner class just for illustrative purposes; + * it would normally be an unrelated data class. + */ + public class MusicRecording { + int id; + String title; + String artist; + public String toString() { + return "MusicRecording#"+id+"["+artist+"--"+title+"]"; + } + } +} diff --git a/src/main/java/database/jdbc/db.properties b/src/main/java/database/jdbc/db.properties new file mode 100644 index 000000000..d54d24885 --- /dev/null +++ b/src/main/java/database/jdbc/db.properties @@ -0,0 +1,14 @@ +# JDBC Properties + +# Connection information for the Oracle database on the server +db.driver = oracle.jdbc.driver.OracleDriver +#db.url = jdbc:oracle:thin:@server:1521:db570 +db.url = jdbc:oracle:thin:@ltree7:1521:db570 + +# Connection information for the Access database on the local machine +# db.driver = sun.jdbc.odbc.JdbcOdbcDriver +# db.url = jdbc:odbc:RainForestDSN + +# userId and password for the database connection +db.user = student +db.password = student diff --git a/src/main/java/miles2kms/Miles2Kms.java b/src/main/java/miles2kms/Miles2Kms.java index 24918afeb..f3806501f 100755 --- a/src/main/java/miles2kms/Miles2Kms.java +++ b/src/main/java/miles2kms/Miles2Kms.java @@ -1,5 +1,3 @@ -// DO NOT USE -- in transition... - import java.awt.*; import java.awt.event.*; import java.applet.*; @@ -7,9 +5,10 @@ /** * A simple applet panel - miles <==> kilometers - * - * @author Ian Darwin, after a temperature demo by Arthur van Hoff. + * @author Ian Darwin, based loosely on a long-ago temperature demo + * by Arthur van Hoff. * Reworked as an "observable" demo after an example (FtoC) from Course 477. + * Should add text listeners on the textfields... */ public class Miles2Kms extends Applet { Scrollbar sb; @@ -17,11 +16,15 @@ public class Miles2Kms extends Applet { MyModel model; public void init() { - setLayout(new BorderLayout()); - add("North", miles = new LabelTextField('m', "Miles", 10)); - add("Center", sb = new Scrollbar(Scrollbar.VERTICAL, - 0, 1, 0, 239)); - add("South", kms = new LabelTextField('k', "Kilometers", 10)); + Panel pl, pr; + pl = new Panel(); + pr = new Panel(); + pl.setLayout(new BorderLayout()); + pl.add(BorderLayout.NORTH, miles = new LabelTextField('m', "Miles", 10)); + pr.add(sb = new Scrollbar(Scrollbar.VERTICAL, 0, 1, -240, 0)); + pl.add(BorderLayout.SOUTH, kms = new LabelTextField('k', "Kilometers", 10)); + add(pr); + add(pl); model = new MyModel(); model.addObserver(miles); @@ -98,6 +101,6 @@ class MyAdjustmentListener implements AdjustmentListener { this.model = model; } public void adjustmentValueChanged( AdjustmentEvent e ) { - model.setMiles( e.getValue() ); + model.setMiles( -e.getValue() ); } } diff --git a/src/main/java/native1_1/HelloWorld.java b/src/main/java/native1_1/HelloWorld.java index 2ebc4d362..daef88ee9 100755 --- a/src/main/java/native1_1/HelloWorld.java +++ b/src/main/java/native1_1/HelloWorld.java @@ -21,6 +21,7 @@ public static void main(String[] args) { // Static code blocks are executed once, when class file is loaded static { - System.load("libhello.so"); + System.load(System.getProperty("java.user.directory") + "/" + + "libhello.so"); } } diff --git a/src/main/java/native1_1/Makefile b/src/main/java/native1_1/Makefile index faa2e06c8..f4240c8d2 100644 --- a/src/main/java/native1_1/Makefile +++ b/src/main/java/native1_1/Makefile @@ -1,63 +1,67 @@ -# Makefile for the 1.1 Java Native Methods examples for -# Learning Tree International Course 471/478. -# Has been tested on Solaris both with "gcc" and with SunSoft "cc". -# On other platforms it will certainly need some tweaking; please -# let me know how much! :-) -# Ian Darwin, ian@darwinsys.com, http://www.darwinsys.com - -# $Id$ - -# Configuration Section - -CSRCS = HelloWorld.c -JAVAHOME = /local/jdk1.1.2 -INCLUDES = -I$(JAVAHOME)/include -I$(JAVAHOME)/include/solaris -LIBDIR = $(JAVAHOME)/lib/sparc/green_threads -CLASSPATH = $(JAVAHOME)/lib/classes.zip:. - -all: testhello testjavafromc - -# This part of the Makefile is for C called from Java, in HelloWorld -testhello: hello.all - @echo - @echo "Here we test the Java code \"HelloWorld\" that calls C code." - @echo - LD_LIBRARY_PATH=`pwd`:. java HelloWorld - -hello.all: HelloWorld.class libhello.so - -HelloWorld.class: HelloWorld.java - javac HelloWorld.java - -HelloWorld.h: HelloWorld.class - javah -jni HelloWorld - -HelloWorld.o:: HelloWorld.h - -libhello.so: $(CSRCS) HelloWorld.h - $(CC) $(INCLUDES) -G $(CSRCS) -o libhello.so - -# This part of the Makefile is for Java called from C, in javafromc -testjavafromc: javafromc.all hello.all - @echo - @echo "Now we test HelloWorld using javafromc instead of java" - @echo - LD_LIBRARY_PATH="$(LIBDIR):." CLASSPATH="$(CLASSPATH)" ./javafromc HelloWorld - @echo - @echo "That was, in case you didn't notice, C->Java->C. And," - @echo "incidentally, a replacement for JDK program \"java\" itself!" - @echo - - -javafromc.all: javafromc - -javafromc: javafromc.o - $(CC) -L$(LIBDIR) javafromc.o -ljava -o $@ - -javafromc.o: javafromc.c - $(CC) -c $(INCLUDES) javafromc.c - -clean: - rm -f core *.class *.o *.so HelloWorld.h -clobber: clean - rm -f javafromc +# Makefile for the 1.1 Java Native Methods examples for +# Learning Tree International Course 471/478. +# Has been tested on Solaris both with "gcc" and with SunSoft "cc". +# On other platforms it will certainly need some tweaking; please +# let me know how much! :-) +# Ian Darwin, ian@darwinsys.com, http://www.darwinsys.com + +# $Id$ + +# Configuration Section + +CFLAGS_FOR_SO = -G # Solaris +CFLAGS_FOR_SO = -shared +CSRCS = HelloWorld.c +#JAVAHOME = /local/jdk1.1.2 +JAVAHOME = /usr/local/jdk-1.2.2 +#INCLUDES = -I$(JAVAHOME)/include -I$(JAVAHOME)/include/solaris +INCLUDES = -I$(JAVAHOME)/include -I$(JAVAHOME)/include/openbsd +LIBDIR = $(JAVAHOME)/lib/sparc/green_threads +CLASSPATH = $(JAVAHOME)/lib/classes.zip:. + +all: testhello testjavafromc + +# This part of the Makefile is for C called from Java, in HelloWorld +testhello: hello.all + @echo + @echo "Here we test the Java code \"HelloWorld\" that calls C code." + @echo + LD_LIBRARY_PATH=`pwd`:. java HelloWorld + +hello.all: HelloWorld.class libhello.so + +HelloWorld.class: HelloWorld.java + javac HelloWorld.java + +HelloWorld.h: HelloWorld.class + javah -jni HelloWorld + +HelloWorld.o:: HelloWorld.h + +libhello.so: $(CSRCS) HelloWorld.h + $(CC) $(INCLUDES) $(CFLAGS_FOR_SO) $(CSRCS) -o libhello.so + +# This part of the Makefile is for Java called from C, in javafromc +testjavafromc: javafromc.all hello.all + @echo + @echo "Now we test HelloWorld using javafromc instead of java" + @echo + LD_LIBRARY_PATH="$(LIBDIR):." CLASSPATH="$(CLASSPATH)" ./javafromc HelloWorld + @echo + @echo "That was, in case you didn't notice, C->Java->C. And," + @echo "incidentally, a replacement for JDK program \"java\" itself!" + @echo + + +javafromc.all: javafromc + +javafromc: javafromc.o + $(CC) -L$(LIBDIR) javafromc.o -ljava -o $@ + +javafromc.o: javafromc.c + $(CC) -c $(INCLUDES) javafromc.c + +clean: + rm -f core *.class *.o *.so HelloWorld.h +clobber: clean + rm -f javafromc diff --git a/src/main/java/servlet/inst b/src/main/java/servlet/inst deleted file mode 100755 index 81c07a57b..000000000 --- a/src/main/java/servlet/inst +++ /dev/null @@ -1,2 +0,0 @@ -cp PDFCouponServlet.htm ~/webs/daroadweb -sudo cp PDFCouponServlet.class /var/www/servlets diff --git a/src/main/java/tools/build.xml b/src/main/java/tools/build.xml new file mode 100644 index 000000000..4a21e1450 --- /dev/null +++ b/src/main/java/tools/build.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stylesheet.css b/stylesheet.css new file mode 100644 index 000000000..46208f73a --- /dev/null +++ b/stylesheet.css @@ -0,0 +1,30 @@ +/* Style Sheet for Java Cookbook web site. + * This is the web: go ahead and borrow this page, but change it for + * your own web, and pass it on with the same terms of re-use. + * $Id$ + */ + +/* Attributes named after an HTML element apply to all occurrences of type. */ + +/* Page attributes */ +body { background-color: #FFFFFF; color: #000; + link-color: #000; vlink-color: #660099; alink-color: #FF0000 +} + +/* Paragraph formats: use generic, non-vendor specific names (no Arial) */ +H1 { color: #000; font-family: Helvetica, sans-serif } +H2 { color: blue; font-family: Helvetica, sans-serif } +H3 { color: blue; font-family: Helvetica, sans-serif } + +/* Attributes named with a "#" can apply to any element but only if ID= used. */ + +/* Heading colors */ +#TextAbout { color: #0000FF; font-family: Helvetica, sans-serif } /* blue */ + +/* Table cell colors */ +#TableNav { background-color: #00cc33; cellpadding: 5} + +/* Link colors */ +#LinkLocal { color: #00FF00 } /* green */ +#LinkRemote { color: #ff0000 } /* red */ +