Reputation: 37
So I have a relatively good understanding of java, but I cannot continue on with a program I am working on until I can figure out how to pass on a variable from my main in a gui to a private class in a gui that has action listener implemented. This was just a test I was doing to see if I could get something basic to work.
public static void main (String args[]) throws IOException {
Scanner inputChamps = new Scanner (new FileReader("Dazzle_Squad_Champs.txt"));
int number = inputChamps.nextInt(); // trying to pass this on from here
LoadButtonHandler(number);
Dazzle_Squad myAreaObject = new Dazzle_Squad();
}
public static void LoadButtonHandler (int number) implements ActionListener {
public void actionPerformed (ActionEvent ae) {
System.out.println(number); // and outputting it here.. Everything else works so far
}
}
Upvotes: 0
Views: 93
Reputation: 14413
void? u are creating a method there...
public class LoadButtonHandler implements ActionListener
{
private int number;
public LoadButtonHandler(int number){
this.number=number;
}
public void actionPerformed (ActionEvent ae)
{
System.out.println(number); // and outputting it here.. Everything else works so far
}
}
u are mixing console application with gui :O That listener have to be added to a component like this
myAreaObject.addActionListener(new LoadButtonHandler(inputConsole));
Upvotes: 4