|
||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||
com.numobjects.mathbeans.CalcSet
Class CalcSet (Calculator set bean) provides the following functionality: based solely on a string representing a set of mathematical expressions with any number of variables, automatically constructs and displays a mini-calculator panel for these expressions. The panel will have named input fields for all variables in the expressions and similar fields for the results. The user enters any numbers into the input fields and presses a button or just Enter in any of these fields. The result is immediately computed and displayed in the result fields. The user can set parameters that control the format of the output.
This bean provides a unique possibility of creating various calculators, static or dynamic, avoiding the hassle of setting up GUI, adding logic, dispatching events, etc. The user's only input is the formula itself, all the rest is figured out by the bean.
The formulas must have the form
Result1=expression1;...ResultN=expressionN
Here "ResultX" is any string providing the name for the result, e.g. "Total amount". The "expressionX" must be a valid non-constant mathematical expression (i.e. must contain variables). Variable names in the expression cannot contain spaces; if there is a need for the displayed screen name to consist of several words, enclose the name in double quotes. Here is one simple example:
"Total tax"=Quantity*"Item price"*"Tax rate"/100;
"Total amount"=Quantity*"Item price"*(1+"Tax rate"/100)+Shipping
The resulting calculator set would contain a parameter panel with fields labeled "Quantity", "Item price", "Tax rate", "Shipping", and a result panel with "Total tax" and "Total amount". As soon as one enters values in the first four fields and presses Enter, the result fields will display the computed values. Missing values are treated as zero.
Here is the code that you have to include in your program:
import com.numobjects.mathbeans.CalcSet;
...
String formula = "Total tax=Quantity*\"Item price\"*\"Tax rate\"/100;Total amount=Quantity*\"Item price\"*(1+\"Tax rate\"/100)+Shipping";
CalcSet calcSet = new CalcSet ();
calcSet.setFormulae (formula);
The calculator set is ready to be added to your container.
See Expression syntax and available functions for a full description of syntax, available functions and procedures.
CalcSolveSet,
CalcGraphSet, Serialized Form| Constructor Summary | |
CalcSet()
Constructs new CalcPanel |
|
| Method Summary | |
void |
actionPerformed(java.awt.event.ActionEvent e)
Responds to action events |
void |
addActionListener(java.awt.event.ActionListener l)
Adds action listener |
com.numobjects.beans.ControlPanel |
getControl()
Gets control panel |
java.lang.String |
getFormulae()
Gets the formula set for the calc set |
NamedFieldPanel |
getParameterPanel()
Gets the parameter panel |
int |
getParametersCount()
Gets the number of parameters of a set of formulas |
int |
getParametersDisplayCount()
Gets the number of parameters of a set of formulas |
java.lang.String[] |
getParameterTitles()
Gets panel titles for the parameter panel |
java.lang.String |
getParameterTitles(int i)
Gets panel title for the parameter panel |
int |
getPrecision()
Gets precision |
NamedFieldPanel |
getResultPanel()
Gets the result panel |
int |
getResultsCount()
Gets the number of formulas in a set |
int |
getResultsDisplayCount()
Gets the number of formulas in a set |
java.lang.String[] |
getResultTitles()
Gets panel titles for the result panel |
java.lang.String |
getResultTitles(int i)
Gets panel title for the result panel |
java.lang.String |
getResultValue(int index)
Gets value of a formula |
int |
getRounding()
Gets rounding |
java.lang.String |
getValue(java.lang.String parameterName)
Gets value of a parameter. |
void |
removeActionListener(java.awt.event.ActionListener l)
Removes action listener |
void |
setBackground(java.awt.Color c)
Sets background color |
void |
setControl(com.numobjects.beans.ControlPanel control)
Sets control panel |
void |
setFormulae(java.lang.String formulaSet)
Sets formulae |
void |
setParameterError(java.lang.String parameterName)
Sets parameter error for a parameter |
void |
setParameterError(java.lang.String parameterName,
boolean flag)
Sets parameter error for a parameter |
void |
setParameterPanel(NamedFieldPanel panel)
Sets the parameter panel |
void |
setParameterTitles(int i,
java.lang.String title)
Sets panel title for the parameter panel |
void |
setParameterTitles(java.lang.String[] titles)
Sets panel titles for the parameter panel |
void |
setPrecision(int value)
Sets precision (the number of significant digits in the calculation); range 1 - 15, default precision is 6 |
void |
setResultPanel(NamedFieldPanel panel)
Sets the result panel |
void |
setResultTitles(int i,
java.lang.String title)
Sets panel title for the result panel |
void |
setResultTitles(java.lang.String[] titles)
Sets panel titles for the result panel |
void |
setResultValue(int index,
java.lang.String result)
Sets result value for a given formula in a set |
void |
setRounding(int value)
Sets rounding (the number of digits displayed after the decimal dot); range -1 - 15, default rounding is -1 (no rounding) |
void |
updateSet()
|
| Constructor Detail |
public CalcSet()
| Method Detail |
public java.lang.String[] getParameterTitles()
public java.lang.String getParameterTitles(int i)
i - title index
public void setParameterTitles(int i,
java.lang.String title)
i - title indextitle - title (string)public void setParameterTitles(java.lang.String[] titles)
titles - titlespublic java.lang.String[] getResultTitles()
public java.lang.String getResultTitles(int i)
i - title index
public void setResultTitles(int i,
java.lang.String title)
i - title indextitle - title (string)public void setResultTitles(java.lang.String[] titles)
titles - titlespublic void setBackground(java.awt.Color c)
c - colorpublic void setPrecision(int value)
value - precision to setpublic int getPrecision()
public void setRounding(int value)
value - roundingpublic int getRounding()
public int getParametersCount()
public int getParametersDisplayCount()
public int getResultsCount()
public int getResultsDisplayCount()
public void updateSet()
public void setFormulae(java.lang.String formulaSet)
formulaSet - a string representing a set of formulae (semicolon delimited)public java.lang.String getFormulae()
public void addActionListener(java.awt.event.ActionListener l)
l - ActionListenerpublic void removeActionListener(java.awt.event.ActionListener l)
l - ActionListenerpublic void actionPerformed(java.awt.event.ActionEvent e)
e - ActionEventpublic java.lang.String getValue(java.lang.String parameterName)
parameterName - parameter namepublic java.lang.String getResultValue(int index)
index - formula index in a set
public void setResultValue(int index,
java.lang.String result)
index - formula indexresult - string value to setpublic void setParameterError(java.lang.String parameterName)
parameterName - parameter nameflag - error flag
public void setParameterError(java.lang.String parameterName,
boolean flag)
parameterName - parameter nameflag - error flagpublic NamedFieldPanel getParameterPanel()
public void setParameterPanel(NamedFieldPanel panel)
panel - parameter panelpublic void setResultPanel(NamedFieldPanel panel)
panel - result panelpublic NamedFieldPanel getResultPanel()
public com.numobjects.beans.ControlPanel getControl()
public void setControl(com.numobjects.beans.ControlPanel control)
control - control panel
|
||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||