Results 1 to 11 of 11
  1. #1
    calnastic is offline Member
    Join Date
    Jun 2011
    Posts
    18
    Rep Power
    0

    Default Math equation in Java Applet

    Hi,
    I am trying to design an applet to draw parabola. The equation displayed is something like:
    y = 3x^2 + 5x + 7
    which is ugly.

    Is there a way I can display the formal math equation? Like this:

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,039
    Rep Power
    10

    Default

    How are you displaying it? Using a JLabel? A JTextField? The Graphics.drawString() method? Something else?

    In short, the answer is yes. But it depends on how you're doing your drawing.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    calnastic is offline Member
    Join Date
    Jun 2011
    Posts
    18
    Rep Power
    0

    Default

    I am using a JLabel

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,039
    Rep Power
    10

    Default

    In that case, you could probably use HTML.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    JavaForums's Avatar
    JavaForums is offline Administrator
    Join Date
    Dec 2006
    Posts
    876
    Rep Power
    10

    Default

    What do you mean with ugly? I guess that it does not look smooth.

    You can use a plotting library. Check this:

    How to draw a Smooth Curve using jfreechart

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,039
    Rep Power
    10

    Default

    I was under the impression that he was talking about the text display of the actual equation, not the graph itself. In which case, HTML tags might work. I could be wrong though.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    JavaForums's Avatar
    JavaForums is offline Administrator
    Join Date
    Dec 2006
    Posts
    876
    Rep Power
    10

    Default

    Quote Originally Posted by KevinWorkman View Post
    I was under the impression that he was talking about the text display of the actual equation, not the graph itself. In which case, HTML tags might work. I could be wrong though.
    I can be wrong too :) I noticed the second part of the message later..

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,777
    Blog Entries
    7
    Rep Power
    21

    Default

    html sucks; look what my expression transmogrifier did to the OP's example:

    Java Code:
    -<i>x</i><sup><font color=\"#8000\">2</font></sup>&minus;<font color=\"#8000\">6</font>&middot;<i>x</i>+<font color=\"#8000\">7</font>
    It can't even do double (or more) subscripts; it may be adequate for simple single superscripts, but that's about it. I wonder if a LaTex package exists for Java ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    JavaForums's Avatar
    JavaForums is offline Administrator
    Join Date
    Dec 2006
    Posts
    876
    Rep Power
    10

    Default

    Quote Originally Posted by JosAH View Post
    html sucks; look what my expression transmogrifier did to the OP's example:
    I wonder if a LaTex package exists for Java ...
    Good question! Our friend google returned this:

    JLaTeXMath - A Java API to render LaTeX - A Java package to display LaTeX code in mathematical mode

  10. #10
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default

    @ administrator:
    I just tried it with your link. It works. I have a JButton now with a complicated formula on it (as an icon). Now I seem to have to learn TEX to make formulas other then this example.
    @OP:
    I had some difficulty finding an example. I used Feature Requests - JAMWiki Java Wiki Engine If you need more help, I'm an expert now
    Last edited by Jodokus; 06-23-2011 at 04:09 AM.
    No bug ever had to calculate its fitnessfunction.

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,777
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by JavaForums View Post
    That's cute; I'll give it a try; thanks for the link.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Reading a Math Equation in the console
    By JonB319 in forum New To Java
    Replies: 7
    Last Post: 06-10-2011, 02:54 PM
  2. converting an algebraic equation to Java
    By fsuarjun03 in forum New To Java
    Replies: 2
    Last Post: 03-09-2010, 08:58 PM
  3. Need help with math equation
    By annabellastorm in forum New To Java
    Replies: 4
    Last Post: 01-10-2010, 06:12 PM
  4. Help with an equation in java
    By coco in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 08:47 AM
  5. Help with quadratic equation in java
    By paul in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 09:23 PM

Posting Permissions

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