Skip to content
Advertisement

How do I get a variable collected from a JTextField and give it to a getter method?

Very new to using Java and spent hours looking for a solution, but I cannot find out how to get the input collected by a JTextField with a button and ActionListener then be used for a getter method that can receive idNum so I can use the input in another class.

JavaScript

Advertisement

Answer

I believe what you are trying to do is something like this:

JavaScript

Using a setter in StaffBooking would be better in this case:

JavaScript

A further improvement oof the structure can be achieved by using a model class, shared between Staff and StaffBooking:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement