DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005
    Posts
    6

    Can't add action listener

    Got a small prob maybe someone could help me if you have time. I get an error message saying that it can't apply the actionlistener to the code
    Thanks in advance
    PS
    I'm using JCreator Pro

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

    public class Iceb extends Applet {
    Button ok = new Button("Encrypt");
    TextField input = new TextField("Enter your text here");
    TextField output = new TextField("");
    TextField title = new TextField("");
    Button br = new Button("Decrypt");
    Color bg;
    public void init() {
    setLayout(null);
    ok.setBounds(50,60,80,30);
    br.setBounds(140,60,80,30);
    input.setBounds(50,100,300,50);
    bg = Color.black;
    setBackground(bg);
    ok.addActionListener(this);
    br.addActionListener(this);
    input.addActionListener(this);
    output.addActionListener(this);
    add(ok);
    add(br);
    add(input);
    }

    public void paint(Graphics g) {
    g.setColor(bg);
    }
    public void actionPerformed(ActionEvent evt) {
    if(evt.getSource == ok)
    input.setText("You just pressed the Encrypt button");
    }
    }
    Last edited by vxfox05; 04-29-2005 at 01:58 PM.

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    Your class hasn't implemented the ActionListener class, so the statements
    Code:
    ok.addActionListener(this);
    br.addActionListener(this);
    input.addActionListener(this);
    output.addActionListener(this);
    are not valid, because this is not an ActionListener.

  3. #3
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468

    action listener

    So declare your class:


    public class Iceb extends Applet implements ActionListener
    {

  4. #4
    Join Date
    Apr 2005
    Posts
    6
    ah, ok, thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links