-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputclass.java
More file actions
364 lines (324 loc) · 15 KB
/
inputclass.java
File metadata and controls
364 lines (324 loc) · 15 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
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
package traffic;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author hp
*/
public class inputclass extends javax.swing.JFrame {
/**
* Creates new form inputclass
*/
Connection conn;
PreparedStatement pst;
ResultSet rs;
String msql;
int count=0;
public inputclass() {
initComponents();
conn=connectionclass.Makeconnection();
if(conn==null)
{
JOptionPane.showMessageDialog(null, "Unable to make connection");
mainwindow wref=new mainwindow();
wref.setVisible(true);
this.setVisible(false);
}
msql="select * from cardata";
try
{
pst=conn.prepareStatement(msql);
rs=pst.executeQuery();
}
catch(SQLException se)
{
JOptionPane.showMessageDialog(null, se);
}
catch(Exception er)
{
JOptionPane.showMessageDialog(null, er);
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
carnumber = new javax.swing.JLabel();
time = new javax.swing.JLabel();
color = new javax.swing.JLabel();
toc = new javax.swing.JTextField();
carnumber2 = new javax.swing.JTextField();
accident = new javax.swing.JComboBox<>();
jLabel2 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
add = new javax.swing.JButton();
clearall = new javax.swing.JButton();
retreive = new javax.swing.JButton();
home = new javax.swing.JButton();
ownername = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
owner = new javax.swing.JTextField();
mobile = new javax.swing.JTextField();
address = new javax.swing.JTextField();
dateofentry = new com.toedter.calendar.JDateChooser();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jLabel1.setBackground(new java.awt.Color(255, 0, 204));
jLabel1.setFont(new java.awt.Font("Algerian", 1, 24)); // NOI18N
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("Data Entry Management");
jLabel1.setOpaque(true);
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 30, 390, 60));
carnumber.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
carnumber.setText("Car Number");
getContentPane().add(carnumber, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 130, 140, 30));
time.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
time.setText("Time Of Crossing");
getContentPane().add(time, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 190, 140, 30));
color.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
color.setText("Accident");
getContentPane().add(color, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 260, 90, 30));
toc.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
getContentPane().add(toc, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 190, 200, 30));
carnumber2.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
getContentPane().add(carnumber2, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 130, 200, 30));
accident.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
accident.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Yes", "No" }));
getContentPane().add(accident, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 260, 200, 30));
jLabel2.setBackground(new java.awt.Color(255, 51, 51));
jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel2.setText("Date Of Data Entry");
jLabel2.setOpaque(true);
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 220, 170, 30));
jPanel1.setBackground(new java.awt.Color(102, 255, 51));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "ACTION BUTTONS", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Algerian", 1, 14), new java.awt.Color(51, 0, 255))); // NOI18N
jPanel1.setForeground(new java.awt.Color(102, 102, 255));
add.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
add.setText("ADD");
add.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addActionPerformed(evt);
}
});
clearall.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
clearall.setText("CLEAR ALL");
clearall.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearallActionPerformed(evt);
}
});
retreive.setFont(new java.awt.Font("Times New Roman", 1, 20)); // NOI18N
retreive.setText("Retrieve");
retreive.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
retreiveActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(clearall)
.addGap(72, 72, 72)
.addComponent(retreive)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
.addComponent(add)
.addGap(44, 44, 44))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(13, 13, 13)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(retreive)
.addComponent(add)
.addComponent(clearall))
.addContainerGap(26, Short.MAX_VALUE))
);
getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 540, 530, 100));
home.setBackground(new java.awt.Color(255, 51, 153));
home.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
home.setText("HOME");
home.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
homeActionPerformed(evt);
}
});
getContentPane().add(home, new org.netbeans.lib.awtextra.AbsoluteConstraints(790, 10, -1, -1));
ownername.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
ownername.setText("Owner's Name ");
getContentPane().add(ownername, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 330, -1, -1));
jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
jLabel3.setText("Mobile Number");
getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 390, -1, -1));
jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
jLabel4.setText("Address");
getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 450, -1, -1));
owner.setEditable(false);
owner.setBackground(new java.awt.Color(255, 255, 255));
owner.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
getContentPane().add(owner, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 330, 200, 30));
mobile.setEditable(false);
mobile.setBackground(new java.awt.Color(255, 255, 255));
mobile.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
getContentPane().add(mobile, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 390, 200, 30));
address.setEditable(false);
address.setBackground(new java.awt.Color(255, 255, 255));
address.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
getContentPane().add(address, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 450, 200, 30));
dateofentry.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
getContentPane().add(dateofentry, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 260, 170, 30));
pack();
}// </editor-fold>//GEN-END:initComponents
private void homeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_homeActionPerformed
// TODO add your handling code here:
mainwindow wref=new mainwindow();
wref.setVisible(true);
this.setVisible(false);
}//GEN-LAST:event_homeActionPerformed
private void clearallActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearallActionPerformed
// TODO add your handling code here:
carnumber2.setText("");
toc.setText("");
mobile.setText("");
address.setText("");
owner.setText("");
carnumber2.enable(true);
toc.enable(true);
}//GEN-LAST:event_clearallActionPerformed
private void addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addActionPerformed
// TODO add your handling code here:
java.text.SimpleDateFormat date=new java.text.SimpleDateFormat("yyyy-MM-dd");
String mobj=date.format(dateofentry.getDate());
int fine;
int time=(Integer.parseInt(toc.getText()));
time=time%180;
if(time>=0&&time<=60)
fine=0;
else
fine=500;
String acc=(String)accident.getSelectedItem();
if(acc.equalsIgnoreCase("yes"))
count++;
try
{
msql="insert into cardata values(?,?,?,?,?,?,?) ";
pst=conn.prepareStatement(msql);
pst.setString(1,carnumber2.getText());
pst.setString(2,mobj);
pst.setString(3,owner.getText());
pst.setString(4,mobile.getText());
pst.setString(5,address.getText());
pst.setInt(6,fine);
pst.setInt(7,count);
pst.executeUpdate();
if(acc.equalsIgnoreCase("yes"))
JOptionPane.showMessageDialog(null,"Accident has occured.Call the ambulance");
}
catch(SQLException se)
{
JOptionPane.showMessageDialog(null, se);
}
catch(Exception er)
{
JOptionPane.showMessageDialog(null, er);
}
}//GEN-LAST:event_addActionPerformed
private void retreiveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_retreiveActionPerformed
// TODO add your handling code here:
String carno=carnumber2.getText();
try
{
msql="select * from data where carno=?";
pst=conn.prepareStatement(msql);
pst.setString(1,carno);
rs=pst.executeQuery();
if(rs.next())
{
owner.setText(rs.getString(1));
mobile.setText(rs.getString(3));
address.setText(rs.getString(4));
}
}
catch(SQLException se)
{
JOptionPane.showMessageDialog(null, se);
}
catch(Exception er)
{
JOptionPane.showMessageDialog(null, er);
}
}//GEN-LAST:event_retreiveActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(inputclass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(inputclass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(inputclass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(inputclass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new inputclass().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JComboBox<String> accident;
private javax.swing.JButton add;
private javax.swing.JTextField address;
private javax.swing.JLabel carnumber;
private javax.swing.JTextField carnumber2;
private javax.swing.JButton clearall;
private javax.swing.JLabel color;
private com.toedter.calendar.JDateChooser dateofentry;
private javax.swing.JButton home;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField mobile;
private javax.swing.JTextField owner;
private javax.swing.JLabel ownername;
private javax.swing.JButton retreive;
private javax.swing.JLabel time;
private javax.swing.JTextField toc;
// End of variables declaration//GEN-END:variables
}