Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to do add/delete operations in Cells in Swing table  RSS feed

 
Yasin Kazi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys , I tired to make one very useful class to implement +/- operation in a cell of Swing table. I hope it will be useful for you guys.
public class JTableSample exetends JFrame
{
.
.
public void setValueAt(Object value, int row, int column)
{
// write your formula identification code here
Formula.ComputeFormula(this, strValue);
}
}
class Formula
{
public Formula()
{
}
static String ComputeFormula(TableModel table, String strFormula)
{
strFormula = strFormula.substring(1);
String s;
try
{
StringTokenizer st = new StringTokenizer(strFormula, "+-", true);
int count = st.countTokens();
if(count != 3)
{
String s1 = "BAD";
return s1;
}
String lhand = st.nextToken();
String op = st.nextToken();
String rhand = st.nextToken();
Cell lCell = GetCellAt(table, lhand);
Cell rCell = GetCellAt(table, rhand);
double dLVal = Double.parseDouble(lCell.getValue().toString());
double dRVal = Double.parseDouble(rCell.getValue().toString());
double dRetVal;
if(op.equals("+"))
dRetVal = dLVal + dRVal;
else
if(op.equals("-"))
{
dRetVal = dLVal - dRVal;
} else
{
String s2 = "BAD OP";
return s2;
}
String s3 = Double.toString(dRetVal);
return s3;
}
catch(Exception e)
{
s = "Cannot Parse the formula";
}
return s;
}
[ January 07, 2003: Message edited by: Yasin Kazi ]
[ February 10, 2003: Message edited by: Yasin Kazi ]
[ February 15, 2003: Message edited by: Yasin Kazi ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!