-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteCustomer.java
73 lines (65 loc) · 2.49 KB
/
DeleteCustomer.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.awt.EventQueue;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
* The DeleteCustomer class provides a GUI for deleting a customer record from the database.
* It allows the user to enter a Customer ID, check its existence, and delete the record if found.
*/
public class DeleteCustomer extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField custIDTF;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
DeleteCustomer frame = new DeleteCustomer();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Constructor - Creates the frame and initializes UI components.
*/
public DeleteCustomer() {
AgencyDbase d = new AgencyDbase();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Customer ID:");
lblNewLabel.setBounds(55, 41, 183, 14);
contentPane.add(lblNewLabel);
custIDTF = new JTextField();
custIDTF.setBounds(209, 38, 96, 20);
contentPane.add(custIDTF);
custIDTF.setColumns(10);
JButton btnNewButton = new JButton("Delete");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
int custID = Integer.parseInt(custIDTF.getText());
boolean found = d.searchCustID(custID);
if (found) {
d.deleteCust(custID);
} else {
JOptionPane.showMessageDialog(null, "Customer not found!");
}
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(null, "Please enter a valid Customer ID!");
}
}
});
btnNewButton.setBounds(216, 87, 89, 23);
contentPane.add(btnNewButton);
}
}