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();
}
}
Tweet

Thanks for dropping by! Feel free to join the discussion by leaving comments, and stay updated by subscribing to the

Recent Comments