2013-03-07 36 views
0

如何將語句添加到actionPerformed以調用mkList並將結果存儲在新變量LinkedList aList中。如何將語句添加到actionPerformed來調用LinkedList並將結果存儲在新變量中

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 

回答

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 
相關問題