0

如何向 actionPerformed 添加语句以调用 mkList 并将结果存储在新变量 LinkedList aList 中。

public void actionPerformed(ActionEvent event) {    
    if (event.getSource() == reading) {
        String s = txt1.getText();
        String delims = expression.getText(); 
        String[] anArray = s.split(delims);
        result.setText("");
        print(anArray);
    } 
    LinkedList<String> mkList;
    LinkedList<String> aList = new LinkedList<String>();

} // actionPerformed

public LinkedList<String> mkList(String[] sa) {
    LinkedList<String> st = new LinkedList<String>();
    for (int i = 0; i < sa.length && sa[i] != null; i++)
    st.add(sa[i] + "\n");
    return st;
} // mkList
4

1 回答 1

0

使anArray变量 成为局部变量,以便您可以使用它作为参数传递给mkList()外部方法if statement

public void actionPerformed(ActionEvent event) {    
String[] anArray=null;  
  if (event.getSource() == reading) {
        String s = txt1.getText();
        String delims = expression.getText(); 
        anArray = s.split(delims);
        result.setText("");
        print(anArray);
    } 
    LinkedList<String> mkList;
    LinkedList<String> aList = new LinkedList<String>();
    if(anArray!=null)        
     aList = mkList(anArray);

} // actionPerformed
于 2013-03-07T19:00:04.947 回答