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
|
import java.awt.*; import java.awt.event.*; import javax.swing.*;
public class Hydrant extends JPanel implements ActionListener{ GridBagConstraints gbc = new GridBagConstraints( ); String strQuery = new String(); JTextField notext = new JTextField(15); JTextArea locarea = new JTextArea(); String [] items = {"Water Pressure","0-1 Bar","2 Bar","3 Bar","4 Bar","5 Bar"}; JComboBox pressureBox = new JComboBox(items); String [] types = {"Standpipe Type","Spindle Standpipe","Country Standpipe"}; JComboBox typeBox = new JComboBox(types); JRadioButton[] faults = new JRadioButton[2]; ButtonGroup group = new ButtonGroup(); JTextArea faultarea = new JTextArea(); String [] conditions = {"Condition","Very Poor Condition","Poor Condition","Average Condition","Good Condition","Very Good Condition"}; JComboBox conditionBox = new JComboBox(conditions);
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); JFrame f = new JFrame("Fire and Emergency Medical Services, Logistics, Administration and Mobilization.");
public Hydrant( ) {
JPanel firstRow = new JPanel(); firstRow.setBorder(BorderFactory.createEtchedBorder());
//////////////////////// // make the number row// ////////////////////////
JPanel numberRow = new JPanel(); numberRow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Hydrant No."));
gbc.fill = GridBagConstraints.NONE; gbc.weightx = 1.0; gbc.weighty = 1.0; addGB(numberRow,notext, 0, 0);
addGB(firstRow, numberRow, 0, 0);
////////////////////////// // make the location row// //////////////////////////
JPanel locRow = new JPanel(); locRow.setBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Location"));
gbc.fill = GridBagConstraints.BOTH; JScrollPane locPane = new JScrollPane(locarea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); addGB(locRow,locPane, 0, 0);
addGB(firstRow, locRow, 1, 0);
addGB(this, firstRow, 0, 0);
JPanel secondRow = new JPanel(); secondRow.setBorder(BorderFactory.createEtchedBorder());
////////////////////////// // make the pressure row// //////////////////////////
JPanel pressureRow = new JPanel(); pressureRow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Last Test Pressure"));
gbc.fill = GridBagConstraints.HORIZONTAL; addGB(pressureRow,pressureBox, 0, 0);
addGB(secondRow, pressureRow, 0, 0);
/////////////////////////// // make the standpipe row// ///////////////////////////
JPanel standpipeRow = new JPanel(); standpipeRow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Standpipe Type"));
addGB(standpipeRow,typeBox, 0, 0);
addGB(secondRow, standpipeRow, 1, 0);
/////////////////////////// // make the condition row// ///////////////////////////
JPanel condRow = new JPanel(); condRow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Current Condition"));
gbc.weightx = 1.0; gbc.weighty = 1.0; addGB(condRow,conditionBox, 0, 0);
addGB(secondRow, condRow, 2, 0);
addGB(this, secondRow, 0, 2);
JPanel thirdRow = new JPanel(); thirdRow.setBorder(BorderFactory.createEtchedBorder());
/////////////////////// // make the fault row// ///////////////////////
JPanel faultRow = new JPanel(); faultRow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Fault"));
gbc.weightx = 1.0; gbc.weighty = 1.0; faults[0] = new JRadioButton ("No"); faults[1] = new JRadioButton ("Yes"); addGB(faultRow,faults[0],0,0); addGB(faultRow,faults[1],1,0); for (int i=0; i<faults.length; i++){ group.add(faults[i]); } addGB(thirdRow, faultRow, 0, 0);
//////////////////////// // make the fault1 row// ////////////////////////
JPanel fault1Row = new JPanel(); fault1Row.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Faults - Give details of fault below if answer is Yes."));
gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 0.8; gbc.weighty = 0.8; JScrollPane faultPane = new JScrollPane(faultarea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); addGB(fault1Row,faultPane, 0, 0);
addGB(thirdRow, fault1Row, 1, 0); addGB(this,thirdRow, 0, 1); ///////////////////// //add the fifth row// ///////////////////// 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, 3);
}
public void actionPerformed(ActionEvent event) { try { String myEvent = event.getActionCommand(); int number = Integer.parseInt(notext.getText()); 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 hydrant (NO,LOCATION,FAULT,PRESSURE,TYPE,CONDITION) "; strQuery += "VALUES (" + number + ",'" + locarea.getText() + "','"; strQuery += faultarea.getText() + "','" + pressureBox.getSelectedItem() + "','"; strQuery += typeBox.getSelectedItem() + "','" + conditionBox.getSelectedItem() + "')"; System.out.println(strQuery); s.Select(strQuery); s.Close(); } if ("ClearFields".equals(myEvent)) { notext.setText(""); locarea.setText(""); faultarea.setText(""); } } } catch (Exception e) { System.out.println("An Error has occured at ListenForButtonPress :"+e.toString()); } } 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 static void main(String[] args) { JFrame f = new JFrame("Hydrant Report Form"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.setSize(1024,768); f.setLocation(0,0); f.setContentPane(new Hydrant()); f.setVisible(true); } } |