Click here to Skip to main content
15,888,081 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java JList error in my code?
When i create a class called inner and add the rest of the code in netbeans it underlines the inner word with a red line , what is wrong ? and how do i fix this ?

Java
package test;

import javax.swing.*;
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class Main {
public static void main(String[] args) {
fr gui = new fr();
gui.go();

}
}

class fr{

JList list;

public void go(){
JFrame frame = new JFrame();
String enteries[] = {"Delta" , "Tango" , "fed"};
list = new JList(enteries);
JPanel panel = new JPanel();

frame.setSize(300,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EX…
frame.getContentPane().add(BorderLayout.…
panel.add(list);

JScrollPane scroller = new JScrollPane(list);
scroller.setVerticalScrollBarPolicy(Scro…
scroller.setHorizontalScrollBarPolicy(Sc…
panel.add(scroller);

list.setVisibleRowCount(4);
list.setSelectionMode(ListSelectionModel…

list.addListSelectionListener(new inner());
}

class inner implements ListSelectionListener{ // the inner word is underlined in red why ?
public void valueChaned(ListSelectionEvent lse){

if(!lse.getValueIsAdjusting()){
String selection = (String) list.getSelectedValue();
JOptionPane.showMessageDialog(null,selec…
}
}


}
}
Posted
Updated 12-Oct-11 11:02am
v2

inner classes are called anonymous classes - and I can't see something wrong with the declaration - beside of the fact that the class name is starting lower case, which leads to the red underline.

Please use a proper IDE for coding - Eclipse and Netbeans are free and will notify you of such things.

EDIT: the class fr is also named incorrect. Also please make these all separated files, the class fr can extend JFrame - very elegant, and the class inner should be called frController or frWorker (according to the name of the GUI-part). The rest look really good!
 
Share this answer
 
v3
It's not implementing the interface, you've misspelled the method name.
It should be valueChanged, not valueChaned.

Hope this helps,
Fredrik
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900