• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

retrieve other class method

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, i need some help with my program. I have two class which both extends JFrame. The first class called security class and second class is available class. In the security class, i create a button to operate the available class and it generate a result in method Count(). I want to view the result in Frame Security by calling method count but i could manage to do it. Can somebody help me how to manage this problem?

Thanks. :roll:
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your security class will only display something if your method count() returns something, print the return value of count() by System.out.println() to console, as I think your method is not returning what you are expecting.

By the way, which element you are using to display output at security class?

Zia
 
nani aman
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You right. The security cannot retrieve the value of available class because the available class do nothing. I have declare an object of available class but it do nothing. Any suggestion to view Frame of available class and retrieve instance count?

This is the code:

public void Security extends JFrame implements ActionListener{
Available avail = new Available();

public Security(){
avCount = avail.getCount();
}
}

public void Available extends JFrame implements ActionListener{
public int getCount(){
return count;
}
}

Please help, i just have few days left to submit and this is my only problem. Thanks.
 
Ranch Hand
Posts: 158
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Hope this example could help you out.

This is the all i am using in my software.






Hope you understand how can we get value from ClassA to ClassB.

Tell me if i am wrong.
 
Anand Karia
Ranch Hand
Posts: 158
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry nani, i have made a single mistake in my code. Here is the correct one for you.

wrong code as private void getValue() method in which i suppose to use System.out.println(obj.getUserID()); rather than System.out.println(obj.strUserId());...


 
nani aman
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way i do is the same as you. it still didn;t work. Is it because both extends JFrame?


 
Anand Karia
Ranch Hand
Posts: 158
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In ClassA i have made a function that assign value to strUserId then
in second function only retrived the same value that is public in ClassA through

this.strUserID;

I didnt find any value that you are passing. It means that if you are having null value into your count variable, no data will be shown.

Try to assign value at top of the declaration of count variable as
public int count = 99;

Now try this. It does nothing what your java class is extended from. I am using JFRAME and JDIALOG. I am using NETBEANS IDE that by default extends JFrame. And the example i have given you was one of my real application.

Hope now you understand. If not then send me all your code in this form or send me email at [email protected]........ May i solve your this problem.

Take Care....
 
nani aman
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anand,
i understand the way you told me but i still couldn't solve my problem. i will send to you email my 2 classes and i wish you could see what is the real problem. Thanks for helping me.
reply
    Bookmark Topic Watch Topic
  • New Topic