-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormDialog.java
68 lines (59 loc) · 2.59 KB
/
FormDialog.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
import javax.swing.*;
import java.awt.*;
/**
* Project 2: FormDialog class extends JDialog.
* General dialog component for dialogs that requires a field input.
* Stores reference to controller and parent frame, action buttons, form label
* and input.
*
* @author Abdurrahman Faqih 104675143
* @version 0.1 9 May 2024
*/
public class FormDialog extends JDialog {
private CarparkSystem controller; // Store reference to controller
// Initialize dialog components
private JFrame parent;
private JButton actionButton;
private JButton closeButton = new JButton("Cancel");
private JLabel formLabel;
private JTextField formTextField = new JTextField(10);
public FormDialog(CarparkSystem controller, JFrame parent, String title, String action, String formLabel) {
super(parent, title, true);
this.controller = controller;
this.parent = parent;
this.actionButton = new JButton(action);
this.formLabel = new JLabel(formLabel);
// Set layout of form
setLayout(new GridLayout(0, 2));
add(this.formLabel);
add(this.formTextField);
// Add action listener to action button
switch (action) {
case "Add":
this.actionButton.addActionListener(e -> DialogActionListeners
.addParkingSpotActionListener(this.formTextField, this.parent, this.controller));
break;
case "Delete":
this.actionButton.addActionListener(e -> DialogActionListeners
.deleteParkingSpotActionListener(this.formTextField, this.parent, this.controller));
break;
case "Find by registration number":
this.actionButton.addActionListener(e -> DialogActionListeners
.findByRegNoActionListener(this.formTextField, this.parent, this.controller));
break;
case "Remove by registration number":
this.actionButton.addActionListener(e -> DialogActionListeners
.removeByRegNoActionListener(this.formTextField, this.parent, this.controller));
break;
case "Find by make":
this.actionButton.addActionListener(e -> DialogActionListeners
.findByMakeActionListener(this.formTextField, this.parent, this.controller));
break;
}
add(this.actionButton);
// Add action listener to close button
this.closeButton.addActionListener(e -> this.setVisible(false));
add(this.closeButton);
this.pack();
}
}