I am new to java so help is much appreciated.
I have a few classes. I want to pass the user input from my GUI class to my Basket class where it will update the value stored in the variable. Below is what i currently have but it doesn't seem to be updating the variable.
Class One - GUI Class: I would like to pass the 'seats' to the basket class
Basket b;
b = new Basket();
String seats = JOptionPane.showInputDialog("Enter the number of seats to book");
try {
int currentValue = Integer.parseInt(seats);
int newValue = currentValue;
b.setSeatsBooked(newValue);
//some code emitted
}
Second Class - Basket Class, I would like the 'seats' to be passed into this class and stored in the instance variable.
public class Basket {
private int seatsBooked;
public int getSeatsBooked() {
return seatsBooked;
}
public void setSeatsBooked(int seatsBooked) {
this.seatsBooked = seatsBooked;
}
}
This is in another class where i see the result as 0:
Basket b;
b = new Basket();
lblMovieSelection = new JLabel("You have booked:" + b.getSeatsBooked());