Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未解析的编译和大量未解析的变量错误_Java_User Interface_Listener_Actionlistener - Fatal编程技术网

Java 未解析的编译和大量未解析的变量错误

Java 未解析的编译和大量未解析的变量错误,java,user-interface,listener,actionlistener,Java,User Interface,Listener,Actionlistener,这里的发帖社区是新来的,但我已经在这件事上束手无策了。。。我对GUI非常不熟悉,因此我需要能够使下面的侦听器类与rnaSeq类正确通信 public class RNA5 { private static TreeMap<String, ArrayList<String>> filtered = new TreeMap<String, ArrayList<String>>(); private static ArrayList<String&

这里的发帖社区是新来的,但我已经在这件事上束手无策了。。。我对GUI非常不熟悉,因此我需要能够使下面的侦听器类与rnaSeq类正确通信

public class RNA5 {
private static TreeMap<String, ArrayList<String>> filtered = new TreeMap<String, ArrayList<String>>();
private static ArrayList<String> ITEMS = new ArrayList<String>();

public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    infile();
    new rnaSeq();
}

public static TreeMap<String, ArrayList<String>> infile() throws IOException {
    InputStream stream = new FileInputStream("C:\\NEW.txt");
    BufferedReader infile = new BufferedReader(new InputStreamReader(stream));
    int i = 0;
    while(infile.ready()) {
        ArrayList<String> s = new ArrayList<String>(Arrays.asList(infile.readLine().split("\t")));
        if(i == 0) {
            for(int j = 0; j < s.size(); j++) {
                ITEMS.add(s.get(j));
            }
        }
        else {
            String firstColumn = s.get(0);
            s.remove(0);
            filtered.put(firstColumn, s);
        }
        i++;
    }
    infile.close();

    return filtered;
}

JFrame window;
JMenuBar menuBar;
JMenu mnFile, mnEdit, mnHelp;
JPanel panel, panel_1, panel_2, panel_3;
TextArea textArea_2, textArea, textArea_1;
JButton btnNewButton_1, btnNewButton, btnNewButton_2, btnNewButton_3, btnNewButton_4, btnNewButton_5, btnNewButton_6, btnNewButton_7;
JTabbedPane tabbedPane;
rnaSeq.Listener listener;

public rnaSeq() {
    window = new JFrame();
    window.setSize(800,400);

    menuBar = new JMenuBar();
    window.setJMenuBar(menuBar);

    mnFile = new JMenu("File");
    menuBar.add(mnFile);

    mnEdit = new JMenu("Edit");
    menuBar.add(mnEdit);

    mnHelp = new JMenu("Help");
    menuBar.add(mnHelp);
    window.getContentPane().setLayout(new java.awt.GridLayout(0, 2, 0, 0));

    panel = new JPanel();
    window.getContentPane().add(panel);
    panel.setLayout(new java.awt.GridLayout(0, 2, 0, 0));

    textArea_2 = new TextArea();
    panel.add(textArea_2);

    panel_1 = new JPanel();
    panel.add(panel_1);
    panel_1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

    btnNewButton_1 = new JButton("Enter");
    panel_1.add(btnNewButton_1);
    btnNewButton_1.addActionListener(listener);

    btnNewButton = new JButton("Create");
    panel_1.add(btnNewButton);
    btnNewButton.addActionListener(listener);

    btnNewButton_2 = new JButton("Clear");
    panel_1.add(btnNewButton_2);
    btnNewButton_2.addActionListener(listener);

    btnNewButton_3 = new JButton("Clear All");
    panel_1.add(btnNewButton_3);
    btnNewButton_3.addActionListener(listener);

    btnNewButton_5 = new JButton("Select");
    panel_1.add(btnNewButton_5);
    btnNewButton_5.addActionListener(listener);

    btnNewButton_6 = new JButton("Sort");
    panel_1.add(btnNewButton_6);
    btnNewButton_6.addActionListener(listener);

    btnNewButton_7 = new JButton("Range");
    panel_1.add(btnNewButton_7);
    btnNewButton_7.addActionListener(listener);

    btnNewButton_4 = new JButton("Link");
    panel_1.add(btnNewButton_4);
    btnNewButton_4.addActionListener(listener);

    panel_3 = new JPanel();
    panel.add(panel_3);
    panel_3.setLayout(new java.awt.GridLayout(1, 0, 0, 0));

    panel_2 = new JPanel();
    panel.add(panel_2);

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    window.getContentPane().add(tabbedPane);
    tabbedPane.setToolTipText("");

    textArea = new TextArea();
    tabbedPane.addTab("Output", null, textArea, null);

    textArea_1 = new TextArea();
    tabbedPane.addTab("Analysis", null, textArea_1, null);

    window.setVisible(true);
    window.setDefaultCloseOperation(3);
}

class Listener implements ActionListener {
    Listener() {}

    public void actionPerformed(ActionEvent e) {
        Component clicked = (Component)e.getSource();
        System.out.println("actionPerformed is working!");
        if(clicked == rnaSeq.btnNewButton_1) {
            openDialogInput(0);
            System.out.println("clicked is working!");
        }
        else if(clicked == rnaSeq.btnNewButton) {
            openDialogInput(1);
        }
        else if(clicked == rnaSeq.btnNewButton_2) {
            openDialogInput(2);
        }
        else if(clicked == rnaSeq.btnNewButton_3) {
            openDialogInput(3);
        }
        else if(clicked == rnaSeq.btnNewButton_4) {
            openDialogInput(4);
        }
        else if(clicked == rnaSeq.btnNewButton_5) {
            openDialogInput(5);
        }
        else if(clicked == rnaSeq.btnNewButton_6) {
            openDialogInput(6);
        }
        else if(clicked == rnaSeq.btnNewButton_7) {
            openDialogInput(7);
        }
    }

    public String openDialogInput(int i) {
        String input = (String)JOptionPane.showInputDialog(null, "", "Input Type", JOptionPane.QUESTION_MESSAGE, null, ITEMS.toArray(new String[ITEMS.size()]), ITEMS.toArray(new String[ITEMS.size()])[0]);
        return openDialogOutput(input, i);
    }

    public String openDialogOutput(String input, int i) {
        JList<String> list = new JList<String>(ITEMS.toArray(new String[ITEMS.size()]));
        JOptionPane.showMessageDialog(null, list, "Output Type", JOptionPane.QUESTION_MESSAGE);
        ArrayList<String> output = new ArrayList<String>();
        output.addAll((Collection<? extends String>)Arrays.asList((Arrays.toString(list.getSelectedIndices())).split(" ")));
        TreeMap<String, ArrayList<String>> inputOutput = new TreeMap<String, ArrayList<String>>();
        inputOutput.put(input, output);
        return evaluate(inputOutput, i);
    }

    public String evaluate(TreeMap<String, ArrayList<String>> inputOutput, int i) {
        int in = -1;
        ArrayList<Integer> out = new ArrayList<Integer>();
        for(int j = 0; j < ITEMS.size(); j++) {
            for(Map.Entry<String, ArrayList<String>> entry : inputOutput.entrySet()) {
                if(entry.getKey() == ITEMS.get(j)) {
                    in = j;
                    for(int k = 0; k < ITEMS.size(); k++) {
                        for(Map.Entry<String, ArrayList<String>> entry2 : inputOutput.entrySet()) {
                            for(int m = 0; m < entry2.getValue().size(); m++) {
                                if(entry2.getValue().get(m) == ITEMS.get(k)) {
                                    out.add(k);
                                }
                            }
                        }
                    }
                }
            }
        }
        return setText(in, out, i);
    }

    public String getText() {
        return "";

    }

    public String setText(Integer in, ArrayList<Integer> out, int i) {
        if(in == -1) {
            return "";
        }
        else {
            StringBuilder c = new StringBuilder();
            for(int j = 0; 0 < out.size(); j++) {
                if(j == out.get(j)) {
                    c.append(ITEMS.get(j) + "\t");
                }
                c.append("\r\n");
            }
            return c.toString();
        }
    }
}
}
我觉得这一定是一个愚蠢的问题,我错过了。。。如果需要更多信息,请告诉我

