JAVA, How to make main function wait with executing code until JButton is pressed

I am a beginner, and i need help with my code that creates GUI. In main function, i use default constructor for class GUI that creates a frame with menu. Then i want the main function to wait with executing the rest of the code (which will start a simulation) until user presses START JButton in the GUI frame. How can I do that without using any loop? Below is my code, kinda long because of the GroupLayout that i use

package simulation;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.HashMap;


public class GUI extends JFrame {
    //by default map set to riverside
    public String mapName = "riverside";
    //user number of creatures input is stored in a hashmap
    HashMap<String, Integer> mapOfCreatures = new HashMap<>();


public GUI()
{
    this.setTitle("Simulation Of Evolution");

    this.setDefaultCloseOperation(3);
    setVisible(true);
    this.setSize(500, 500);
    this.setLocation(300, 300);
    initComponents();

}

public void initComponents()
{
    biomes.add(island);
    biomes.add(riverside);
    biomes.add(seaside);
    island.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            mapName = "island";
        }
    });
    riverside.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            mapName = "riverside";
        }
    });
    seaside.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            mapName = "seaside";
        }
    });
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            mapOfCreatures.put("wolves", (Integer)l1.getValue());
            mapOfCreatures.put("humans", (Integer)l2.getValue());
            mapOfCreatures.put("cockroach", (Integer)l3.getValue());
            mapOfCreatures.put("dinos", (Integer)l4.getValue());
            mapOfCreatures.put("bird", (Integer)l5.getValue());
            mapOfCreatures.put("fish", (Integer)l6.getValue());

            System.out.println(mapName);
            dispose();
        }
    });
    //this.getContentPane().setBackground(Color.BLUE);

    GroupLayout layout = new GroupLayout(getContentPane());
    this.getContentPane().setLayout(layout);

    /*here is the grouplayout, it is long so i deleted it here/*

//components
JRadioButton island = new JRadioButton("Island");
JRadioButton riverside = new JRadioButton("Riverside");
JRadioButton seaside = new JRadioButton("Seaside");
ButtonGroup biomes = new ButtonGroup();
JButton button = new JButton("START");
JLabel label1 = new JLabel("Please choose number of creatures in the beginning of simulation:");
JLabel label2 = new JLabel("Please choose a biome:");
JLabel label3 = new JLabel("Wolves");
JLabel label4 = new JLabel("Humans");
JLabel label5 = new JLabel("Cockroach");
JLabel label6 = new JLabel("Dinos");
JLabel label7 = new JLabel("Bird");
JLabel label8 = new JLabel("Fish");
JSpinner l1 = new JSpinner(new SpinnerNumberModel(1, 1, 300, 1));
JSpinner l2 = new JSpinner(new SpinnerNumberModel(1, 1, 300, 1));
JSpinner l3 = new JSpinner(new SpinnerNumberModel(1, 1, 300, 1));
JSpinner l4 = new JSpinner(new SpinnerNumberModel(1, 1, 300, 1));
JSpinner l5 = new JSpinner(new SpinnerNumberModel(1, 1, 300, 1));
JSpinner l6 = new JSpinner(new SpinnerNumberModel(1, 1, 300, 1));

**
public static void main(String[] args) {
new GUI();
/here will be rest of code, which should be executed when user presses START Jbutton/
}**

}


My teacher said i shouldnt use any loops,  maybe try callbacks or thread but i have no idea how to implement it

New contributor

user25304176 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật