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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
import java.awt.*; import java.awt.event.*; import javax.swing.*;
public class Staff extends JPanel implements ActionListener{
GridBagConstraints gbc = new GridBagConstraints(); String strQuery = new String(); JLabel titleLabel = new JLabel ("Rank :"); JLabel badgeLabel = new JLabel ("Badge Number :"); JLabel yearsofserviceLabel = new JLabel ("Years of Service :"); JLabel firstLabel = new JLabel ("First Name(s) : "); JLabel initialLabel = new JLabel ("Initial :"); JLabel secondLabel = new JLabel ("Surname(s) :"); JLabel nextofkinLabel = new JLabel ("Next Of Kin :"); JLabel bloodgroupLabel = new JLabel ("Blood Group :"); JLabel dateLabel = new JLabel ("D.O.B. : "); JLabel genderLabel = new JLabel ("Gender : "); JLabel addressLabel = new JLabel ("Address(postal) : "); JLabel townLabel = new JLabel ("Town : "); JLabel countyLabel = new JLabel ("County : "); JLabel postcodeLabel = new JLabel ("Post Code : "); JLabel hometeleLabel = new JLabel ("Telephone(H) :"); JLabel workteleLabel = new JLabel ("Telephone(W) :"); JLabel mobileLabel = new JLabel ("Mobile : "); JLabel emailLabel = new JLabel ("Email Address : "); JLabel ppsLabel = new JLabel ("P.P.S. Number : "); JLabel corporationLabel = new JLabel ("Corporation No. : "); JLabel trainingLabel = new JLabel ("Training Level :"); JComboBox titleBox = new JComboBox(); JComboBox dayBox = new JComboBox(); JComboBox monthBox = new JComboBox(); JComboBox yearBox = new JComboBox(); JComboBox genderBox = new JComboBox(); JComboBox trainingBox = new JComboBox(); JComboBox bloodgroupBox = new JComboBox();
JTextField firstname = new JTextField(30); JTextField initial = new JTextField(5); JTextField surname = new JTextField(30); JTextField nextofkin = new JTextField(30); JTextField address1 = new JTextField(30); JTextField address2 = new JTextField(30); JTextField address3 = new JTextField(30); JTextField town = new JTextField(30); JTextField county = new JTextField(30); JTextField postcode = new JTextField(30); JTextField hometele = new JTextField(30); JTextField worktele = new JTextField(30); JTextField mobile = new JTextField(30); JTextField email = new JTextField(30); JTextField badge = new JTextField(30); JTextField yearsofservice = new JTextField(30); JTextField pps = new JTextField(30); JTextField corporation = new JTextField(30);
Icon quitbug = new ImageIcon("door.gif"); Icon submitbug = new ImageIcon("satelite.gif"); Icon clearfieldsbug = new ImageIcon("trash.gif"); Icon menubug = new ImageIcon("inventory.gif");
JButton quit = new JButton ("Quit",quitbug); JButton submit = new JButton ("Submit",submitbug); JButton clearfields = new JButton ("ClearFields",clearfieldsbug);
public Staff(){ JPanel titleRow = new JPanel(); titleRow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder())); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1.0; gbc.weighty = 1.0; addGB(titleRow,titleLabel, 0, 0); titleBox.addItem("Recruit Fire Fighter"); titleBox.addItem("Fire Fighter"); titleBox.addItem("Sub Officer"); titleBox.addItem("Station Officer"); titleBox.addItem("District Officer"); titleBox.addItem("Third Officer"); addGB(titleRow,titleBox, 1, 0); addGB(titleRow,badgeLabel, 0, 1); addGB(titleRow,badge, 1, 1); addGB(titleRow,yearsofserviceLabel, 0, 2); addGB(titleRow,yearsofservice, 1, 2);
JPanel dateRow = new JPanel(); addGB(titleRow,dateLabel, 0, 3); addGB(dateRow,dayBox, 1, 0); dayBox.addItem("DAY"); for (int j=1; j<32; j++) dayBox.addItem("" + j); addGB(dateRow,monthBox, 2, 0); monthBox.addItem("MONTH"); for (int k=1; k<13; k++) monthBox.addItem("" + k); addGB(dateRow,yearBox, 3, 0); yearBox.addItem("YEAR"); for (int l=1930; l<1990; l++) yearBox.addItem("" + l); addGB(titleRow,dateRow, 1, 3);
addGB(this, titleRow, 0, 0);
JPanel firstRow = new JPanel(); firstRow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder())); addGB(firstRow,firstLabel, 0, 0); addGB(firstRow,firstname, 1, 0); addGB(firstRow,initialLabel, 0, 1); addGB(firstRow,initial, 1, 1); addGB(firstRow,secondLabel, 0, 2); addGB(firstRow,surname, 1, 2); addGB(firstRow,nextofkinLabel, 0, 3); addGB(firstRow,nextofkin, 1, 3); addGB(firstRow,bloodgroupLabel, 0, 4); bloodgroupBox.addItem("A-"); bloodgroupBox.addItem("A+"); bloodgroupBox.addItem("B-"); bloodgroupBox.addItem("B+"); bloodgroupBox.addItem("O-"); bloodgroupBox.addItem("O+"); bloodgroupBox.addItem("AB-"); bloodgroupBox.addItem("AB+"); addGB(firstRow,bloodgroupBox, 1, 4); addGB(this, firstRow, 0, 1);
JPanel genderRow = new JPanel(); genderRow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder())); addGB(genderRow,genderLabel, 0, 0); genderBox.addItem("Female"); genderBox.addItem("Male"); addGB(genderRow,genderBox, 1, 0); addGB(genderRow,addressLabel, 0, 1); addGB(genderRow,address1, 1, 1); addGB(genderRow,address2, 1, 2); addGB(genderRow,address3, 1, 3); addGB(genderRow,townLabel, 0, 4); addGB(genderRow,town, 1, 4); addGB(genderRow,countyLabel, 0, 5); addGB(genderRow,county, 1, 5); addGB(genderRow,postcodeLabel, 0, 6); addGB(genderRow,postcode, 1, 6); addGB(this, genderRow, 0, 2);
JPanel teleRow = new JPanel(); teleRow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder())); addGB(teleRow,hometeleLabel, 0, 0); addGB(teleRow,hometele, 1, 0); addGB(teleRow,workteleLabel, 0, 1); addGB(teleRow,worktele, 1, 1); addGB(teleRow,mobileLabel, 0, 2); addGB(teleRow,mobile, 1, 2); addGB(teleRow,emailLabel, 0, 3); addGB(teleRow,email, 1, 3); addGB(this, teleRow, 0, 3);
JPanel ppsRow = new JPanel(); ppsRow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder())); addGB(ppsRow,ppsLabel, 0, 0); addGB(ppsRow,pps, 1, 0); addGB(ppsRow,corporationLabel, 0, 1); addGB(ppsRow,corporation, 1, 1); addGB(this, ppsRow, 0, 4);
JPanel trainingRow = new JPanel(); gbc.fill = GridBagConstraints.BOTH; trainingRow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder())); addGB(trainingRow,trainingLabel, 0, 0); trainingBox.addItem("B.A. Course(1)"); trainingBox.addItem("R.T.A. Course(2)"); trainingBox.addItem("Pump Course(3)"); trainingBox.addItem("Hot Fire Course(4)"); trainingBox.addItem("E.M.T. Course(5)"); trainingBox.addItem("Marine Rescue Course(6)"); trainingBox.addItem("Junior Officer Course(7)"); trainingBox.addItem("Senior Officer Course(8)"); addGB(trainingRow,trainingBox, 1, 0); addGB(this, trainingRow, 0, 5); JPanel fifthRow = new JPanel(); gbc.fill = GridBagConstraints.HORIZONTAL; addGB(fifthRow, quit, 0, 0); quit.addActionListener(this); addGB(fifthRow, new JLabel(""), 3, 0); addGB(fifthRow, submit, 4, 0); submit.addActionListener(this); addGB(fifthRow, new JLabel(""), 5, 0); addGB(fifthRow, clearfields, 6, 0); clearfields.addActionListener(this);
addGB(this, fifthRow, 0, 6); }
void addGB(Container cont, Component comp, int x, int y) { if ((cont.getLayout( ) instanceof GridBagLayout) == false) cont.setLayout(new GridBagLayout( )); gbc.gridx = x; gbc.gridy = y; cont.add(comp, gbc); }
public void actionPerformed(ActionEvent event) { try { String myEvent = event.getActionCommand(); int rid = 1, gid = 1, tid = 1, bid = 1; if ( event.getSource() instanceof JButton) { if ( "Quit".equals(myEvent)) { System.exit(0); } if ( "Submit".equals(myEvent)) { Submit s = new Submit(); s.Open();
strQuery = "INSERT INTO detail(corporation,badge,years,dob,nok,address,phone_h,phone_w,mobile,email)"; strQuery += "values(" + corporation.getText() + "," + badge.getText() + "," + yearsofservice.getText(); strQuery += ",'" + dayBox.getSelectedItem() +"/"+ monthBox.getSelectedItem() + "/" + yearBox.getSelectedItem(); strQuery += "','" + nextofkin.getText() + "','" + address1.getText() + ", " + address2.getText(); strQuery += ", " + address3.getText() + ", " + town.getText() + ", " + county.getText() + ", "; strQuery += postcode.getText() + "'," + hometele.getText() + ","; strQuery += worktele.getText() + "," + mobile.getText() + ",'" + email.getText() + "')"; System.out.println(strQuery); s.Select(strQuery);
strQuery = "INSERT INTO member (pps,name,corporation,rid,gid,tid,bid)values("; strQuery += pps.getText() + ",'" + firstname.getText() + " " + initial.getText() + " "; strQuery += surname.getText() + "'," + corporation.getText() + ",";
if (titleBox.getSelectedItem() == "Recruit Fire Fighter") rid = 1; else if (titleBox.getSelectedItem() == "Fire Fighter") rid =2; else if (titleBox.getSelectedItem() == "Sub Officer") rid =3; else if (titleBox.getSelectedItem() == "Station Officer") rid =4; else if (titleBox.getSelectedItem() == "District Officer") rid =5; else if (titleBox.getSelectedItem() == "Third Officer") rid =6; strQuery += rid + ",";
if (genderBox.getSelectedItem() == "Female") gid = 1; else if (genderBox.getSelectedItem() == "Male") gid =2; strQuery += gid + ",";
if (trainingBox.getSelectedItem() == "B.A. Course(1)") tid = 1; else if (trainingBox.getSelectedItem() == "R.T.A. Course(2)") tid =2; else if (trainingBox.getSelectedItem() == "Pump Course(3)") tid =3; else if (trainingBox.getSelectedItem() == "Hot Fire Course(4)") tid =4; else if (trainingBox.getSelectedItem() == "E.M.T. Course(5)") tid =5; else if (trainingBox.getSelectedItem() == "Marine Rescue Course(6)") tid =6; else if (trainingBox.getSelectedItem() == "Junior Officer Course(7)") tid =7; else if (trainingBox.getSelectedItem() == "Senior Officer Course(8)") tid =8; strQuery += tid + ",";
if (bloodgroupBox.getSelectedItem() == "A-") bid = 1; else if (bloodgroupBox.getSelectedItem() == "A+") bid =2; else if (bloodgroupBox.getSelectedItem() == "B-") bid =3; else if (bloodgroupBox.getSelectedItem() == "B+") bid =4; else if (bloodgroupBox.getSelectedItem() == "O-") bid =5; else if (bloodgroupBox.getSelectedItem() == "O+") bid =6; else if (bloodgroupBox.getSelectedItem() == "AB-") bid =7; else if (bloodgroupBox.getSelectedItem() == "AB+") bid =8; strQuery += bid + ")"; System.out.println(strQuery); s.Select(strQuery); s.Close(); } if ("ClearFields".equals(myEvent)) { firstname.setText(""); initial.setText(""); surname.setText(""); nextofkin.setText(""); address1.setText(""); address2.setText(""); address3.setText(""); town.setText(""); county.setText(""); postcode.setText(""); hometele.setText(""); worktele.setText(""); mobile.setText(""); email.setText(""); badge.setText(""); yearsofservice.setText(""); pps.setText(""); corporation.setText(""); } } } catch (Exception e) { System.out.println("An Error has occured at ListenForButtonPress :"+e.toString()); } }
public static void main(String[] args) { JFrame f = new JFrame("Staff Details Form"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.setSize(1024,768); f.setLocation(0,0); f.setContentPane(new Staff()); f.setVisible(true); } } |