Results 1 to 8 of 8
Thread: Reading from a JTextPane
- 04-15-2010, 05:00 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 4
- Rep Power
- 0
Reading from a JTextPane
Hi All,
I an new to Swing and I have a simple question:
I am writing a console which acts as a very simple calculator where the user types a math question (e.g. 7 + 6 ) and the program returns the answer. The console would like some thing as the following:
enter Input: 7 + 6
Output is: 13
What is the best way to read the input line (i.e 7 + 6). The expression "7+6" could appear any where in the input line.
Thanks in advance
- 04-15-2010, 07:12 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
First of all think about your design.
When we talking about the math equations, users can deals with large number of such as addition, multiplication, division, and more seriously the combination of those. So how you going to handle that? Do you have any limitation?
- 04-15-2010, 08:10 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Starting from Java 1.6 the distribution comes bundled with a Javascript interpreter; you can use that for the runtime interpretation of expressions:
kind regards,Java Code:import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class ScriptDemo { public static void main(String[] args) { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); String expr= "2*(3+4)"; try { System.out.println(expr+": "+engine.eval(expr)); } catch(ScriptException se) { se.printStackTrace(); } } }
Jos
- 04-15-2010, 04:35 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Giving a hint I think much better. :rolleyes:
- 04-15-2010, 06:51 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 04-16-2010, 02:36 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 04-16-2010, 08:17 AM #7
Cross post
Swing - JTextPane
db
- 04-17-2010, 03:33 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
[SOLVED] jTextPane to xml
By er_zhong in forum New To JavaReplies: 9Last Post: 04-15-2009, 04:46 AM -
StyledDocument for JTextPane
By nadia in forum AWT / SwingReplies: 2Last Post: 12-28-2008, 02:41 AM -
GetIcon from jTextPane
By Gudradain in forum AWT / SwingReplies: 4Last Post: 11-26-2008, 03:26 AM -
JTextPane (reading char and its attributes)
By Defero in forum New To JavaReplies: 0Last Post: 07-19-2008, 08:09 PM -
Transparent JTextPane
By Ada in forum AWT / SwingReplies: 1Last Post: 05-31-2007, 09:50 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks