簡體   English   中英

處理Java:防止selectInput無限期打開

[英]Processing Java: Prevent selectInput from opening indefinitely

當我使用selectInput()創建“打開文件”按鈕時。 問題在於,每次用戶選擇文件時,程序都會不斷打開窗口。 如何防止這種情況發生?

void setup()
{
  size(500, 500);
  background(255);
}

void draw()
{
  noStroke();
  fill(255, 0, 0);
  rect(0, 0, 50, 20);

  if (mousePressed)
  {
    if (mouseX <= 50 && mouseY <= 20)
    {
      selectInput("Select a file to open:", "fileSelected");
    }
  }
}

void fileSelected(File selection)
{
  if (selection != null)
  {
    String absolutePath = selection.getAbsolutePath();
    String[] locations = split(absolutePath, "\\");
    String fileName = locations[locations.length - 1];

    //addFile(fileList);
    println(fileName);
  }
}

使用JOptionPane.showMessageDialog()

否則,您可以使用一個變量來跟蹤是否已經打開一個對話框,但這是一個混亂的解決方案。

另一個解決方案是將conditionals mousePressed()和以下selectInput放入Processing的 mousePressed()函數中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM