The title is explicit enough, I want to let the user choose the text file he want to open. I do not know if there is an explorer or an input field already implemented on processing.
Any help would be great.
The title is explicit enough, I want to let the user choose the text file he want to open. I do not know if there is an explorer or an input field already implemented on processing.
Any help would be great.
使用选择输入。从处理参考:
打开特定于平台的文件选择器对话框以选择要输入的文件。选择完成后,选择的文件将被传递给“回调”函数。如果对话框关闭或取消,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);
}
}
没有已实现的方法,但您可以像这样制作缓冲区并监视按键:
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");
}
}
按下触发键时,它会加载文件