BKevinT
04-21-2007, 05:10 PM
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.
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):
public int findNumChars(){
return numChars;
}
Then I tried using that method in the learner class.
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
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.
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):
public int findNumChars(){
return numChars;
}
Then I tried using that method in the learner class.
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