Very useful indeed. Perhaps we should think about an org.biojava.Dilbert package heirarchy? :)
-----Original Message----- From: Russell Smithies [mailto:[EMAIL PROTECTED] Sent: Friday, July 18, 2003 4:12 PM To: [EMAIL PROTECTED] Org Subject: [Biojava-l] not biojava... ...... but a useful peice of code everyone should have ;-) --------------------------------------------------------- import java.io.*; import java.net.URL; import javax.swing.*; public class DilbertComic { public static String todaysDilbert() throws IOException { // open up the webpage to today's comic URL url = new URL("http://www.dilbert.com"); BufferedReader webRead = new BufferedReader( new InputStreamReader(url.openStream())); String line; while ((line = webRead.readLine()) != null) { if (line.indexOf("ALT=\"Today's Dilbert Comic\"") != -1) { int offset = line.indexOf( "<IMG SRC=\"/comics/dilbert/archive/images/dilbert"); line = line.substring(offset + 10); return "http://www.dilbert.com" + line.substring(0, line.indexOf('"')); } } return null; } public static void download(URL url, File file) throws IOException { InputStream in = url.openStream(); FileOutputStream out = new FileOutputStream(file); byte[] b = new byte[1024]; int len; while((len = in.read(b)) != -1) { out.write(b, 0, len); } out.close(); } public static void main(String[] args) throws IOException { System.out.println("Looking for today's dilbert comic . . ."); String today = todaysDilbert(); if (today == null) { System.out.println("Could not find today's dilbert comic!"); } else { System.out.println("Found today's dilbert: " + today); URL url = new URL(today); // download it as an ImageIcon and show it in a JFrame. System.out.println("Downloading the Image . . ."); ImageIcon im = new ImageIcon(url); System.out.println("Downloaded the Image"); JFrame f = new JFrame("Today's Dilbert"); f.getContentPane().add(new JLabel(im)); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.show(); } } } --------------------------------------------------------------- _______________________________________________ Biojava-l mailing list - [EMAIL PROTECTED] http://biojava.org/mailman/listinfo/biojava-l _______________________________________________ Biojava-l mailing list - [EMAIL PROTECTED] http://biojava.org/mailman/listinfo/biojava-l