Click to See Complete Forum and Search --> : Error in compiling Inner class
ANANI
05-04-2001, 09:38 AM
I can't compile the following program. Can anyone help me with this.
---------------------------------
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Applet1 extends Applet {
public void init() {
Button button1 = new Button("Clear");
Button button2 = new Button("Send");
TextField textField1 = new TextField();
SymAction lSymAction = new SymAction();
button1.addActionListener(lSymAction);
button2.addActionListener(lSymAction);
}
class SymAction implements ActionListener
{
public void actionPerformed( ActionEvent event)
{
Object object = event.getSource();
if (object == button1) textField1.setText("");
if (object == button2) doSend( textField1.getText() );
}
}
}
Check your if condition syntex
"ANANI" <g_anani@hotmail.com> wrote:
>
>I can't compile the following program. Can anyone help me with this.
>---------------------------------
>import java.awt.*;
>import java.awt.event.*;
>import java.applet.*;
>
>public class Applet1 extends Applet {
> public void init() {
> Button button1 = new Button("Clear");
> Button button2 = new Button("Send");
> TextField textField1 = new TextField();
>
> SymAction lSymAction = new SymAction();
> button1.addActionListener(lSymAction);
> button2.addActionListener(lSymAction);
> }
> class SymAction implements ActionListener
> {
> public void actionPerformed( ActionEvent event)
> {
> Object object = event.getSource();
> if (object == button1) textField1.setText("");
> if (object == button2) doSend( textField1.getText() );
> }
>}
>}
Paul Clapham
05-04-2001, 11:25 AM
When you can't compile a program, you get some kind of error messages that
tell you what the problem is. You have to look at these messages and fix
the problems they tell you about.
Since you haven't told us what the error messages are, we can't do much for
you.
PC2
"ANANI" <g_anani@hotmail.com> wrote in message
news:3af2b0ca$1@news.devx.com...
>
> I can't compile the following program. Can anyone help me with this.
> ---------------------------------
> import java.awt.*;
> import java.awt.event.*;
> import java.applet.*;
>
> public class Applet1 extends Applet {
> public void init() {
> Button button1 = new Button("Clear");
> Button button2 = new Button("Send");
> TextField textField1 = new TextField();
>
> SymAction lSymAction = new SymAction();
> button1.addActionListener(lSymAction);
> button2.addActionListener(lSymAction);
> }
> class SymAction implements ActionListener
> {
> public void actionPerformed( ActionEvent event)
> {
> Object object = event.getSource();
> if (object == button1) textField1.setText("");
> if (object == button2) doSend( textField1.getText() );
> }
> }
> }
You have many mistakes in your classes
1- Button1, Button2, and textField1 are all declared inside the init() method
therefore they are local objects and not visible outside this method. Declare
them outside the method and initialize them in the method.
2- dont use == to test equality for object types in java use equals method
instead. e.g. if(event.getSource().equals(Button1)) .......
3- doSend(String s) is not defined anywhere.
Good Luck
Ako
"ANANI" <g_anani@hotmail.com> wrote:
>
>I can't compile the following program. Can anyone help me with this.
>---------------------------------
>import java.awt.*;
>import java.awt.event.*;
>import java.applet.*;
>
>public class Applet1 extends Applet {
> public void init() {
> Button button1 = new Button("Clear");
> Button button2 = new Button("Send");
> TextField textField1 = new TextField();
>
> SymAction lSymAction = new SymAction();
> button1.addActionListener(lSymAction);
> button2.addActionListener(lSymAction);
> }
> class SymAction implements ActionListener
> {
> public void actionPerformed( ActionEvent event)
> {
> Object object = event.getSource();
> if (object == button1) textField1.setText("");
> if (object == button2) doSend( textField1.getText() );
> }
>}
>}
devx.com
Copyright Internet.com Inc. All Rights Reserved