-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualiseData.java
46 lines (40 loc) · 1.74 KB
/
VisualiseData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class VisualiseData extends JFrame {
public final String dbName;
public VisualiseData(String dbName){
this.dbName = dbName;
this.setTitle("product table from " + dbName);
Object[][] products = ManageData.getAllProducts(dbName);
String column[] = {"id","product","qty","cost","amt","tax","total","region"};
DefaultTableModel model = new DefaultTableModel(products,column);
JTable table = new JTable(model);
table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
JButton button = new JButton("Remove");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
// check for selected row first
if(table.getSelectedRow() != -1) {
// remove selected row from the model
String id = table.getValueAt(table.getSelectedRow(),0).toString();
ManageData.removeFromBD(id, dbName);
ManageData.removeFromHO(id);
model.removeRow(table.getSelectedRow());
JOptionPane.showMessageDialog(null, "Selected row deleted successfully");
}
}
});
add(new JScrollPane(table), BorderLayout.CENTER);
add(button, BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 300);
setLocationRelativeTo(null);
setVisible(true);
}
}