Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!

Leo Max

Ranch Hand
+ Follow
since Sep 27, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Leo Max

Sorry I was trying to explain my situation. I brought up the editable text area in my first msg in order to show you what I want to happen when I press the home key.
so yes you're right. you want to find the index in the string where the caret would be if it were displayed and the home key was pressed?" <- EXACTLY

In my last message, I told you exactly what I was trying to accomplish. I'm trying to automate the process of "fixing" a line that has both languages in it such that the order of words will be correct.
5 years ago
Hi. I do wish to simulate the the HOME key because I'm only dealing with strings. There is no editable text area.

Okay I shall tell you exactly what I'm trying to do

I wrote two lines as an example in my first message. Take the first one and paste it in notepad. Click anywhere on the sentence and then press the HOME key. You'll see that the cursor moves to the end of the second arabic word. Right click on that spot (or just press the button in the keyboard that simulates a right mouse button) and choose INSERT UNICODE CONTROL CHARACTER then choose RLE RIGHT TO LEFT EMBEDDING.
You'll see that the order of the sentence has changed (look left to right) to arabic english arabic arabic.

Right click anywhere in notepad and choose SHOW UNICODE CONTROL CHARACTER. You'll see that this special character is put at the end of the line. I know the unicode rep of this character \u202B. I tried adding it but it didn't work. So I figured I'd do it like I usually do but couldn't find a way to simulate the HOME key.
5 years ago
I have a string: hi there my name is Leo
I want to move the cursor to the beginning of the sentence. That line that flashes whenever you click on any text editable area. I want it to move to the beginning of the line so that I can write something. I don't want to use \r or newstring + oldstring. It HAS TO BE HOME The line I'm writing isn't necessarily in English.

Ex: English: hi there my name is Leo <-- the HOME button takes me to right before hi (look at it from left to right)
Ex: English + Arabic: مرحباً أنا name ليو <-- the HOME button takes me to right after the second word (look at it from left to right)
5 years ago
How am I supposed to test it? Write a timer function and see how long it takes? And I didn't claim anything. But from your response, I'm going to go with method 1. Thank you.
5 years ago
In the arabic language, sometimes you need to draw two tiny forward slashes on top of or under letters. For example, the word also in arabic has these slashes on top of the o so also//

now i want to write a spell checker in java that looks into things like this.

method 1:
- use a 2D array where column1 has all the words that require the slashes but don't include them in it so index00 will be also and column2 has the same words but with the slashes in the appropriate places so index01 will be also//
- use a for loop to go through each line where in each line, we use stringtokenizer to go thru each word comparing it to the words in column1. Once you find it, replace it with column2.

method 2: same 2D array but first you use a regular expression. i create one that has all the words in column1. then i write if (m.find()) change found to true (default false) and exit. then i check if found is true. if it is, i use stringtokenizer. you know the rest

I'm looking for the efficient way to do this as the title says.

Pros of method2 (Yes im starting with 2) using regular expressions saves you the trouble of having to go through the for loop as some lines might be correct the Big O notation of using a regular expressions is at least O(n) just like the while loop which means that it's efficient because a while loop with a for loop in it is On squared

Cons of method2 it might be efficient but the lines and their spelling depends on the user writing them so you might find that you're not really saving much time using this method

As for method1, there's not much to say. Well it depends on your opinion of the pros and cons of method2. You might surprise me and tell me that the notation of regular expressions is worse than O(n) so I might as well stick to the for loop. Only O(n) and I will be entering the for loop anyways.

What do you think?
5 years ago
So to confirm, any of the 3 books (the forth is uml which you said was removed) would suffice ya? Also, just like scja was renamed to ocaj, so was the exam number right?
I have a follow up question please. I checked the books recommended in the faq section. They're several years old. For the last 5 years, haven't there been any updates/developments on 5/6 that Oracle requires its OCAJ takers to know? Is SE 6 like an OS? Once it's out, it's out and the patches added aren't important compared to the OS itself?
Ya I know how I can do this myself. I jsut figured it'd be easier if it already existed But I don't know what JSPLITPANE is. I had to google it just now when I read your reply. I was thinking I'd use a frame, container set to borderlayout or any other one since it's only two panels i'll b using, and of course the two panels. one to set my jtree and the other to display list of names of files and folders. So thank you for the reply. I will be using JSPLITPANE instead. It's new.
6 years ago
I know the code that will list all the drives available. I also know the code that will list all the files and folders in a given directory. Finally, I just learned that we can use jfilechooser in open/save scenarios and jtree to list the folders the same way windows explorer does. You have the collapse/expand column on the left and on the right you see the avialable files/folders in that location. My question is:
Is there a code that does all this or does everyone have to write it themselves? I just want to know if java has something like this before or not because I haven't foudn one but that could be because I'm googling the wrong keywords
6 years ago
well it's working on my pc and laptop now. whe ni open 2003 ms word it works. but no luck with 2007. i thought it would work since they said 97-2007. well at least i got it to work. i went tback to using exe4j and this time i added the jar file (generated by ide) and the 2 jar files from poi and it worked just as well. guess that answers my question then.
alas 2007 isn't supported. either that or im doing something wrong again

