I am working on a Java graphical interface (Swing , AWT) . The data entry in my application is supposed to be done via a JFrame
. In fact I have 10 entities that necessitate 10 JFrame
s. I used a for
loop but JFrame
s don't seem to wait until data entry.
I used Thread.sleep()
but in vain. Any help?
Here is some of my code:
for (int i=0; i < VMnumber; i++) // VMnumber : number of virtual machines to instantiate
{
mips=0;
frame=new VMcaracteristics(); // VMcaracteristics is a JFrame to enter VMs caracteristics
frame.setVisible(true);
while (!VMcaracteristicsFlag) // Current frame is still open
{
Thread.sleep(100);
} // create a VM correspondent to the current frame
vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
vmlist.add(vm);
}
You are looking for JOptionPane.
String data = JOptionPane.showInputDialog(
null, //parent window
"Hi! Enter some data, please:", //text
"Input", //title
JOptionPane.PLAIN_MESSAGE //icon?
);
Explore the documentation to find the best method for your needs.
Edit: JOptionPane actually blocks, so you can loop:
String[] data = new String[10];
for(int i = 0; i < 10; i++) {
data[i] = JOptionPane.showXXX(...);
}