|
| 1 | +package OOAD_Project; |
| 2 | + |
| 3 | +import java.awt.Color; |
| 4 | +import java.awt.EventQueue; |
| 5 | +import java.awt.event.ActionEvent; |
| 6 | +import java.awt.event.ActionListener; |
| 7 | +import java.sql.Connection; |
| 8 | +import java.sql.ResultSet; |
| 9 | +import java.sql.Statement; |
| 10 | +import java.text.DecimalFormat; |
| 11 | +import java.util.Random; |
| 12 | + |
| 13 | +import javax.swing.JButton; |
| 14 | +import javax.swing.JFrame; |
| 15 | +import javax.swing.JOptionPane; |
| 16 | +import javax.swing.JPanel; |
| 17 | +import javax.swing.border.EmptyBorder; |
| 18 | +import javax.swing.JTextArea; |
| 19 | + |
| 20 | +public class Info extends JFrame { |
| 21 | + |
| 22 | + /** |
| 23 | + * |
| 24 | + */ |
| 25 | + private static final long serialVersionUID = 1L; |
| 26 | + private JPanel contentPane; |
| 27 | + Connection con; |
| 28 | + Random rn = new Random(); |
| 29 | + static Color color; |
| 30 | + static int num, ran; |
| 31 | + private static DecimalFormat df = new DecimalFormat("0.00"); |
| 32 | + static String or, ch = ""; |
| 33 | + |
| 34 | + /** |
| 35 | + * Launch the application. |
| 36 | + */ |
| 37 | + public static void main(String[] args) { |
| 38 | + EventQueue.invokeLater(new Runnable() { |
| 39 | + public void run() { |
| 40 | + try { |
| 41 | + Info frame = new Info(num, ran, or, ch, color); |
| 42 | + frame.setVisible(true); |
| 43 | + } catch (Exception e) { |
| 44 | + e.printStackTrace(); |
| 45 | + } |
| 46 | + } |
| 47 | + }); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Create the frame. |
| 52 | + * |
| 53 | + * @param order_id |
| 54 | + * @param ch |
| 55 | + * @param color |
| 56 | + */ |
| 57 | + public Info(int name, int ran, String order_id, String ch, Color color) { |
| 58 | + con = AppDatabase.connect(); |
| 59 | + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 60 | + setBounds(100, 100, 700, 500); |
| 61 | + contentPane = new JPanel(); |
| 62 | + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); |
| 63 | + contentPane.setLayout(null); |
| 64 | + contentPane.setBackground(color); |
| 65 | + setContentPane(contentPane); |
| 66 | + JTextArea textArea = new JTextArea(); |
| 67 | + textArea.setBounds(349, 28, 293, 356); |
| 68 | + textArea.append("Hello World."); |
| 69 | + contentPane.add(textArea); |
| 70 | + JButton btnNewButton_1 = new JButton("User Info"); |
| 71 | + btnNewButton_1.addActionListener(new ActionListener() { |
| 72 | + |
| 73 | + @Override |
| 74 | + public void actionPerformed(ActionEvent e) { |
| 75 | + try { |
| 76 | + textArea.setText(null); |
| 77 | + Statement s = con.createStatement(); |
| 78 | + String sql = "Select * from user where user_id ='" + name + "'"; |
| 79 | + ResultSet rs = s.executeQuery(sql); |
| 80 | + if (rs.next()) { |
| 81 | + String userName = rs.getString(2); |
| 82 | + String phone = rs.getString(3); |
| 83 | + textArea.append( |
| 84 | + "Customer: " + userName + "\nMobile Number: " + phone + "\nPayment Method: " + ch); |
| 85 | + textArea.setFont(textArea.getFont().deriveFont(15f)); |
| 86 | + rs.close(); |
| 87 | + } else { |
| 88 | + JOptionPane.showMessageDialog(null, "Failed"); |
| 89 | + } |
| 90 | + |
| 91 | + } catch (Exception e1) { |
| 92 | + System.out.println(e1); |
| 93 | + } |
| 94 | + |
| 95 | + } |
| 96 | + }); |
| 97 | + btnNewButton_1.setBounds(69, 257, 171, 41); |
| 98 | + contentPane.add(btnNewButton_1); |
| 99 | + |
| 100 | + JButton btnNewButton_2 = new JButton("Driver Info"); |
| 101 | + btnNewButton_2.addActionListener(new ActionListener() { |
| 102 | + |
| 103 | + @Override |
| 104 | + public void actionPerformed(ActionEvent e) { |
| 105 | + try { |
| 106 | + textArea.setText(null); |
| 107 | + Statement s = con.createStatement(); |
| 108 | + String sql = "Select * from driver where driver_id ='" + ran + "'"; |
| 109 | + ResultSet rs = s.executeQuery(sql); |
| 110 | + if (rs.next()) { |
| 111 | + String driverName = rs.getString(2); |
| 112 | + String phone = rs.getString(3); |
| 113 | + String carModel = rs.getString(5); |
| 114 | + String carNum = rs.getString(6); |
| 115 | + String rating = rs.getString(7); |
| 116 | + textArea.append("Driver: " + driverName + "\nMobile Number: " + phone + "\n" + "Car: " |
| 117 | + + carModel + ", " + carNum + "\n" + "Rating: " + rating); |
| 118 | + textArea.setFont(textArea.getFont().deriveFont(15f)); |
| 119 | + rs.close(); |
| 120 | + } else { |
| 121 | + JOptionPane.showMessageDialog(null, "Failed"); |
| 122 | + } |
| 123 | + |
| 124 | + } catch (Exception e1) { |
| 125 | + System.out.println(e1); |
| 126 | + } |
| 127 | + |
| 128 | + } |
| 129 | + }); |
| 130 | + btnNewButton_2.setBounds(69, 51, 171, 41); |
| 131 | + contentPane.add(btnNewButton_2); |
| 132 | + JButton btnNewButton = new JButton("Order Info"); |
| 133 | + btnNewButton.addActionListener(new ActionListener() { |
| 134 | + |
| 135 | + @Override |
| 136 | + public void actionPerformed(ActionEvent e) { |
| 137 | + try { |
| 138 | + textArea.setText(null); |
| 139 | + Statement s = con.createStatement(); |
| 140 | + String sql = "Select user_name from user where user_id ='" + name + "'"; |
| 141 | + ResultSet rs = s.executeQuery(sql); |
| 142 | + if (rs.next()) { |
| 143 | + String userName = rs.getString(1); |
| 144 | + textArea.append("Customer: " + userName); |
| 145 | + rs.close(); |
| 146 | + } else { |
| 147 | + JOptionPane.showMessageDialog(null, "Failed"); |
| 148 | + } |
| 149 | + String sql1 = "Select * from driver where driver_id ='" + ran + "'"; |
| 150 | + ResultSet rs1 = s.executeQuery(sql1); |
| 151 | + if (rs1.next()) { |
| 152 | + String driverName = rs1.getString(2); |
| 153 | + String carModel = rs1.getString(5); |
| 154 | + String carNum = rs1.getString(6); |
| 155 | + textArea.append( |
| 156 | + "\n" + "Driver: " + driverName + "\n" + "Car: " + carModel + ", " + carNum + "\n"); |
| 157 | + textArea.setFont(textArea.getFont().deriveFont(15f)); |
| 158 | + } |
| 159 | + String sql2 = "Select * from current_order where order_id ='" + order_id + "'"; |
| 160 | + ResultSet rs2 = s.executeQuery(sql2); |
| 161 | + if (rs2.next()) { |
| 162 | + String curAdd = rs2.getString(4); |
| 163 | + String desAdd = rs2.getString(5); |
| 164 | + textArea.append("From: " + curAdd + " \nTo: " + desAdd); |
| 165 | + } |
| 166 | + String sql3 = "SELECT * FROM taxi JOIN driver ON taxi.car_num = driver.car_num WHERE driver_id ='" |
| 167 | + + ran + "'"; |
| 168 | + ResultSet rs3 = s.executeQuery(sql3); |
| 169 | + if (rs3.next()) { |
| 170 | + String type = rs3.getString(3); |
| 171 | + if (type.equalsIgnoreCase("vip")) { |
| 172 | + double price = 1 + 9.0 * rn.nextDouble(); |
| 173 | + price += 12; |
| 174 | + |
| 175 | + textArea.append("\n" + "Price of the ride: " + df.format(price) + " azn"); |
| 176 | + } else if (type.equalsIgnoreCase("comfort")) { |
| 177 | + double price = 1 + 9.0 * rn.nextDouble(); |
| 178 | + price += 7; |
| 179 | + textArea.append("\n" + "Price of the ride: " + df.format(price) + " azn"); |
| 180 | + } else if (type.equalsIgnoreCase("econom")) { |
| 181 | + double price = 1 + 9.0 * rn.nextDouble(); |
| 182 | + price += 3; |
| 183 | + textArea.append("\n" + "Price of the ride: " + df.format(price) + " azn"); |
| 184 | + } |
| 185 | + textArea.setFont(textArea.getFont().deriveFont(15f)); |
| 186 | + rs3.close(); |
| 187 | + } |
| 188 | + } catch (Exception e1) { |
| 189 | + System.out.println(e1); |
| 190 | + } |
| 191 | + |
| 192 | + } |
| 193 | + }); |
| 194 | + btnNewButton.setBounds(69, 119, 171, 41); |
| 195 | + contentPane.add(btnNewButton); |
| 196 | + |
| 197 | + JButton btnNewButton_3 = new JButton("Vehicle Info"); |
| 198 | + btnNewButton_3.addActionListener(new ActionListener() { |
| 199 | + |
| 200 | + @Override |
| 201 | + public void actionPerformed(ActionEvent e) { |
| 202 | + try { |
| 203 | + textArea.setText(null); |
| 204 | + Statement s = con.createStatement(); |
| 205 | + String sql = "SELECT * FROM taxi JOIN driver ON taxi.car_num = driver.car_num WHERE driver_id ='" |
| 206 | + + ran + "'"; |
| 207 | + ResultSet rs = s.executeQuery(sql); |
| 208 | + if (rs.next()) { |
| 209 | + String carModel = rs.getString(1); |
| 210 | + String carNum = rs.getString(2); |
| 211 | + String type = rs.getString(3); |
| 212 | + textArea.append("Car: " + carModel + ", " + carNum + "\n" + "Type: " + type); |
| 213 | + textArea.setFont(textArea.getFont().deriveFont(15f)); |
| 214 | + rs.close(); |
| 215 | + } else { |
| 216 | + JOptionPane.showMessageDialog(null, "Failed"); |
| 217 | + } |
| 218 | + |
| 219 | + } catch (Exception e1) { |
| 220 | + System.out.println(e1); |
| 221 | + } |
| 222 | + |
| 223 | + } |
| 224 | + }); |
| 225 | + btnNewButton_3.setBounds(69, 188, 171, 41); |
| 226 | + contentPane.add(btnNewButton_3); |
| 227 | + |
| 228 | + JButton btnNewButton_4 = new JButton("Enter Chat"); |
| 229 | + btnNewButton_4.addActionListener(new ActionListener() { |
| 230 | + |
| 231 | + @Override |
| 232 | + public void actionPerformed(ActionEvent e) { |
| 233 | + textArea.setText(null); |
| 234 | + textArea.append("Please enter your Message \nand driver will receive it: "); |
| 235 | + textArea.setFont(textArea.getFont().deriveFont(15f)); |
| 236 | + } |
| 237 | + }); |
| 238 | + btnNewButton_4.setBounds(69, 326, 171, 41); |
| 239 | + contentPane.add(btnNewButton_4); |
| 240 | + |
| 241 | + JButton btnNewButton_5 = new JButton("Exit"); |
| 242 | + btnNewButton_5.setBounds(471, 420, 110, 20); |
| 243 | + contentPane.add(btnNewButton_5); |
| 244 | + } |
| 245 | +} |
0 commit comments