-
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.
-
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.
-
action listener
So declare your class:
public class Iceb extends Applet implements ActionListener
{
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks