2 Replies - 169 Views - Last Post: 01 February 2013 - 10:19 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 - 09:43 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 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5417
  • View blog
  • Posts: 11,609
  • Joined: 02-June 10

Re: Problem calling a method?!

Posted 01 February 2013 - 09:47 AM

Is this JAVA? Because you posted in C & C++
Was This Post Helpful? 0
  • +
  • -

#3 Javano0b  Icon User is offline

  • New D.I.C Head

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

Re: Problem calling a method?!

Posted 01 February 2013 - 10:19 AM

View PosttlhIn`toq, on 01 February 2013 - 09:47 AM, said:

Is this JAVA? Because you posted in C & C++


Haha oh wow what a stupid mistake... Thanks for pointing that out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1