I'm taking a course in java and now I got stuck in a problem which is probably very obvious and clear, but I cant find any answer on the internet so i decided to come here and personally ask you guys.
So.. JOpitionPane to display LIFO (Last In First Out) stack. In my code below I'm using System.out.println as an example to show what I want it to do. What I need it to do is to display it in a JOptionPane.showMessageDialog box. I somehow cant figure it out, creating an array to stack the amount you want to display is my guess, but I don't know how to move forward from here.
Many thanks to whoever could answer my question.
Here's my simplified code-text for this question.
import java.util.Stack;
import javax.swing.JOptionPane;
public class Test1 {
public static void main(String args[]) {
new Test1();
}
public Test1() {
boolean status = false;
Stack<String> lifo = new Stack<>();
while (!status) {
String s = (JOptionPane.showInputDialog("Write something"));
if (s == null) {
status = true;
} else {
lifo.add(s);
}
}
if (status == true) {
Double num = Double.parseDouble(JOptionPane.showInputDialog("How many of latest Input would you like to see?"));
for (int i = 0; i < num; i++) {
System.out.println(lifo.pop()); //Here is where i would want
System.out.print(','); //JOptionPane.showMessageDialog instead.
}