Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 如何使类的主方法等待GUI操作执行_User Interface_Wait_Notify - Fatal编程技术网

User interface 如何使类的主方法等待GUI操作执行

User interface 如何使类的主方法等待GUI操作执行,user-interface,wait,notify,User Interface,Wait,Notify,我在一个类的主方法中使用了一个while循环,它不断提示用户输入一个名字,然后打开一个新窗口,该窗口由我编写的一个单独的类创建,该类扩展了面板,允许用户从姓氏的人中进行选择 但是,一旦main方法打开包含名称列表的新窗口,它将继续运行并重新启动循环,提示用户在可以从最后一个循环中选择一个名称之前键入新的姓氏 如何在while循环打开列表窗口后暂停它,直到用户选择了一个名称并且窗口关闭 我尝试过使用wait和notify逻辑,但不知道如何在循环中实现wait语句,该语句将在另一个类中等待notif

我在一个类的主方法中使用了一个while循环,它不断提示用户输入一个名字,然后打开一个新窗口,该窗口由我编写的一个单独的类创建,该类扩展了面板,允许用户从姓氏的人中进行选择

但是,一旦main方法打开包含名称列表的新窗口,它将继续运行并重新启动循环,提示用户在可以从最后一个循环中选择一个名称之前键入新的姓氏

如何在while循环打开列表窗口后暂停它,直到用户选择了一个名称并且窗口关闭

我尝试过使用wait和notify逻辑,但不知道如何在循环中实现wait语句,该语句将在另一个类中等待notify语句

此代码在其当前形式下不起作用,但这是我希望代码等待的地方,然后在按下按钮通知它继续后,我希望actionPerformed子句在这里工作

SelectListener类位于DoctorPanel类中,它扩展了面板并用于创建框架

package components;

import java.sql.Time;
import java.util.ArrayList;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Runner2 {

public static void main(String[] args) {
    ArrayList<Doctor> fullList=new ArrayList<Doctor>();
    fullList.add(new Doctor("John","Smith","High Point","NC",27031,"Eye Doctor","202 Fake St."));
    fullList.add(new Doctor("Mark","Smith","Kernersville","NC",27023,"The Place","222 Apple St."));
    fullList.add(new Doctor("Billy","Smith","Winston-Salem","NC",27345,"Eye Associates","8275 Farmview Ave."));
    fullList.add(new Doctor("John","Baker","Lewisville","NC",27678,"Eye Care","929 Pilot Cir."));
    fullList.add(new Doctor("Wes","Baker","Mocksville","NC",27324,"Endocrinologist","435 Fun Ln."));

    ArrayList<Doctor> selectedList=new ArrayList<Doctor>();

    while(true){
        String name=JOptionPane.showInputDialog("Enter last name of doctor (or 'done' if finished).");
        if (name.equals("done"))
            break;

        JFrame frame=new JFrame();
        DoctorPanel panel = new DoctorPanel(name,fullList);
        frame.add(panel);
        frame.setSize(400,400);
        frame.setVisible(true);
        wait();
        selectedList.add(panel.getDoctorAt(panel.getDoctor()));
        frame.dispose();
        //System.out.println(panel.getDoctor());

    }
    // TODO Auto-generated method stub

}

}


class SelectListener implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent arg0) {
        int index=list.getSelectedIndex();
        DOCTOR=index;
        //System.out.println(DOCTOR);
        notify();

    }
你可以从

 JFrame frame=new JFrame();
    DoctorPanel panel = new DoctorPanel(name,fullList);
    frame.add(panel);
    frame.setSize(400,400);
    frame.setVisible(true);
    wait();
    selectedList.add(panel.getDoctorAt(panel.getDoctor()));
    frame.dispose();
    //System.out.println(panel.getDoctor());

这样,您可以暂停,让您的_boolean等于false,并在动作侦听器中将_boolean设置为true

JFrame frame=new JFrame();
    DoctorPanel panel = new DoctorPanel(name,fullList);
    frame.add(panel);
    frame.setSize(400,400);
    frame.setVisible(true);
    if(your_boolean) {
        wait();
        selectedList.add(panel.getDoctorAt(panel.getDoctor()));
        frame.dispose();
        //System.out.println(panel.getDoctor());
   }