2013-04-30 46 views

回答

3

使用selectInput。從處理參考:

打開特定於平臺的文件選擇器對話框以選擇要輸入的文件。選擇完成後,選定的文件將被傳遞給'回調'功能。如果對話框關閉或取消,則將向該函數發送null,以便程序不會等待其他輸入。由於線程工作方式,回調是必要的。

我修改了它們在參考文獻中提供的示例草圖,其中包括使用loadStrings方法加載文件。

String[] txtFile; 

void setup() { 
    selectInput("Select a file to process:", "fileSelected"); 
} 

void fileSelected(File selection) { 
    if (selection == null) { 
    println("Window was closed or the user hit cancel."); 
    } else { 
    String filepath = selection.getAbsolutePath(); 
    println("User selected " + filepath); 
    // load file here 
    txtFile = loadStrings(filepath); 
    } 
} 
0

沒有實現的方法,但你可以可以使一個緩衝和監控按鍵,像這樣:

String[] File; 
String keybuffer = ""; 
Char TriggerKey = Something; 

void setup(){ 
    //do whatever here 
} 

void draw(){ 
    //Optional, to show the current buffer 
    background(255); 
    text(keybuffer,100,100); 
} 

void keyPressed(){ 
    if(keyCode >= 'a' && keyCode <= 'z'){ 
    keybuffer = keybuffer + key; 
    } 
    if(key == TriggerKey){ 
    File = loadStrings(keybuffer + ".txt"); 
    } 
} 

當按下triggerkey,它加載文件

相關問題