Notepad program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    Notepad program

    Im currently doing my project "sukatoa notepad"!!! and im inspired to code it for that it looks like windows notepad... and it is 97 percent complete!!!

    But i get stucked of the last part, "Counting the lines" (update the caretPosition);

    Ive formulated 4 algorithms that will count the lines '\n' from the textArea....
    those four algorithms is sucks when it is greater than 210 lines...
    I mean the performance starts to slow after 100th lines...
    (I used it to update the Line position)/(On what line is my caretPosition now!!!)
    Calling that method from textAreaKeyRele ased event....

    Ive test those algorithms by this example...

    The quick brown fox jump over the lazy dog.(new line) times 800...

    I need your advice and idea how you implement the fastest way to count the lines...(for updating lines starts from zero to the last character where the caret positioned.... getCaretPositio n)....

    Which is the best Event to call my future method(Update what line)?(keyPress ed or KeyReleased?).. ...

    if you have the algorithm, can you show it?!!

    Thank you so much Experts!!!

    I will appreciate any reply...
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Use a CaretListener on your JTextArea; each time the caret position changes
    an event will be fired. In the listener check the JTextArea for the line and column
    positions; it has convenience methods for that. Never use low level events when
    high level semantic events are available for the same purpose. A Key event is
    a low level event; a Caret event is a high level event.

    kind regards,

    Jos

    Comment

    • sukatoa
      Contributor
      • Nov 2007
      • 539

      #3
      It really works!!!

      Thanks Jos!!! Project Finished!!!
      Looks like the same time interval at line 10 to line 879... So fast...
      no logging!!!

      =)

      Thank you!!!....

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by sukatoa
        It really works!!!

        Thanks Jos!!! Project Finished!!!
        Looks like the same time interval at line 10 to line 879... So fast...
        no logging!!!

        =)

        Thank you!!!....
        You're welcome of course. Did you add an UndoManager yet? Such a thing is
        very convenient and easy to add to your enhanced JTextArea.

        kind regards,

        Jos

        Comment

        • sukatoa
          Contributor
          • Nov 2007
          • 539

          #5
          Originally posted by JosAH
          You're welcome of course. Did you add an UndoManager yet? Such a thing is
          very convenient and easy to add to your enhanced JTextArea.

          kind regards,

          Jos
          Not yet!! Yah, Swing textArea have no Undo shortCut!! (ctrl z)....
          i don't know about Undo Manager in JTextArea...

          I will study it first!!! Thanks again...

          99%complete!!

          Comment

          Working...