wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes JList error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JList error" Watch "JList error" New topic
Author

JList error

Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
Hi all.

Getting there slowly but miffied about this:


C:\Users\rob\Documents\TextArea1.java:72: cannot find symbol
symbol : class ListSelectionEvent
location: class TextArea1.ListBoxClick
public void valueChanged(ListSelectionEvent lse) {
^
C:\Users\rob\Documents\TextArea1.java:40: addListSelectionListener(javax.swing.event.ListSelectionListener) in javax.swing.JList cannot be applied to (TextArea1.ListBoxClick)
list.addListSelectionListener(new ListBoxClick());
^
C:\Users\rob\Documents\TextArea1.java:71: TextArea1.ListBoxClick is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
class ListBoxClick implements ActionListener {
^
3 errors

Tool completed with exit code 1


Thanks in advance.

Rob.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11150
    
  16

I'm not 100% sure, but I think when you do

import javax.swing.*;

you only get the first level below "javax.swing"

However, the ListSelectionEvent is two levels below:

javax.swing.event.ListSelectionEvent

So I would either explicitly import that, or import this:

import javax.swing.event.*;


note: I have not tried this, it's a somewhat educated guess.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
Tried what you suggested fred but still get the same error.
Dielson Sales
Greenhorn

Joined: Feb 02, 2011
Posts: 4

Rob Brew wrote:Tried what you suggested fred but still get the same error.

It must be another error. Could you post the error again, when you try to import everything?
Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
Sure.


C:\Users\Rob\Documents\TextArea1.java:41: addListSelectionListener(javax.swing.event.ListSelectionListener) in javax.swing.JList cannot be applied to (TextArea1.ListBoxClick)
list.addListSelectionListener(new ListBoxClick());
^
C:\Users\Rob\Documents\TextArea1.java:72: TextArea1.ListBoxClick is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
class ListBoxClick implements ActionListener {
^
2 errors

Tool completed with exit code 1
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11150
    
  16

So how is going from 3 errors to 2 errors the same thing?
Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
Sorry Fred, will repost the code.

Dielson Sales
Greenhorn

Joined: Feb 02, 2011
Posts: 4

Think you're getting this error because you're implementing ActionListener in you class ListBoxClick, and the method addListSelectionListener asks for a ListSelectionListener. Both extend EventListener, but they are different.

You should implement ListSelectionListener and override the method valueChanged.
Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
Sorted, thanks Dielson
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JList error
 
Similar Threads
JList deselection problem
What listener to implement for JList?
implementing ActionListener and ItemListener
JTextArea page 415 of Head First Java
JRadioButtonList error