Skip to content

Commit 054e94a

Browse files
authored
Add files via upload
1 parent e7ab37f commit 054e94a

16 files changed

+1125
-0
lines changed

Task 3/AppDatabase.java

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package OOAD_Project;
2+
3+
import java.sql.Connection;
4+
import java.sql.DriverManager;
5+
import javax.swing.JOptionPane;
6+
7+
public class AppDatabase {
8+
static String url = "jdbc:mysql://localhost:3306/test?useTimezone=true&serverTimezone=UTC";
9+
static String usern = "root";
10+
static String password = "";
11+
12+
public static Connection connect() {
13+
try {
14+
Class.forName("com.mysql.jdbc.Driver");
15+
Connection con = DriverManager.getConnection(url, usern, password);
16+
return con;
17+
} catch (Exception e) {
18+
JOptionPane.showMessageDialog(null, e);
19+
return null;
20+
}
21+
}
22+
}

Task 3/AppFirstPage.java

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package OOAD_Project;
2+
3+
import java.awt.BorderLayout;
4+
import java.awt.Color;
5+
import java.awt.EventQueue;
6+
import java.awt.Font;
7+
import java.awt.SystemColor;
8+
import java.awt.event.ActionEvent;
9+
import java.awt.event.ActionListener;
10+
import java.util.Random;
11+
12+
import javax.swing.ImageIcon;
13+
import javax.swing.JButton;
14+
import javax.swing.JFrame;
15+
import javax.swing.JLabel;
16+
import javax.swing.JPanel;
17+
import javax.swing.SwingConstants;
18+
import javax.swing.border.EmptyBorder;
19+
20+
import net.miginfocom.swing.MigLayout;
21+
22+
public class AppFirstPage extends JFrame {
23+
24+
/**
25+
*
26+
*/
27+
private static final long serialVersionUID = 1L;
28+
static AppFirstPage frame;
29+
private JPanel contentPane;
30+
Random rn = new Random();
31+
32+
/**
33+
* Launch the application.
34+
*/
35+
public static void main(String[] args) {
36+
EventQueue.invokeLater(new Runnable() {
37+
public void run() {
38+
try {
39+
frame = new AppFirstPage();
40+
frame.setVisible(true);
41+
} catch (Exception e) {
42+
e.printStackTrace();
43+
}
44+
}
45+
});
46+
}
47+
48+
/**
49+
* Create the frame.
50+
*/
51+
public AppFirstPage() {
52+
Color color = new Color(244, 208, 63);
53+
color.brighter();
54+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
55+
setBounds(100, 100, 670, 400);
56+
contentPane = new JPanel();
57+
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
58+
contentPane.setLayout(new BorderLayout(0, 0));
59+
contentPane.setBackground(color);
60+
setContentPane(contentPane);
61+
62+
JPanel panel = new JPanel();
63+
panel.setToolTipText("Hi");
64+
panel.setForeground(Color.PINK);
65+
contentPane.add(panel, BorderLayout.CENTER);
66+
panel.setLayout(new MigLayout("", "[1px][][][][][][][][][][]", "[1px][][][][][][][][][][][][][][][][]"));
67+
68+
JLabel lblNewLabel = new JLabel("Taxi Dispatch Application");
69+
lblNewLabel.setBackground(SystemColor.activeCaption);
70+
lblNewLabel.setFont(new Font("UD Digi Kyokasho NP-R", Font.PLAIN, 27));
71+
lblNewLabel.setForeground(SystemColor.textHighlight);
72+
panel.add(lblNewLabel, "cell 4 7");
73+
74+
JButton btnNewButton_1 = new JButton("REGISTER");
75+
btnNewButton_1.setBackground(Color.WHITE);
76+
panel.add(btnNewButton_1, "cell 4 12");
77+
btnNewButton_1.addActionListener(new ActionListener() {
78+
79+
@Override
80+
public void actionPerformed(ActionEvent e) {
81+
Registration rg = new Registration(color);
82+
rg.setVisible(true);
83+
rg.toFront();
84+
}
85+
86+
});
87+
88+
JLabel lblNewLabel_1 = new JLabel(" OR");
89+
panel.add(lblNewLabel_1, "cell 4 13");
90+
91+
JButton btnNewButton = new JButton("LOG IN");
92+
btnNewButton.setBackground(Color.WHITE);
93+
btnNewButton.setVerticalAlignment(SwingConstants.BOTTOM);
94+
panel.add(btnNewButton, "cell 4 14");
95+
btnNewButton.addActionListener(new ActionListener() {
96+
97+
@Override
98+
public void actionPerformed(ActionEvent e) {
99+
// frame.dispose();
100+
Log us = new Log(color);
101+
us.setVisible(true);
102+
us.toFront();
103+
}
104+
105+
});
106+
107+
JLabel image = new JLabel("");
108+
image.setIcon(new ImageIcon("src/OOAD_HW2/Taxi (2).png"));
109+
panel.add(image, "cell 50 50");
110+
111+
}
112+
113+
}

Task 3/Application.java

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package OOAD_Project;
2+
3+
public class Application {
4+
public static void main(String[] args) {
5+
AppFirstPage app = new AppFirstPage();
6+
app.setVisible(true);
7+
app.toFront();
8+
}
9+
10+
}

Task 3/Dr.png

20.8 KB
Loading

Task 3/Info.java

+245
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
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

Comments
 (0)