0
"Sale"버튼을 클릭하면 표가 첫 번째 행에 표시되어야하고, 어떤 항목을 판매했는지, 얼마인지를 표시해야합니다. 하지만 두 번째 클릭하면 마지막 행을 삭제하고 새 테이블을 만듭니다. 새 데이터로 새 행을 만들려면 어떻게해야합니까? 이 내 코드입니다 :JButton을 클릭 한 후 JTable을 업데이트하십시오.
이if (e.getSource()==sale)
{
int tempcod=0,tempcant=0; //tempcod is the code of the product,
temocant is the number of products sold
final DefaultTableModel model = new DefaultTableModel();
model.addColumn("Product");
model.addColumn("Price");
try
{
tempcod=Integer.parseInt(cod.getText());
tempcant=Integer.parseInt(quantity.getText());
}
catch(NumberFormatException a)
{
JOptionPane.showMessageDialog(null, "Invalid Number");
}
for (int j=0;j<nulo; j++) //nulo is the number of items at sale
{
if (tempcod==codigo[j]) //id the code i wrote exist in
the list of products
{
for (int k=0; k<nulo; k++)
{
if (tempcod==ventaActual[0][k])
{
ventaActual[1][k]+=tempcant;
}
else
{
ventaActual[0][k]=tempcod;
ventaActual[1][k]=tempcant;
}
}
model.insertRow(model.getRowCount(), new Object[]{item[j],price[j]*tempcant});//this line creates the row of the table.
//item[] is the name of the item, price[] is the price of the item
JTable Lista= new JTable(model);
lista1=new JScrollPane(Lista);
lista1.setBounds(170,150,200,200);
lista1.setEnabled(false);
lista1.setVisible(true);
this.add(lista1);
a+=(tempcant*precio[j]);
String b=Integer.toString(a);
tot.setText(b);
ventaInforme=ventaActual;
}
else
{
cod.setText(null);
cantidad_n.setText(null);
}
}
}
당신은 선생님입니다. – aerojun