如何使用JOptionPane删除输入

时间:2019-04-07 02:00:07

标签: java joptionpane

如何使用JOptionPane搜索和删除输入,以及当用户在“是否要重试”之后单击“是”时,如何使程序返回到开头?

代码的第一部分是输入所在的位置。我不确定OP是否需要在此处添加任何内容来帮助删除,因为稍后我将不得不使其删除输入之一。

Java:

int i = 0;
while (i < numItems && inp != null) {
    inp = JOptionPane.showInputDialog(null, "Enter name of expense " + i);
    if (inp != null) {
        expenseNameList[i] = inp;
        inp = JOptionPane.showInputDialog(null, "Enter price of " + expenseNameList[i]);
        if (inp != null) {
            expensePriceList[i]=Double.parseDouble(inp);
        }
    }
    i = i + 1;
}

if (inp == null) {
    return;
}

代码的第二部分是我必须在其中放置选项的位置,以便用户搜索和删除数组中的输入。

//searching for an expense
     String target = "";
     msg = "";
     while (msg.length() == 0 && target != null) {
         target=JOptionPane.showInputDialog("Which expense did you want to search for...");
         if (target != null) {
             i = 0;
             while(i < numItems) {
                 if (expenseNameList[i].contains(target)) {
                     msg = msg + expenseNameList[i] + ": " + expensePriceList[i] + "\n";
                 }
                 i = i + 1;
           }  
        }

if (msg.length() > 0) {
JOptionPane.showMessageDialog(null, "Results found ...\n" + msg);;
      {
int reply = JOptionPane.showConfirmDialog(null, "Do you want to try again?", "", JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION) 
JOptionPane.showMessageDialog(null, "Hello");           
          //need to make it go back to the start here   
else {
JOptionPane.showMessageDialog(null, "Goodbye!"); 

0 个答案:

没有答案