5 Replies Latest reply on Mar 12, 2013 3:35 AM by EJP

    Need help finding the error in my code

      I'm currently learning Java with SAMS "Teach yourself Java in 21 days" and I've
      hit a road block I'm unable to find a resolution. I'm implementing a 4 step
      technique to open a connection to a WEB site and read an HTML doc from it but
      the code compiles with errors that i can't seem to find. The declaration of
      WindowListener 1 = new WindowAdapter() is where the errors begin in the NetBeans
      IDE but it's exactly how the book wrote. Please help.

      import java.awt.*;
      import java.awt.event.*;
      import java.net.*;
      import java.io.*;

      public class GetFile extends Frame implements Runnable {
      Thread runner;
      URL page;
      TextArea box = new TextArea("Getting text...");

      public GetFile() {
      super("Get File");
      try {
      page = new URL("http://quanhodges.com/Bio.html");
      catch (MalformedURLException e) {
      System.out.append("Bad URL: " + page);
      public static void main(String[] arguments) {
      GetFile frame = new GetFile();

      WindowListener 1 = new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
      if (frame.runner == null) {
      frame.runner = new Thread(frame);
      public void run() {
      URLConnection conn = null;
      InputStreamReader in;
      BufferedReader data;
      String line;
      StringBuffer buf = new StringBuffer();
      try {
      conn = this.page.openConnection();
      box.setText("Connection opened...");
      in = new InputStreamReader(conn.getInputStream());
      data = new BufferedReader(in);
      box.setText("Reader data...");
      while ((line = data.readLine()) != null) {
      buf.append(line + "\n");
      catch (IOException e) {
      System.out.println("IO Error:" + e.getMessage());

      Sincerely, Quan Hodges