Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-21-2007, 06:14 PM   PM User | #1
BKevinT
New to the CF scene

 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
BKevinT is an unknown quantity at this point
Need to use an int in a different class

EDIT: Problem solved.....feel free to delete this thread

I have a very basic question:

I have 2 classes; GUI.java & learner.java. The GUI contains a method that is called when it runs that shows an inputDialog , and the user chooses a number between 2 & 10.

Code:
public void setNumChars()throws Exception{
   int tmp;
   do
       tmp = Integer.parseInt(JOptionPane.showInputDialog("Write 
       num of chars\nbetween 2 and 10:"));
        
   while(tmp>10 || tmp<2);
     
   numChars = tmp;
}
And I need the number that the user inputs to be available to me in the learner.java class. So I tried creating a public method that retrieves the number (it is also located in the GUI class):

Code:
public int findNumChars(){
   return numChars;
}
Then I tried using that method in the learner class.

Code:
public static void learn(String tekst, int orden)
        {
        ....................
        for(int i=0; i<=tekst.length()-(findNumChars() -1); i++)
            {
           ...........................
            if
                ....................
            else
                ..................
            
            }
            
        }
Now, I know that this doesn't work. My question is; what changes do I have to make to be able to use the user-inputted int from the GUI, in the learner class?

Really appreciate your help, thanks

Last edited by BKevinT; 04-22-2007 at 01:23 AM..
BKevinT is offline   Reply With Quote
Old 04-22-2007, 04:01 PM   PM User | #2
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
Can you please post your solution for future reference?

I know it either involves setting a global variable to using a set method in the learner class, but let us know which you used.
__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch
Aradon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:46 AM.


Advertisement
Log in to turn off these ads.