Java GUI应用程序

-2 java swing jframe event-dispatch-thread thread-sleep

我正在研究Java图形界面(Swing,AWT).我的应用程序中的数据输入应该通过一个JFrame.事实上,我有10个实体需要10 JFrame秒.我使用了一个for循环,但JFrame似乎没有等到数据输入.

我用Thread.sleep()但是徒劳无功.有帮助吗?

这是我的一些代码:

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);
}
Run Code Online (Sandbox Code Playgroud)

J4v*_*4v4 5

您正在寻找JOptionPane.

String data = JOptionPane.showInputDialog(
    null, //parent window
    "Hi! Enter some data, please:", //text
    "Input", //title
    JOptionPane.PLAIN_MESSAGE //icon?
);
Run Code Online (Sandbox Code Playgroud)

浏览文档以找到满足您需求的最佳方法.

编辑: JOptionPane实际上是块,所以你可以循环:

String[] data = new String[10];
for(int i = 0; i < 10; i++) {
    data[i] = JOptionPane.showXXX(...);
}
Run Code Online (Sandbox Code Playgroud)