Greetings,
So far, my code compiles, but it changes white to black and then don’t want to change.
Supposely it should change from red->orange->green->pink->blue->black..
public void init() {
c=new Color[] {Color.red, Color.orange, Color.green,
Color.pink, Color.blue, Color.black };
btnNext = new Button("Next Color");
btnNext.addActionListener(this);
setLayout(new BorderLayout());
add(btnNext, BorderLayout.SOUTH);
}
public void paint(Graphics g) { }
public void actionPerformed(ActionEvent e) {
if(e.getSource() == btnNext) {
for(int n=0;n<6;n++) {
setBackground(c[n]);
}
repaint();
}
}
Thank you for your help.
What you need to do is keep an
intmember variable of the current position in the array. Then increment that position every time you click the button.