Each of the buttons that I have listed performs some type of action. The button that says "reverse" in the text field should output the word hello backward olleh. The string at the very bottom, private String reverse(String inStr) is just not outputting correctly.
I'm really new at this and I can't figure out why it's not working. Most of it is working except for the hello reverse part. Can anyone help, please.
public static final int WIDTH = 600; public static final int HEIGHT = 300; public static final int LINES = 10; public static final int CHAR_PER_LINE = 40; privateJTextArea theText; private String memo1 = "Memo 1 Saved."; private String memo2 = "Memo 2 Saved."; private String memo3 = "No Memo 3."; private String memo4 = "No Memo 4."; private String memo5 = "No Memo 5."; private String memo6 = "No Memo 6."; private String reverse;
> The string at the very bottom, private String reverse(String inStr) > is just not outputting correctly.
there is no 'reverse' code in the method, it returns what it gets from the text area
memo3 = theText.getText(); theText.setText("hello"); //reverse the string then return it return memo3;
but, at this stage it is irrelevant - the method reverse(..) is not called
Lisa Lopez
Greenhorn
Joined: Apr 26, 2006
Posts: 3
posted
0
Do I put the reverse code in the button?
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> Do I put the reverse code in the button?
no, the button calls the method reverse(..) and supplies the data to satisfy the argument
the 'reverse' code goes into the reverse(..)method, where you have the notation //reverse the string then return it
generally you would have it like this
and in your 'reverse' button's actionPerformed(), the method would be called something like this theText.setText(reverse(theText.getText()));
samir Sadiki
Ranch Hand
Joined: Apr 22, 2006
Posts: 31
posted
0
Hi Lisa Your code is very good.The only thing that is missing is an implementation of the reverse method. This method should take s string, reverse it, and give you back the reversed string. When you click on the button reverse, any text that is in the textArea should be reversed. Try this code
Lisa Lopez
Greenhorn
Joined: Apr 26, 2006
Posts: 3
posted
0
Thanks Michael and Samir for your help. I think I got it working now.