Solved

Applet, TextField, addActionListener

Posted on 1998-02-24
3
1,380 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
Comment Utility
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
Comment Utility
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 100 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now