编辑:错误更具体地说是:1 rnaSeq.Listener无法解析为类型rnaSeq.Listener Listener,2方法的返回类型缺少公共rnaSeq。。。它是一个内部类,3个侦听器无法解析为变量BtnewButton_1。addActionListenerlistener及其兄弟,4个BtnewButton无法解析或不是字段及其兄弟。基本上,我认为错误3和4源于错误1和2。

1在这一行:

rnaSeq.Listener listener;
您说过要使用在rnaSeq类中声明的侦听器类。没有这样的类rnaSeq。改为:

Listener listener;
2这一行:

public rnaSeq() {
看起来它试图成为rnaSeq类的构造函数。但您只能在rnaSeq的类声明中声明rnaSeq类的构造函数,并且代码中没有这样的类声明

其他错误可能是由这两个错误引起的


顺便说一下,使用rnaSeq作为Java类的名称是非常糟糕的风格。Java类名应始终以大写字母开头。

您发布了大量代码,但没有指出错误在哪里或错误是什么。请帮助我们将代码量减少到一个简短但完整的示例中,以演示问题并包括错误,从而帮助您。另外,在代码编译之前不要尝试运行它…对不起!错误为:1 rnaSeq.Listener无法解析为类型rnaSeq.Listener Listener,2该方法的返回类型缺少公共rnaSeq。。。这是一个内部类,3个侦听器无法解析为变量BtnewButton_1。addActionListenerlistener及其兄弟,4个BtnewButton无法解析或不是字段及其兄弟。基本上,我需要位于rnaSeq中的GUI和ActionListener类进行通信,尽管我花了数小时的努力,我似乎无法完成。提示:在进行过程中获取要编译的代码。这样,您就不会一次修复大量代码和多个错误。很抱歉,Listener类在内部,但我将其移到了外部,因为我无法在内部类的textArea中声明更改。那是我的错,不够清楚。谢谢!那么我应该重命名内部类RNA5吗?不。为什么你希望外部类和内部类有相同的名称???事实上…是的,这似乎是个坏主意…好的。所以我修改了1,现在剩下的唯一错误是2。那么这应该是内部类的构造函数吗?如果是,则声明内部类。如果不是,则添加一个void返回类型以使其成为一个方法。