-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDoctor_Lookup_Panel.java
More file actions
executable file
·166 lines (128 loc) · 5.23 KB
/
Doctor_Lookup_Panel.java
File metadata and controls
executable file
·166 lines (128 loc) · 5.23 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*****************************************************************************************************
* A display for the user to lookup Doctors in the database.
*****************************************************************************************************/
public class Doctor_Lookup_Panel extends JPanel
{
/* Panel for displaying output data - deleted and re-added afer every click of 'submit' */
private JPanel doctor_output_panel;
/* Fields for getting input from the user */
private JTextField ssn_field;
private String ssn;
/*********************************************************************************
* Main constructor for setting up the Doctor lookup menu.
*********************************************************************************/
public Doctor_Lookup_Panel()
{
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
JPanel top = new JPanel();
// add the components to the panel
top.add(new Centered_Text_Panel("Doctor Lookup"));
//add(new JLabel(""));
top.add(new Centered_Text_Panel("by: SSN"));
add(top);
JPanel bottom = new JPanel();
bottom.add(ssn_field = new JTextField(9));
bottom.add(new Submit_Button());
add(bottom);
add(doctor_output_panel = new Doctor_Info_Output());
}
/*********************************************************************************
* Display new output information for a doctor, if any output is currently being
* displayed, remove it first.
*********************************************************************************/
protected void displayNewDoctorOutput(JPanel output)
{
if(doctor_output_panel != null)
remove(doctor_output_panel);
add(doctor_output_panel = output);
revalidate();
repaint();
}
/******************************************************************************
* Submit button for Doctor_Lookup_Panel class.
******************************************************************************/
private class Submit_Button extends JButton
{
/******************************************************************
* Main constructor for Submit_Button
******************************************************************/
public Submit_Button()
{
super("Submit");
addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
// get input from ssn field into ssn string variable
loadText();
// pass input into Doctor instance to modify tuple
Doctor doc = new Doctor(ssn);
String result = doc.search("DOCTOR");
String[] values = result.split("\n");
// extract fields from string and pass to doctor:
displayNewDoctorOutput(new Doctor_Info_Output(values));
}
});
}
/******************************************************************
* Load input from ssn field into corresponding string variable.
*
* If load is successful, true is returned, otherwise false
* is returned.
******************************************************************/
private boolean loadText()
{
// get ssn from field
try
{
ssn = ssn_field.getText();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "SSN input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// if this point is reached age and ssn were successfully retrieved
return true;
}
} // end Submit_Button class
/*********************************************************************************
* Panel for displaying Doctor info output data based on input data from the user.
*********************************************************************************/
protected class Doctor_Info_Output extends JPanel
{
/***********************************************************************
* Default constructor for Doctor_Info_Output, initializing empty results.
***********************************************************************/
public Doctor_Info_Output()
{
add(new Centered_Text_Panel("Doctor Info:"));
}
/***********************************************************************
* Primary constructor for Doctor_Info_Output.
***********************************************************************/
public Doctor_Info_Output(String[] result)
{
setLayout(new GridLayout(result.length + 1, 1));
add(new Centered_Text_Panel("Doctor Info:"));
for(int i = 0; i < result.length; i++)
{
add(new JLabel(result[i]));
}
}
/***********************************************************************
* Primary constructor for Doctor_Info_Output.
***********************************************************************/
public Doctor_Info_Output(String result)
{
setLayout(new GridLayout(2, 1));
add(new Centered_Text_Panel("Doctor Info:"));
//add(new Centered_Text_Panel(""));
//add(new Centered_Text_Panel(result);
add(new JTextField(result));
}
} // end Doctor_Info_Output class
} // end Doctor lookup class