Java JList错误问题 [英] Java JList error problem

查看:93
本文介绍了Java JList错误问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中的Java JList错误?
当我创建一个名为inner的类并将其余代码添加到netbeans中时,它用红线在内部单词下划线,这是怎么回事?以及我该如何解决?

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 ?

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…
}
}


}
}

推荐答案

内部类称为匿名类-我看不到声明有问题-旁边类名以小写开头的事实,导致红色下划线.

请使用正确的IDE进行编码-Eclipse和Netbeans是免费的,并且会通知您此类情况.

类fr也被命名为不正确.另外,请制作所有这些分离的文件,类fr可以扩展JFrame-非常优雅,并且类内部应称为frController或frWorker(根据GUI部件的名称).其余的看起来真的很好!
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.

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!


它没有实现接口,您已经拼错了方法名称.
它应该是valueChanged,而不是valueChaned.

希望这会有所帮助,
弗雷德里克(Fredrik)
It''s not implementing the interface, you''ve misspelled the method name.
It should be valueChanged, not valueChaned.

Hope this helps,
Fredrik


这篇关于Java JList错误问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