-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenterDashBoard.java
More file actions
442 lines (377 loc) · 18.8 KB
/
Copy pathRenterDashBoard.java
File metadata and controls
442 lines (377 loc) · 18.8 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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package Rent_Rover;
import Rent_Rover.DataBases.DB;
import java.awt.Color;
import Rent_Rover.GradientPanel;
import Rent_Rover.GradientPanel.Direction;
import java.awt.Cursor;
import java.awt.Image;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author PC MOD NEPAL
*/
public class RenterDashBoard extends javax.swing.JFrame {
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(RenterDashBoard.class.getName());
/**
* Creates new form Form_Login
*/
public RenterDashBoard() {
initComponents();
this.setLocationRelativeTo(null);
}
private String username;
public RenterDashBoard(String username) {
initComponents();
this.username = username; // save it for later use
setProfilePicture(username); // optional: show profile pic
ImageScaler.setScaledImage(home, "C:\\Users\\97798\\Desktop\\ProjectImages\\icons8-home-48.png");
}
private void setProfilePicture(String username) {
try {
Connection con = DB.getConnection();
String query = "SELECT username, profile_picture FROM customer WHERE username = ?";
PreparedStatement ps = con.prepareStatement(query);
ps.setString(1, username);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
// Set username in text field
ufield.setText(rs.getString("username"));
// Set profile picture in JLabel
byte[] imgBytes = rs.getBytes("profile_picture");
if (imgBytes != null) {
ImageIcon imageIcon = new ImageIcon(imgBytes);
Image image = imageIcon.getImage().getScaledInstance(pfp.getWidth(), pfp.getHeight(), Image.SCALE_SMOOTH);
pfp.setIcon(new ImageIcon(image));
CircularLabel.makeCircular(pfp);
}
}
rs.close();
ps.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 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() {
jPanel1 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
pfp = new javax.swing.JLabel();
RentButton = new javax.swing.JLabel();
carpfp = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
ufield = new RoundedTextField(10);
uname = new javax.swing.JLabel();
brand = new javax.swing.JLabel();
bfield = new RoundedTextField(10);
model = new javax.swing.JLabel();
mfield = new RoundedTextField(10);
location = new javax.swing.JLabel();
mfield1 = new RoundedTextField(10);
price = new javax.swing.JLabel();
pfield = new RoundedTextField(10);
jLabel6 = new javax.swing.JLabel();
select_vehicle = new javax.swing.JLabel();
home = new javax.swing.JLabel();
brandLogo = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(51, 102, 0));
jPanel1.setForeground(new java.awt.Color(255, 255, 255));
jPanel1.setPreferredSize(new java.awt.Dimension(1366, 768));
jPanel3.setBackground(new java.awt.Color(255, 255, 255));
jPanel3.setPreferredSize(new java.awt.Dimension(1366, 768));
jPanel3.setLayout(null);
jPanel3.add(pfp);
pfp.setBounds(1280, 20, 60, 60);
RentButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
RentButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
RentButtonMouseClicked(evt);
}
});
jPanel3.add(RentButton);
RentButton.setBounds(267, 250, 150, 270);
carpfp.setBackground(new java.awt.Color(0, 255, 0));
carpfp.setOpaque(true);
jPanel3.add(carpfp);
carpfp.setBounds(830, 270, 380, 270);
jPanel2.setBackground(new java.awt.Color(0, 255, 0));
jPanel2.setOpaque(false);
ufield.setEditable(false);
ufield.setBackground(new java.awt.Color(0, 0, 0));
ufield.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
ufield.setForeground(new java.awt.Color(255, 255, 255));
ufield.setOpaque(true);
uname.setFont(new java.awt.Font("Lucida Fax", 1, 14)); // NOI18N
uname.setForeground(new java.awt.Color(255, 255, 255));
uname.setText("Username");
brand.setFont(new java.awt.Font("Lucida Fax", 1, 14)); // NOI18N
brand.setForeground(new java.awt.Color(255, 255, 255));
brand.setText("Brand");
bfield.setBackground(new java.awt.Color(0, 0, 0));
bfield.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
bfield.setForeground(new java.awt.Color(255, 255, 255));
model.setFont(new java.awt.Font("Lucida Fax", 1, 14)); // NOI18N
model.setForeground(new java.awt.Color(255, 255, 255));
model.setText("Model");
mfield.setBackground(new java.awt.Color(0, 0, 0));
mfield.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
mfield.setForeground(new java.awt.Color(255, 255, 255));
location.setFont(new java.awt.Font("Lucida Fax", 1, 14)); // NOI18N
location.setForeground(new java.awt.Color(255, 255, 255));
location.setText("Location");
mfield1.setBackground(new java.awt.Color(0, 0, 0));
mfield1.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
mfield1.setForeground(new java.awt.Color(255, 255, 255));
price.setFont(new java.awt.Font("Lucida Fax", 1, 14)); // NOI18N
price.setForeground(new java.awt.Color(255, 255, 255));
price.setText("Price/Day");
pfield.setBackground(new java.awt.Color(0, 0, 0));
pfield.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
pfield.setForeground(new java.awt.Color(255, 255, 255));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(pfield, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
.addComponent(mfield1, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
.addComponent(location, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(mfield)
.addComponent(uname)
.addComponent(ufield)
.addComponent(brand)
.addComponent(bfield)
.addComponent(model, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(price))
.addContainerGap(101, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(uname)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ufield, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(brand)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bfield, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(model)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mfield, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(location)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mfield1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(price)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pfield, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(27, Short.MAX_VALUE))
);
jPanel3.add(jPanel2);
jPanel2.setBounds(480, 220, 310, 360);
jLabel6.setFont(new java.awt.Font("Perpetua", 1, 36)); // NOI18N
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setText("Become @ Renter");
jPanel3.add(jLabel6);
jLabel6.setBounds(690, 170, 280, 50);
select_vehicle.setFont(new java.awt.Font("Lucida Fax", 1, 24)); // NOI18N
select_vehicle.setForeground(new java.awt.Color(255, 255, 255));
select_vehicle.setText("Select Your Vehicle");
select_vehicle.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
select_vehicleMouseClicked(evt);
}
});
jPanel3.add(select_vehicle);
select_vehicle.setBounds(900, 560, 250, 40);
home.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
home.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
homeMouseClicked(evt);
}
});
jPanel3.add(home);
home.setBounds(70, 40, 30, 30);
brandLogo.setBackground(new java.awt.Color(92, 165, 238));
brandLogo.setIcon(new javax.swing.ImageIcon("C:\\Users\\97798\\Desktop\\ProjectImages\\renterdashboard.png")); // NOI18N
brandLogo.setOpaque(true);
brandLogo.setPreferredSize(new java.awt.Dimension(1366, 768));
jPanel3.add(brandLogo);
brandLogo.setBounds(0, 0, 1370, 770);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
public class ImageUtils {
public static byte[] imageIconToBytes(ImageIcon icon) throws Exception {
java.awt.image.BufferedImage bImage = new java.awt.image.BufferedImage(
icon.getIconWidth(),
icon.getIconHeight(),
java.awt.image.BufferedImage.TYPE_INT_ARGB
);
java.awt.Graphics2D g2 = bImage.createGraphics();
icon.paintIcon(null, g2, 0, 0);
g2.dispose();
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
javax.imageio.ImageIO.write(bImage, "png", baos);
return baos.toByteArray();
}
}
private void RentButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RentButtonMouseClicked
try {
// 1. Get values from fields
String username = this.username; // already set from login
String brandText = bfield.getText().trim();
String modelText = mfield.getText().trim();
String locationText = mfield1.getText().trim();
String priceText = pfield.getText().trim();
// 2. Check if all fields are filled
if (brandText.isEmpty() || modelText.isEmpty() || locationText.isEmpty() || priceText.isEmpty() || carpfp.getIcon() == null) {
StylishPopup.showError(this, "Please fill all details and select a vehicle image!");
return;
}
// 3. Convert vehicle image to byte[]
ImageIcon icon = (ImageIcon) carpfp.getIcon();
byte[] carImage = ImageUtils.imageIconToBytes(icon); // utility function
// 4. Insert into bookings table
Connection con = DB.getConnection();
String query = "INSERT INTO bookings (username, brand, model, location, price_per_day, vehicle_image) VALUES (?, ?, ?, ?, ?, ?)";
PreparedStatement ps = con.prepareStatement(query);
ps.setString(1, username);
ps.setString(2, brandText);
ps.setString(3, modelText);
ps.setString(4, locationText);
ps.setString(5, priceText);
ps.setBytes(6, carImage);
int inserted = ps.executeUpdate();
if (inserted > 0) {
StylishPopup.showSuccess(this, "Vehicle successfully registered!");
new Primary_Screen_Logged(this.username).setVisible(true);
this.dispose();
// Optionally clear fields or redirect
}
ps.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
StylishPopup.showError(this, "Error: " + e.getMessage());
}
}//GEN-LAST:event_RentButtonMouseClicked
private void select_vehicleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_select_vehicleMouseClicked
select_vehicle.setCursor(new Cursor(Cursor.HAND_CURSOR));
select_vehicle.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
javax.swing.JFileChooser fileChooser = new javax.swing.JFileChooser();
int option = fileChooser.showOpenDialog(null);
if (option == javax.swing.JFileChooser.APPROVE_OPTION) {
java.io.File file = fileChooser.getSelectedFile();
String path = file.getAbsolutePath();
javax.swing.ImageIcon icon = new javax.swing.ImageIcon(path);
java.awt.Image img = icon.getImage().getScaledInstance(carpfp.getWidth(), carpfp.getHeight(), java.awt.Image.SCALE_SMOOTH);
carpfp.setIcon(new javax.swing.ImageIcon(img));
carpfp.putClientProperty("imgPath", path); // store path for later
}
}
});
}//GEN-LAST:event_select_vehicleMouseClicked
private void homeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_homeMouseClicked
Primary_Screen_Logged primary = new Primary_Screen_Logged(this.username);
primary.setVisible(true);
this.dispose();
}//GEN-LAST:event_homeMouseClicked
/**
* @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 (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) {
logger.log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> new RenterDashBoard().setVisible(true));
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel RentButton;
private javax.swing.JTextField bfield;
private javax.swing.JLabel brand;
private javax.swing.JLabel brandLogo;
private javax.swing.JLabel carpfp;
private javax.swing.JLabel home;
private javax.swing.JLabel jLabel6;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JLabel location;
private javax.swing.JTextField mfield;
private javax.swing.JTextField mfield1;
private javax.swing.JLabel model;
private javax.swing.JTextField pfield;
private javax.swing.JLabel pfp;
private javax.swing.JLabel price;
private javax.swing.JLabel select_vehicle;
private javax.swing.JTextField ufield;
private javax.swing.JLabel uname;
// End of variables declaration//GEN-END:variables
}