Is there a more efficient way to do this? It would be better if I could take the first two ints from "message" and convert it to an int. Then I want to replace it with nothing. This is my end result. NOTE: In my code I have note replaced anything yet.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
This assumes that each of these chars is a digit in the range 0-9. If it's something else, the results won't make sense. You could add code to check if the results are in the range [0-9] and throw an exception if they aren't (like parseInt() would have) if more validation is preferred.
john price wrote:Then I want to replace it with nothing. This is my end result. NOTE: In my code I have note replaced anything yet.
I can't tell what you want to do here, so I can't answer this part.
^^^ That was what I was talking about. Could I still do everything I just did with your code? Can you make it more efficient?
cc11rocks aka John Price
Joined: Mar 05, 2008
Ummmm... do you use yo3 and yo4 for anything? What is it you're trying to do?
Perhaps we should step back a minute. Forget about the code. What does a sample input string (the parameter "message") look like? And for that input, what result or output do you want to see? It may be helpful to give several examples.
Wow this SUCKS! I'm going to have to redo my WHOLE program because of this. I will explain. I built an IM client and server this past weekend. it has many advanced features such as advanced filtering (of bad words), among other features. Now, most of the users are asking for color options. I have been using a JTextArea to show the data from the server (the information the server sends to the client). For color, I decided to put it in numerical form. If the first two numbers were "00", you would make that line black. "01" red, etc. you would specify the number in the main program, which would send the numbers + the message. I had to take the numbers out so users didn't see it. I now realize I will have to use *groan* JTextPane. I use all kinds of new things for every program. This has been my first encounter with networking and has been a smooth road, with a few speed bumps along the way. Anyway, I guess I should close this. I will either trash the project or have to recode it all from scratch. The reason I will have to code it from scratch is because currently I am appending all the information to the JTextArea, which doesn't work in JTextPane. I have never used JTextPane before and I think it will be too much to be messing with networking in Java and JTextPanes, neither of which I have ever used before. If you guys could give me some help, or tell me why I should or shouldn't stay on this project, I wouldn't mind. If this is off topic, you can move/delete/or whatever to this. My original request was on-topic and I believe this is now off topic so I understand the decision you mods and users make. I guess I'm just kind of down that all my hard work went down the drain. I've worked hard on this for 25+ hours now.
John Price aka cc11rocks
Joined: Mar 05, 2008
Hmmm, well, I'm not sure what's so bad about using JTextPane, but I hope you don't find you need to trash everything. It should be possible to separate your code so that most of the networking code is separate from the JTextPane code, so that for the most part you only need to deal with all these new technologies at once.
Anyway, going back to the last question, it looks like you don't need to look for a particular character or string to delete - you're just removing the first two characters, whatever they are. This can be done without any of the other code:
Two parts to this message/request...
I've been using JTextArea. When the message comes from the server (the client does filtering, etc before it sends it out), it appends it to that JTextArea. Is there any way I could do pretty much the same thing from a JTextPane?
Then later on in my methods (I call them in the other code sections), I do all the stuff. I then append the inputsteam to the JTextArea. Is there an easy substitute in how to make the code with the JTextPane the same as my current, WORKING code?
By working, I mean it is working fine. My program is close to 1,000 lines, but most of it is filtering, which I will not have to change.
I will have to change about 100 lines to my new code. I'll also have to add more lines for the color, but I will figure that out. I've looked at JavaDocs and the tutorials. I am not sure how to implement what I have now... Please help.
Instead of these two lines (using the JTextPane):
Do I use:
John Price aka cc11rocks
EDIT: What I am asking for the first request is how to append a JTextPane. Do you have to do something like this?:
Is there a better way to do it? Does this even work?
So you've got 1,000 lines of code? And you want to modify some of them to use JTextPane, which you don't know much about?
Then take the 1,000 lines of code and stop looking at them. Start a whole new program which does nothing but fiddle about with a JTextPane. Use the examples from the tutorial (follow the link from the JTextPane API documentation) as a basis for that. Fiddle about with JTextPane until you get comfortable with it.
Once you've done that, use your new-found logic to modify your 1,000 lines of code to use JTextPane in the way you want.