• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Creating methods in Java (Object Oriented Programming)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Ranch Hand
Posts: 115
11
IntelliJ IDE Clojure Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 2908
150
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Marshal
Posts: 76860
366
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic