M
M
Maly2022-03-29 14:01:34
Java
Maly, 2022-03-29 14:01:34

How to make a function for sequential click?

Here is the code:

String questions[]={"The first question","The secound qurstion","The third qurstion","The four qurstion","The five qurstion"};
//Массив с вопросами

JLabel label1=new JLabel();
JLabel label2=new JLabel("5\1");
ActionListener actionListener1=new ActionListener(){
    public void actionPerformed(ActionEvent e){

label1.setText(questions[1]);
label1.setText("5\2");

    }
    };
check.addActionListener(actionListener1);


It is necessary that the first time the button is pressed, the first value from the array is displayed; the second time the button is pressed, the second value of the array, and so on until the end.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LittleBob, 2022-03-29
@maly222

Create an int variable and after each click do i++ and display the values ​​of the array.

i++;
if(i < questions.lenght){
label1.setText(questions[i]);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question