当我rowcount
点击删除按钮打印时,它会打印一些任意值。我正在使用由我创建的表模型作为dt
. 它打印一些大的任意值。请帮助更正此代码。
/*
* UpdateGymFees.java
*
* Created on Sep 21, 2012, 2:26:37 PM
*/
package gymmain;
import java.sql.*;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
/**
*
* @author sony
*/
public class UpdateGymFees extends javax.swing.JFrame implements Runnable {
//String r[] = new String [7];
//String r1,r2,r3,r4,r5,r6;
String b[] = new String[4];
int v[] = new int[5];
int c[] = new int[100];
JComboBox c1 = new JComboBox();
JComboBox c2 = new JComboBox();
JComboBox c3 = new JComboBox();
DefaultTableModel dt;
DB data = new DB();
Thread t1;
/**
* Creates new form UpdateGymFees
*/
public UpdateGymFees() {
setVisible(true);
t1 = new Thread(this);
t1.start();
data.dbConnect();
initComponents();
jTable1.setRowSelectionAllowed(true);
jTable1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
String a[][] = new String[1000][1000];
int i = 0;
try {
ResultSet rs1 = data.st.executeQuery("select * from UpdateGymFees");
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private com.toedter.calendar.JDateChooser jDateChooser1;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration
public void run() {
while (true) {
try {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Logger.getLogger(MemberReg.class.getName()).log(Level.SEVERE, null, ex);
}
for (int q = 0; q < jTable1.getRowCount(); q++) {
if (("" == null ? jTable1.getValueAt(q, 4).toString() != null : !"".equals(jTable1.getValueAt(q, 4).toString()))
&& ("" == null ? jTable1.getValueAt(q, 5).toString() != null : !"".equals(jTable1.getValueAt(q, 5).toString()))
&& ("" == null ? jTable1.getValueAt(q, 6).toString() != null : !"".equals(jTable1.getValueAt(q, 6).toString()))) {
int z = 4, y = 0;
while (z < 7) {
b[y] = jTable1.getValueAt(q, z).toString();
v[y] = Integer.parseInt(b[y]);
z++;
y++;
}
v[3] = v[1] - v[2] + v[0];
v[4] = v[1] + v[0];
b[3] = Integer.toString(v[3]);
jTable1.setValueAt(v[3], q, 7);
System.out.print(v[3]);
}
}
} catch (NullPointerException npe) {
}
}
}
}
编辑
评论中的删除操作代码:
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println(jTable1.getRowCount());
int c[] = jTable1.getSelectedRows();
for (int i = 0; i < jTable1.getSelectedRowCount(); i++) {
try {
dt.removeRow(c[i]);
System.out.println(c[i]);
System.out.println(jTable1.getSelectedRowCount());
} catch (ArrayIndexOutOfBoundsException e) {
JOptionPane.showMessageDialog(null, "Select the row to be deleted");
}
}
}