Any thoughts btw? When I enter the location of the ms 2007 docx file, it shows nothing. but when i show it a doc created by 2003 it shows me whts inside.

EDIT: im here now reading webpage and it says that i need a diff package for 2007? instead of hwpf i need xwpf. but i cant find it when i type the import line. import org.apache.poi.xwpf doesnt exist >.>

EDIT: found it! i totlaly forgot that for the import lines to work i needed to right click on the prj-properties-libraries-add jar/folder. the jar file needed for 2007 is poi-ooxml-3.8-beta3-20110606.jar

well this was fun. We all learned something. Thank for your help. And yes, it's still in it's early stages. The method I use to print the contents doesn't help me if I wanted to get them one line at a time so I need to write some workaround code.
6 years ago
Like I said, after some reading i discovered that instead of installing ant and going through hell, that my ide, netbeans already prepares a jar file for me
I'd like to ask a different question please. I read somewhere that Sun doesn't have the libraries needed to reading ms documents but apache does; poi. Is there a version limit on it? I'm running the app on a different laptop that has ms 2007 running and it's not printing anything.
6 years ago
Oh ok I think I got it. Well basically, everytime I want to run this program I'll need the console to use it? The files have to move with me wherever I go. With an exe program, it's just one file which can run anywhere so long as there's jre.

EDIT: ya I understand. Platform independant so you can run it on any platform. it's just something I wanted to try that's all.
6 years ago
java apps run in 3 ways. exe, jar, and from ide. all 3 cases require jvm present. im sorry, what do you mean? i think i fixed my prb. i decided i'd try jar but i didnt no how to turn it to jar and after a lot of reading i discovered that netbeans prepares a jar file in the dist folder of the project folder. so i used a prg called jar2exe. i added the generated jar file and the two jar files tht i needed for my app and created the exe file. it worked. i deleted the folder. it worked! im about to try it on a different laptop. but please do tell me what you meant and how i could have done that.
6 years ago
i used exe4j to turn my java app to exe. the thing, when i ran the exe in my pc it worked but when i ran it on a diff pc it didnt. just a certain function of the program i created didnt work.
the app is simple. i enter the full path of a .doc or .docx file (any ms word file). I press a button and the app opens that document and prints the first paragraph. Sun already has code/libraries for text documents but when it comes to microsoft word documents and other office files, no such thing existed. After some reading I saw that I needed to download libraries that apache built. I did. I edited my code accordingly.
When I ran exe4j, I added the jar files (part of the files located in the apache poi folder) that my app needed and I ran the generated exe file.
That's it. When I tried running it on my pc again after finding out it didnt work on adiff laptop, I don't know how it occured to me, but I decided to delete the folder that had the jar files. I figured it didnt matter because my exe already has everything it needs. But I was wrong. Soon as I deleted the folder and ran the exe file again, it didn't work. When I checked the generated errorlog file I saw the exception CLASSDEFNOUTFOUND error. I already msged the site where I downloaded exe4j from.
What does this mean? Because the jar files weren't part of Sun's production then wherever that exe file goes, the folder must follow as well? :S
Anyone here can recommend a java2exe file they used and had no problems with? thanks
6 years ago
Hello. i don't understand the explanations of the constraints weightxy, ipadxy, anchor and fill. Gridbaylayout example is the site i'm learning from. There wasn't much luck in google. There were some explanations to these terms but I still don't get it. Can someone write some examples or point me to a site that does have them? I'm looking for examples with numbers and pictures. Or at least Gridbaglayout for dummies kinda explanation

Here's my code. I added the first row of components. the app window was small when it started. When maximizing the window, the textbox was stuck to the button. Setting a frame size didn't help either. When I added the rest of the components, that was no longer the case. i don't know why that happened. Also, max/minimizing the window shouldn't make any wierd looks. It's supposed to resize itself. Now my problem is that size is stuck to date. Why I don't know or how it can be fixed. I've attached a picture to help with visualizing what I'm going after. Oh and the first insets line I added was only supposed to affect the first component. Yet somehow, everything else got pushed to the right. I thought I was going to have to add inset to a few of them but one inset fixed it all :S:S:S

All I got was that the size of the smallest component in the column becomes the size of all the components in that column. And that's when weightxy affects the components? BAAAAH!!!

6 years ago