Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: passing string into method

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default passing string into method

    hiya,

    briefly what i want to do is pass a string into a method and use a variable holding the string in place of the string itself.

    public void actionPerformed(ActionEvent e)
    	{
    		if(e.getSource() == orange)
    		{
    			changeColor("orange");
    		}
     
    public String  changeColor(String text)
    	{
    		text.setBackground(Color.orange);
    		return color;
    	}


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: passing string into method

    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource() == orange)
    {
    changeColor("orange");
    }

    public String changeColor(String text)
    {
    text.setBackground(Color.orange);
    return color;
    }
    Make a constructor in the class where you want to recieve the string and make it parametrized and then throw your string from the class and you can easily recieve that in your other form.
    Hope it will work.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: passing string into method

    Have you solved this issue tabutcher?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Passing JTextField as String parameter
    By Christophe in forum Java Theory & Questions
    Replies: 3
    Last Post: April 11th, 2010, 05:32 AM
  2. string method
    By dstha in forum Object Oriented Programming
    Replies: 3
    Last Post: February 25th, 2010, 08:07 PM
  3. Replies: 1
    Last Post: February 4th, 2010, 04:23 PM
  4. Passing in more than one flag
    By anon181 in forum Loops & Control Statements
    Replies: 3
    Last Post: February 2nd, 2010, 06:37 AM
  5. how to reuse method returned string ??
    By zeeshanmirza in forum Collections and Generics
    Replies: 7
    Last Post: September 4th, 2009, 03:54 PM