File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What kind of error is this?

 
nani aman
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, its me again with a lot of blurr..
i had this error in my second class. It seem like lack of something but i couldn't figure it out. What actually i need to do?\

error :
addItemListener(java.awt.event.ItemListener) in javax.swing.AbstractButton cannot be applied to Class2.java

i hope someone can show me the way..
Thank you.
 
Ben Wood
Ranch Hand
Posts: 342
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe some code would help, but my guess is that you have not called the add method on an actual component (button?)

e.g.

 
nani aman
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is some codes that used addItemListener, this is not button but a check box. bFinish is the only button i use in here.

qchk1Yes.addItemListener(this);
qchk1No.addItemListener(this);
qchk2Yes.addItemListener(this);
bFinish.addItemListener(this);

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});

thanks..
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure your class is implementing the ItemListener interface?
 
nani aman
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i implemented the action listener in the class. I change qchk1Yes.addItemListener(this) to qchk1Yes.addActionListener but i still could get why they is error.
 
J Chandler
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi nani,

when we want to implement a Listener interface, we need to declare it
somewhere so the compiler knows.
That means either making our own listener class to handle all the methods
in the listener interface ...
OR, what would be best in this case, because ItemListener has only 1 method - itemStateChanged - we could simply state that we are implementing the ItemListener interface when declaring the class.

Example:-


and don't forget to code your own itemStateChanged method in Class2 - if the compiler knows you want to use ItemListener, it will be looking for your implementation of this method.

Example:-

hope that helps

[ October 19, 2004: Message edited by: J Chandler ]

[ October 19, 2004: Message edited by: J Chandler ]
[ October 19, 2004: Message edited by: J Chandler ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic