Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating methods in Java (Object Oriented Programming)  RSS feed

 
Pascacio Toribio
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I want to create a method to clear text box in my Client class.

I also need to use a method to clear text boxes in my Item class.

The question is : Can I call the method from the Item class? Also I see that the text boxes in the Item class are different in name and quantity than the Client class.

How can I do this? I have searched on Google and can't find anything useful... Thanks.

Maybe the answer is that I should make different method on any class that I need to use the Clear method. I want to use method calling because I need to do something like this because this is for a homework program I am doing...

Thanks again....
 
Jason Bullers
Ranch Hand
Posts: 115
11
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you got so far code wise? You mention a Client class, a text box, and an Item class. Let's see them!
 
salvin francis
Bartender
Posts: 1604
35
Eclipse IDE Google Web Toolkit Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pascacio Toribio wrote:Can I call the method from the Item class


Giving you an answer would be very difficult since you havent shown us your code so far.

Here is my explanation of how stuff works in java in a nutshell.

Objects are defined by data and methods. In java, you need to have a reference to a class to call its method(Except static methods). So, in your code, does "Item" class have a reference of "Client" class ?
if yes, then does "Client" class have a field variable for its textbox ?
if yes, then does "Client" class have a getter for its textbox ?
if yes, then your code in item class can be simply as:



Does this answer your question ?
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should give a bit more explanation of what you wish to do. Without knowing what Item and Client mean, we cannot know how to advise you.

Text boxes are usually designed to receive input to be put into something else. You can have a newClient button which calls a method to clear several text boxes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!