Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Applet, TextField, addActionListener

Posted on 1998-02-24
3
Medium Priority
?
1,397 Views
Last Modified: 2013-11-23
I have trouble with a TextField within an applet. I just want a simple TextField and add an ActionListener but
ist doesn´t work right.
Here is the code:

import java.awt.event.*;
import java.applet.*;
import java.lang.*;
import java.awt.*;

public class testapp extends Applet implements ActionListener {

    TextField tf;

    public void init() {
        setLayout(null);
        tf = new TextField("Meier",20);
        tf.addActionListener(this);
        add(tf);
    }
   
    public void actionPerformed (ActionEvent e) {
        Object obj = e.getSource();
        if ( obj instanceof TextField )
           System.out.println ("Field " + e.getActionCommand() );
    }    

    public void start(){
        System.out.println("Applet: start()...");
    }

    public void stop(){
       System.out.println("Applet: stop()...");
    }

    public void destroy() {
       System.out.println("Applet: destroy()...");

    }      
}

I can compile the programm without any errors and warings but when displaying I get this error mesage:

# Applet exception: error: java.lang.NoSuchMethodError: java.awt.TextField: method addActionListener (Ljava/awt/event/ActionListener;)V not found
java.lang.NoSuchMethodError: java.awt.TextField: method addActionListener (Ljava/awt/event/ActionListener;)V not found

Where is the problem ?

Guido
0
Comment
Question by:experte
3 Comments
 

Expert Comment

by:kls1
ID: 1233237
What are you using to display it?  Appletviewer...or a browser like Netscape? If Netscape, make sure you have the jdk 1.1 patches.
0
 

Author Comment

by:experte
ID: 1233238
Hi !
Yes, I forgot to tell you, I use the Netscape Communicator and I use
JDK 1.1.3
Guido
0
 
LVL 1

Accepted Solution

by:
datadesign earned 300 total points
ID: 1233239
But do u have the jdk 1.1 patch for the Communicator ?
If not, install the patch, and the Applet should work without any problems ! (Applet running in your browser, dont access the jdk 1.1.3 u have installed, they use their own VM.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question