Skip to main content

Need help with code

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2013-03-10

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.*;

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("");
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 =;
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

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2013-03-27

Hi, you can't use the literal number one for a variable name. :)

Also, use the code tags (button with <>) when posting code so it is readable.