I am developing booking system. It will have 2 main users. When user1 request booking for a vehicle, user2 will receive a popup notification stating that user1 is requesting a booking for a vehicle.
When user1 sends a vehicle booking request, the request data should be inserted in the database. In user2 controller, user2 should check/read the database and if there is new request received then there should be an automatic popup notification.
Below is my code for user2 controller to read the database and prompt a popup notification when new record exist.
I am using the TrayNotification. But it didn't popup when the app is currently open and running. However, it only popup when user login to the user2 account, after that when new bookings were made it never popup.
User2 Code:
//-------------------------- get Notifications --------------------------//
public void getNotification() throws ClassNotFoundException, SQLException{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/vbms_db";
conn =(Connection) DriverManager.getConnection(url,"root","");
System.out.println("Connected");
try {
getDepartment= lbl_holdUserDepartment.getText();
pst = conn.prepareStatement("SELECT * FROM bookings WHERE driver_department='"+getDepartment+"' AND vehicle_AvailStatus = 'Pending...'");
rs = pst.executeQuery();
if(rs.next()==true){
NotificationType nt = NotificationType.WARNING;
TrayNotification tray = new TrayNotification();
tray.setTitle("Notification");
tray.setMessage("Vehicle Booking Requested.");
tray.showAndDismiss(Duration.millis(3000));
tray.setNotificationType(nt);
}
} catch (SQLException exception) {
System.out.println(exception);
}
}
Really need help.
I could not get
TrayNotificationto work with the latest version ofJavaFX. I usedControlsFXNotification. The ideas should be very similar.Use
ScheduledServiceto periodically check new db notifications. IfScheduledServicefinds new notifications, stopScheduledServicefrom looking for new notifications. Display the current notifications usingTimeline. Restart theScheduledServiceonce theTimelinefinishes displaying the current notifications.Main
MyNotification
FakeDatabaseHandler
Module-Info
Output