WindowCloser, Exception 1FE, elementsAndMass errors in this code - help?

Hi. I got the following code from Java Programming for Absolute Beginners. I think this book was written for JDK 5, and maybe the issues surrounding this have to do with the fact tha I entered it into JDK 6, but I'm not sure. I've entered it into Eclipse, and am getting messages like: WindowCloser cannot be resolved to a type, Syntax error on token 1F, and elementsAndMass cannot be resolved. I would appreciate any help you could offer.

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

public class LabView extends JFrame {

//#1

private JTextArea frameTextArea;//create a text area

private Container frameContainer;//for the content pane

private JScrollPane scrollForTextArea;//scrollbar

private BorderLayout frameLayout;

final int width = 640, height = 480;

//#2

private JMenuBar bar;

private JMenu fileMenu, editMenu, helpMenu, programMenu;

private JMenuItem saveText, closeApp, clearText,

aboutThisApp,

programA,

programB,

programC;

//#3

public LabView(String title) {

//call to JFrame constructor

super(title);

//call initialization

init();

}

public void init() {

//#4

//use the WindowCloser class

addWindowListener(new WindowCloser());

//#5

//set up the window for the operating system

setLookAndFeel();

//#6

//get the content pane

frameContainer = getContentPane();

//create an instance of a JTextArea

frameTextArea = new JTextArea("\n \t Element \t Weight \n", 18, 70);

//configure the JTextArea

frameTextArea.setEditable(false);

frameTextArea.setLineWrap(true);

//set the text area in the scroll pane

scrollForTextArea = new JScrollPane(frameTextArea);

//#7

//create an instance of a border layout

frameLayout = new BorderLayout();

frameContainer.add(scrollForTextArea, BorderLayout.CENTER);

//size the JFrame and set it to visible

setVisible(true);

setSize(height, width);

//#8 add a menu

makeMenu();

//#9

//this will provide both

//if the lineWrap() method is false

pack();

showElements();

}

//--setLookAndFeel()-

//#5.1

public void setLookAndFeel() {

try {

String lookAndFeel = UIManager.getSystemLookAndFeelClassName();

UIManager.setLookAndFeel(lookAndFeel);

}

catch(Exception 1FE) {

//process exception

}

}

//#8.1makeMenu()--

public void makeMenu() {

//create a menu bar

bar = new JMenuBar();

//create a file menu

fileMenu = new JMenu("File");

fileMenu.setMnemonic('S');

closeApp = new JMenuItem("Close");

closeApp.setMnemonic('C');

//add the File items to File menu

fileMenu.add(saveText);

fileMenu.add(closeApp);

//create Edit menu

editMenu = new JMenu("Edit");

editMenu.setMnemonic('E');

//with menu items

clearText = new JMenuItem("Clear Text");

clearText.setMnemonic('X');

//add the Edit items to the Edit menu

editMenu.add(clearText);

//create Help menu

helpMenu = new JMenu("Help");

helpMenu.setMnemonic('H');

//with menu items

aboutThisApp = new JMenuItem("About...");

aboutThisApp.setMnemonic('A');

//add the Help items to the Help menu

helpMenu.add(aboutThisApp);

//create Programs menu

programMenu = new JMenu("Programs");

programMenu.setMnemonic('P');

//with menu items

programA = new JMenuItem("Program A");

programB = new JMenuItem("Program B");

programC = new JMenuItem("Program C");

//add the Programs menu items to Programs menu

programMenu.add(programA);

programMenu.add(programB);

programMenu.add(programC);

//add File, Edit, Help, and Programs to bar

bar.add(fileMenu);

bar.add(editMenu);

bar.add(helpMenu);

bar.add(programMenu);

//add the menu bar to the content pane

setJMenuBar(bar);

}//end makeMenu

//#9.1--showElements-

public void showElements() {

//create a string

String elementsAtomicMass =

"Oxygen,15.9994,Fluorine,18.9984032,"+

"Neon,20.1797,Zinc,65.39,"+

"Magnesium,24.3050,Aluminum,26.981528,"+

"Silicon,28.0855,Phosphorus,30.973761,"+

"Sulfur,32.065,Chlorine,35.453,"+

"Potassium,39.0983,Calcium,40.078,"+

"Vanadium,50.9415,Manganese,54.938049,"+

"Yttrium,88.90585,Germanium,72.64,"+

"Barium,137.327,Bismuth,208.98038,"+

"Calcium,40.078,";

//split the string into array elements

String elementsandMass[] = elementsAtomicMass.split(",\\s");

//increment by 2s to see both columns

//subtract 1 to allow counting by 2s

for(int cntr = 0; cntr < elementsAndMass.lenth - 1; cntr += 2) {

frameTextArea.append("\n\t");

frameTextArea.append(elementsAndMass[cntr]

+ "\t"

+ elementsAndMass[cntr+1]

);

}

}

//#3.1-main()

public static void main(String args[]) {

new LabView("Lab View A");

}

}

[5276 byte] By [WindowClosera] at [2007-11-27 5:25:41]
# 1

> String elementsandMass[] = elementsAtomicMass.split(",\\s");

Your elementsAndMass problem is due to a typo (elementsandMass != elementsAndMass). I'd imagine that the WindowCloser class was written somewhere else in the chapter... it's simply not there, and you're referring to it.

kevjavaa at 2007-7-12 14:45:56 > top of Java-index,Java Essentials,New To Java...