-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBPanel.java
More file actions
98 lines (83 loc) · 2.87 KB
/
DBPanel.java
File metadata and controls
98 lines (83 loc) · 2.87 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*Name: Robert Hollinger
* Course: CNT 4714-Spring 2021
* Assignment Title: Project 3 - Two-Tier Client-Server Application Development With MySQL and JDBC
* Date: March 21st, 2021
*/
package sqlClientApp;
import java.awt.Dimension;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class DBPanel extends JPanel{
/**
*
*/
private static final long serialVersionUID = 1225376522146990596L;
private JComboBox<String> driver;
private JComboBox<String> url;
private JTextField username;
private JTextField password;
public DBPanel() {
setUpDBPanel();
}
public String getURL() {
return this.url.getSelectedItem().toString();
}
public String getUsername() {
return this.username.getText();
}
public String getPassword() {
return this.password.getText();
}
private void setUpDBPanel() {
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
//Panels to add Label + input field
JPanel titleP = new JPanel();
JPanel driverP = new JPanel();
JPanel urlP = new JPanel();
JPanel userP = new JPanel();
JPanel passP = new JPanel();
driverP.setMaximumSize(new Dimension(400, 35));
urlP.setMaximumSize(new Dimension(400, 35));
userP.setMaximumSize(new Dimension(400, 35));
passP.setMaximumSize(new Dimension(400, 35));
titleP.setMaximumSize(new Dimension(400, 35));
//Create Labels and initialize input fields
JLabel title = new JLabel("Enter Database Information");
String[] driverOptions = {"Select a Driver", "com.mysql.cj.jdbc.Driver", "Other"};
String[] urlOptions = {"Select database URL", "jdbc:mysql://127.0.0.1:3306/project3?useTimezone=true&serverTimezone=UTC", "Other"};
JLabel driverL = new JLabel("JDBC Driver");
JLabel urlL = new JLabel("Database URL");
JLabel userL = new JLabel("Username");
JLabel passL = new JLabel("Password");
this.driver = new JComboBox<String>(driverOptions);
this.url = new JComboBox<String>(urlOptions);
this.username = new JTextField(20);
this.password = new JTextField(20);
//Add labels and input fields to Sub-Panels
driverP.add(driverL);
driverP.add(this.driver);
urlP.add(urlL);
urlP.add(this.url);
userP.add(userL);
userP.add(this.username);
passP.add(passL);
passP.add(this.password);
titleP.add(title);
this.url.setPreferredSize(new Dimension(200, 25));
//Add Sub-Panels to object
this.add(Box.createRigidArea(new Dimension(0,10)));
this.add(titleP);
this.add(Box.createRigidArea(new Dimension(0,5)));
this.add(driverP);
this.add(Box.createRigidArea(new Dimension(0,5)));
this.add(urlP);
this.add(Box.createRigidArea(new Dimension(0,5)));
this.add(userP);
this.add(Box.createRigidArea(new Dimension(0,5)));
this.add(passP);
}
}