Results 1 to 2 of 2
  1. #1
    Felissa is offline Member
    Join Date
    Jun 2007
    Rep Power

    Default Use int in a diferent Class

    I have 2 classes; &

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

    Java Code:
    public void setNumChars()throws Exception{
       int tmp;
           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 class. So I tried creating a public method that retrieves the number

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

    Java Code:
    public static void learn(String tekst, int orden)
            for(int i=0; i<=tekst.length()-(findNumChars() -1); i++)
    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?


  2. #2
    Eric is offline Senior Member
    Join Date
    Jun 2007
    Rep Power


    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.


Similar Threads

  1. Replies: 0
    Last Post: 04-02-2008, 07:04 AM
  2. Replies: 0
    Last Post: 02-17-2008, 10:03 AM
  3. Replies: 0
    Last Post: 02-17-2008, 10:01 AM
  4. Inner class accessing outer class
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-17-2008, 09:59 AM
  5. Replies: 5
    Last Post: 01-03-2008, 08:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts