如何连续使用JButton Action Listener?

问题描述 投票:0回答:0

我正在编写一个简单的程序来获取您的信息,并在计算它们之后为您提供关于您的未来预测。我卡住的地方是;我需要连续向用户显示 21 个问题,我将这些问题放在一个字符串数组中。那里是每次获取用户输入的一个按钮。问题是我无法连续显示问题,因为我不知道如何将 for 循环与 ActionListener 结合使用。有人可以帮助我吗?

我尝试在 ActionListener 方法中使用 for 循环,但它没有用

    confirm.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){ 
                       
            foreground.setSize(450,599);        //Dont Mind This 
        username.setVisible(true);             //This is a textfield for user's name
    explanations.setText(questions[0]);     //This is an array contains all questions.I want
                                         to show each one of them every time.But I cant raise the number.   
                
        String textFieldValue = username.getText(); //This is where I want to get user input
        
                        
                   }
                }
                
                        );
java swing jbutton actionlistener jtextfield
© www.soinside.com 2019 - 2024. All rights reserved.