Page 2 of 2 FirstFirst 12
Results 21 to 34 of 34
  1. #21
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default

    O! right.. I can understand something right now.. On monday i am going to test many times with define a method..
    Thank you very match!!!

  2. #22
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default

    i am sorry
    i cant do it works.. =/
    can anyone correct the program? please?
    thanks.

  3. #23
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Sorry, we'd rather help you fix your program.
    Have you researched how to add a method to a class yet?

    If you look at your code, you already have two methods you have added:
    main() and actionPerformed()

    Using the same syntax add the getString and setString methods to the classes where they need to be added.

  4. #24
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default

    like this?

    public String getString(){
    str.getString();}

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    No. I gave you a prototype earlier:
    public String getString() {
    return "THE STRING";
    }

  6. #26
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default

    a ok..
    now here?

    Java Code:
    public String setString(){
    program1 class2 = new program1();
    class2.setString(name);}
    error returned:

    Java Code:
    program1.java:38: setString() in program1 cannot be applied to (java.lang.String)
    class2.setString(name);}
          ^
    1 error
    Then i change it into this and the result:


    public String setString(){
    program2 class2 = new program2();
    class2.setString(name);}

    error returned :

    Java Code:
    program1.java:38: cannot find symbol
    symbol  : method setString(java.lang.String)
    location: class program2
    class2.setString(name);}
          ^
    1 error

  7. #27
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Can you describe what you are trying to do here?
    Java Code:
    public String setString(){
      program2 class2 = new program2();
      class2.setString(name);   
    }
    This code defines a method: setString in the current class.
    The code in the method is supposed to do what?

    You need to isolate this problem into a small simple program that you can post all of the code for instead of the small sections of code you are posting now. Write a small program with two classes with no more than 30 lines of source. In one class have a String that you want to pass to the other class by using the other class's setString method.

    Add some System.out.println() statements in both classes to show the execution flow.
    Last edited by Norm; 09-13-2010 at 01:42 PM.

  8. #28
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default

    to set the string name to get it after from the second class right there:

    Java Code:
    String str;
    public String getString() {
    return str;
    }

  9. #29
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default

    ok give me a minute.

  10. #30
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default

    Java Code:
    import java.io.*;
    public class pro{
    public static void main (String args []) throws Exception{
    
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    String in = input.readLine();
    
    //here i am going to set the String that i am reading before to be able to geted after at the second class..
    public String setString(){
    pro2 class2 = new pro2();
    class2.setString(in);}
    }}
    
    public pro2{
    public static void main (String args []) throws Exception{
    
    String str;
    
    //here i am geting the String 'in' from the first class that i am setting before and save it into str String..
    public String getString(){
    return str;}
    
    System.out.println(str);
    }
    }

  11. #31
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    What you just posted has too many errors in it.
    I guess you need to start even simpler.
    Write a program with just ONE class that has a getString() method.

  12. #32
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

    Default

    Norm,
    i want to know first of all
    1) how to define a method in the first class (full how to) for how to get the String.

    is so simple i think but i cant understant it.

  13. #33
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    I gave you sample code for the getString method and for the setString method before.
    Here is the getString method again:
    Java Code:
    String THESTRING = .... put something here???
    
    public String getString() {
      return THESTRING;  // return THESTRING to th caller
    }

  14. #34
    JavaCy is offline Member
    Join Date
    Sep 2010
    Posts
    29
    Rep Power
    0

Page 2 of 2 FirstFirst 12

Similar Threads

  1. jsp frames
    By vasug in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-16-2010, 05:00 PM
  2. Switching Frames
    By jonnytabpni in forum New To Java
    Replies: 1
    Last Post: 11-08-2009, 10:12 PM
  3. Help regarding Frames
    By ramesh.8189 in forum AWT / Swing
    Replies: 14
    Last Post: 02-15-2009, 08:12 AM
  4. What are the hot java frames works on demand
    By mallaravi in forum Web Frameworks
    Replies: 1
    Last Post: 10-28-2008, 01:34 PM
  5. will java webBrowser work with frames
    By elipford in forum New To Java
    Replies: 2
    Last Post: 06-04-2007, 03:26 PM

Posting Permissions

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