Home > Java, Programming > Example Code #1 – JOptionPane and ArrayList

Example Code #1 – JOptionPane and ArrayList

Here this class takes some values using JOptionPane.showInputDialog and shows them to the user using foreach loop

import java.util.ArrayList;
import javax.swing.JOptionPane;

public class Confirm {

ArrayList fruits = new ArrayList();

Confirm(){
String value = "";
while (true){
value = JOptionPane.showInputDialog("Which fruit to Add?");

if (!value.equals("") )
{
fruits.add(value);
}
else
break;

}

for (String s : fruits) {
int n = JOptionPane.showConfirmDialog
(null,
s,
"Apple list",
JOptionPane.YES_NO_OPTION);

System.out.println("n value:" + n);

if (n == JOptionPane.YES_OPTION)
continue;
else if (n == JOptionPane.NO_OPTION)
break;
else if (n == JOptionPane.CLOSED_OPTION)
JOptionPane.showMessageDialog(null, "you clicked to close");
}
}

public static void main(String[] args) {

new Confirm();

}

}
VN:F [1.9.22_1171]
Rating: 6.7/10 (7 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Example Code #1 - JOptionPane and ArrayList, 6.7 out of 10 based on 7 ratings
  1. No comments yet.
  1. No trackbacks yet.