validate();
}
elseif(e.getSource()==computerRows)
{
introws=table.getRowCount();//获取现有表格的行数。
for(inti=0;i
{
doublesum=1;
booleanboo=true;
for(intj=1;j<=2;j++)
{
try{
sum=sum*Double.parseDouble(a[i][j].toString());
}
catch(Exceptionee)
{
boo=false;
table.repaint();//表格更新显示。
}
if(boo==true)
{
a[i][3]=""+sum;//修改数组中的数据。
table.repaint();
}
}
}
}
elseif(e.getSource()==computerColums)
{
if(count==0)
{
rowsNumber=table.getRowCount();//获取表格的目前的行数。
count++;
}
else
{
rowsNumber=table.getRowCount();///获取表格的目前的行数。
rowsNumber=rowsNumber-1;//不要最后一行。
}
doubletotalSum=0;
for(intj=0;j {
totalSum=totalSum+Double.parseDouble(a[j][3].toString());
}
Objectb[][]=newObject[rowsNumber+1][4];//比数组a多一行的数组。
for(inti=0;i {
for(intj=0;j<4;j++)
b[i][j]=a[i][j];
}
b[rowsNumber][0]="一共有"+rowsNumber+"件商品";
b[rowsNumber][3]="总销售额:"+totalSum;
a=b;//重新初始化a。
table=newJTable(a,name);
getContentPane().removeAll();
getContentPane().add(newJScrollPane(table),BorderLayout.CENTER);
getContentPane().add(pSouth,BorderLayout.SOUTH);
getContentPane().add(pNorth,BorderLayout.NORTH);
validate();
}
}
}
publicclassExample