CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Swing code problem

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Posts
    9

    Swing code problem

    public void jTextArea2_keyTyped(KeyEvent e)
    {

    if (e.getKeyChar() == '\n')
    {
    System.out.print("got a new line");

    }

    int Count = jTextArea2.getLineCount();
    int I_1,I_2=0; String expr = "";

    try
    {
    I_1 = jTextArea2.getLineStartOffset(Count-2);
    I_2 = jTextArea2.getLineEndOffset(Count-2);
    --I_2;



    expr = jTextArea2.getText(I_1, I_2-I_1);


    }
    catch(Exception ex){}



    Hello everyone,

    This is my code that is supposed to take text from the user typing it in and save it into a variable so I can send the expression to my parser class.

    I am new to swing so I am not sure why this is not working. I also need it to keep reading in expressions until the user is done entering them.

    It would go like this

    User enters x + 4 -4 then hits enter
    then the program would send this expression to my parser class and it would parse the equation

    after this I need the program to wait for another expression to be entered ...

    help please?

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Swing code problem

    It looks like you're extracting a whole line every time a key is typed, are you trying to parse the whole line every time? why?

    If you could explain more clearly exactly what you're trying to achieve and what is going wrong, it would be easier to make suggestions.

    Doing more things faster is no substitute for doing the right things...
    S. R. Covey
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Apr 2010
    Posts
    9

    Re: Swing code problem

    What the program is supposed to do is every time an expression is typed into the text pane it extracts ONLY the expression..

    So say i typed in x+4-2x as my expression

    Then it would extract this expression from the text pane and save it into the variable expr.

    so expr = x+4-2x (I only want to extract this from the GUI text pane)

    This is so i can call my parser class and do this Parser parser = new Parser("expr");

    Then after my program will parse the equation and output it to the GUI

    Then it will wait for another expression to be typed in...

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Swing code problem

    OK. How do you plan to tell that an expression is complete so you can parse it?

    If you cannot describe what you are doing as a process, you don't know what you're doing...
    W. E. Demin
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  5. #5
    Join Date
    Apr 2010
    Posts
    9

    Re: Swing code problem

    The user will hit enter when he/she is done writing the expression

  6. #6
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Swing code problem

    In that case the first thing you should do is check to see if the pressed key is the enter key and if not return immediately.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)