-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInsert_Medication_Menu_Panel.java
More file actions
executable file
·151 lines (117 loc) · 4.22 KB
/
Insert_Medication_Menu_Panel.java
File metadata and controls
executable file
·151 lines (117 loc) · 4.22 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*****************************************************************************************************
* A menu displayed to the user to insert a new Medication into the database.
*****************************************************************************************************/
public class Insert_Medication_Menu_Panel extends JPanel
{
/* Pointer to the main java window to access its get() methods for other panels */
private Hospital_Frame main_frame;
/* Text fields for the user to enter input data */
private JTextField medication_id_field, medication_name_field, medication_use_field;
/* String to get input data from fields */
private String input;
/*********************************************************************************
* Main constructor used for setting up the Insert_Medication_Menu_Panel.
*********************************************************************************/
public Insert_Medication_Menu_Panel(Hospital_Frame frame)
{
this.main_frame = frame;
setLayout(new GridLayout(9, 2));
//setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
initializeTextFields();
add(new JLabel("Enter information of Medication to be added: "));
add(new JLabel(""));
// skip a row in the grid layout
add(new JLabel(""));
add(new JLabel(""));
add(new JLabel(" Medication ID:"));
add(medication_id_field);
add(new JLabel(" Medication Name:"));
add(medication_name_field);
add(new JLabel(" Medication Use:"));
add(medication_use_field);
// skip a row in the grid layout
add(new JLabel(""));
add(new JLabel(""));
// skip a row in the grid layout
add(new JLabel(""));
add(new JLabel(""));
add(new Main_Menu_Button(frame));
add(new Submit_Button());
}
/*********************************************************************************
* Initializes the text fields for Insert_Medication_Menu_Panel.
*********************************************************************************/
private void initializeTextFields()
{
medication_id_field = new JTextField(6);
medication_name_field = new JTextField(6);
medication_use_field = new JTextField(6);
}
/******************************************************************************
* Submit button for Insert_Medication_Menu_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();
//Medication.insert(input);
JOptionPane.showMessageDialog(null,"Submitted");
}
});
}
/******************************************************************
* 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
{
input = medication_id_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "Medication input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get medication name from field
try
{
input += medication_name_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "Medication name input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get medication use from field
try
{
input += medication_use_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "Medication use 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
} // end Medication menu class