[4756] in java-interest

home help back first fref pref prev next nref lref last post

The GraphicsApplet.java in Hooked on Java book

daemon@ATHENA.MIT.EDU (Fritz N. Francis)
Fri Jan 12 14:15:56 1996

To: java-interest@java.sun.com
From: fritz@environs.com (Fritz N. Francis)
Date: Fri, 12 Jan 1996 11:52:13 -0500

Hello,


Thanks to everyone who respnonded to the HelloWorld example that I posted a
few days ago.
I didn't realize that I had a stupid mistake in where the code attribute was
pointing to; instead of having

<applet code="HelloWorld.class">

I had:

<applet code="HelloWorldApp.class">

where HelloWorldApp is a standalone application.


The next question I have deals with an example that comes straight out from
the Hooked on Java book.
This example is on page 131: 

/* File: ButtonExample.java */
/* Line 1: */
import java.awt.*;
/* Line 2: */
public class ButtonExample extends Frame {                             /*
Line 3: */
  public ButtonExample() {
/* Line 4: */     
    setTitle("ButtonExample");
/* Line 5: */     
    setLayout(new FlowLayout());
/* Line 6: */
    add(new Button("Push Me"));
/* Line 7: */
    pack();
/* Line 8: */
    show();
/* Line 9: */
  }
/* Line 10: */
  public boolean action(Event e, Object arg) {
/* Line 11: */         
    System.out.println(((Button)e.target).getLabel());
/* Line 12: */
  }
/* Line 13: */
  public static void main(String args[]) {
/* Line 14: */
    new ButtonExample();
/* Line 15: */
  }
/* Line 16: */
}
/* Line 17: */

After saving this and trying to compile it, I receive the error message:

ButtonExample.java:14: Return required at the end of boolean
action(java.awt.Event, 
  public boolean action (Event e, Object arg) {

1 error

I have several questions about this program:

1) What's wrong with it especially since it came straght from the book?

2) What is that weird construction in Line 12? I know the syntax is
<Class>.<method>(arguments):
So if getlabel() is the method; then what type of class is
((Button)e.target) ? Can someone explain what this line is doing, since the
book only explains up to Line 9?

3) What does the number 14 mean in the compile error message? Is that the
line number with the error?

Thanks,

Fritz

-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post