Problem calling a method?!

Page 1 of 1

1 Replies - 170 Views - Last Post: 01 February 2013 - 10:29 AM Rate Topic: -----

#1 Javano0b  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-October 12

Problem calling a method?!

Posted 01 February 2013 - 10:21 AM

Hey, just trying to get these buttons to work by calling the methods "correctAnswer" and "wrongAnswer" at the bottom into earlier code. I had it working earlier but it was "styled badly" so I'm trying to clean it up. This is the code I have so far.


public class Level1 extends Screen {


private String q = "Name the BAND";
private String b = "";
private AudioClip seize;

private OptionButton[] buttons = {
new OptionButton(50,200,200,50, "Aerosmith"),
new OptionButton(450, 200,200,50, "A7X"),
new OptionButton(50,300,200,50, "Guns n' Roses"),
new OptionButton(450,300,200,50, "AC/DC")

};
private int a=1;

public Level1(final AppPanel panel) {
super(panel);
for (int i =0; i<buttons.length;i++){
panel.add(buttons[i]);
if(i==a){
buttons[i].addActionListener(new ActionListener(){
//this is where I want "correctAnswer"
});
}
else {buttons[i].addActionListener(new ActionListener(){
//this is where I want "wrongAnswer"

});

}
}
}
public void correctAnswer(ActionEvent e){
q = "Correct!";
}


public void wrongAnswer(ActionEvent e){
main.lives--;
if(main.lives<=0){
panel.lastScreen();
main.lives=3;
}
q = "Wrong";
b = ":-(";
}




Earlier I was calling those methods inside the for loop and it worked, but was told to clean that up, so any suggestions, however simple they may be, are very welcome!
Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Problem calling a method?!

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9494
  • View blog
  • Posts: 35,842
  • Joined: 12-June 08

Re: Problem calling a method?!

Posted 01 February 2013 - 10:29 AM

Please do not open duplicate topics. Closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1