• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use a method in more than two different classes

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please can anyone see my screen shots attached here and in the customer form i have text fields for CustomerTFN and Surname and what i want is to show them in the second form which is the booking form I think a Module declaration for those field would be the solution but i dont know how to do that I will appreciate any help thank you


taxreturn.png
[Thumbnail for taxreturn.png]
 
Ranch Hand
Posts: 65
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static variable may do the trick to retain values from your fields. then create a static method where you can use it in any of your classes returning the retained values from your static variable.
 
Marshal
Posts: 79151
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your question is difficult to read, without capitalisation and punctuation, but you almost certainly ought not to declare that variable static. I think that would be a serious error.

Remember, the “model” contains the data and the “view” displays them, so you might have something like... inside the “control”, which manipulates the data and updates the “view”.
 
Myyron Murray Latorilla
Ranch Hand
Posts: 65
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I think that would be a serious error.



Is there memory issue on this approach? Or it is just a design error?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

myyron latorilla wrote:Is there memory issue on this approach? Or it is just a design error?


The latter. static fields should generally only be used to define constants, and should therefore also be final.

Winston
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Robert Leon wrote:i have text fields for CustomerTFN and Surname and what i want is to show them in the second form which is the booking form I think a Module declaration for those field would be the solution but i dont know how to do that...


And neither do we unless you show us your code (and only the relevant bits please).

For example, where do these CustomerTFN and Surname fields come from? Sounds to me like you may have a Customer object behind the scenes.

TellTheDetails (←click).

Winston

PS: When you do post your code, please:
1. UseCodeTags (←click).
2. Break up any very long lines (> ≈80 characters). They tend to screw up the windowing here.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

myyron latorilla wrote: . . . Is there memory issue on this approach? Or it is just a design error?

I hope you don’t think there is such a thing as “just a design error” Design errors are much more serious than using a bit of memory.

Yes, it is a serious design error to mark something static which ought not to be static.
 
Robert Leon
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry guys if I was not clear as I am a new user
my problem is not a design error I hope this time I can be more clear
1. all this 3 form are tables in my database and i have to store each field to their tables which are customers, booking and taxreturns
2. my customer form is the one for starting the program where I enter the customer details.
3. I can insert update delete and search for a customer
4. The second form is for making a booking to do the tax return and the third form if for making the calculation or the tax return

I have no problem so far working with the data base all is good
what i need is:
from the Customer Form I want CustomerTFN and Surname to be display in the other forms. for example if you can see my screen shots. I have the same CustomerTFN and Surname in my Booking Form how can I display them from the Customer Form. If i would do this program in Visual Basic I can make a module or global declaration and end of problem but in Java I dont know how to do it.
i will show a bit of my code if help:
1.-From customer class

2.-from CustomerForm(Design)


3.- what i need to do is this in the third form which is Booking Form



this bit is from the booking form i need to display the customerTFN from the CustomerCLass as i got the set and get method but if i can have a global declaration i can call this methods from any class inside the project


 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is something peculiar about your use of keyReleased. Does that mean you are going to try to validate the entry every time a key is released? And does that mean your entry contains 11 characters and you are going to fail to match after the first 10 keystrokes regardless?
Don’t you have some sort of “accept entry” button? Can’t you get all that validation done when the button is pressed, using an ActionListener?
Or can you use some sort of Listener on the text which does the validation when you reach 11 characters?
 
Robert Leon
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To Cambell: I am using a text Area where I can see the error message because if i use a message box it will pop up everytime i release the button thats why i dont use a message box
 
Robert Leon
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Robert Leon wrote:i
Can you help me please

 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell already hinted at this but the usual approach to this is to follow Model - View - Controller. In your case, you have some views: CustomerForm and BookingForm, and a Model object that represents a Customer. When the user enters information in the CustomerForm, the Model gets updated. Since the BookingForm is also watching for changes in the Customer, it would get updated with the new information. The details of how that happens can be found in many examples that you can find with a search for java swing mvc examples
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Robert Leon wrote:To Campbell: I am using a text Area where I can see the error message because if i use a message box it will pop up everytime i release the button thats why i dont use a message box

That is the sort of thing I meant about failing to match after the first ten keystrokes.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can’t you add an ActionListener to your text field, to receive an event when the enter/return key is pressed? Can’t you add a focus listener to receive an event when the tab key is pressed and the focus is lost? Then you can use them to call a shared method to validate the input.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic