Class App
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,RootPaneContainer,WindowConstants
This class represents the main application window for the Utility App. It extends the JFrame class
and contains fields for various views and controllers used in the application. It also includes a reference to the
logged-in customer. The class provides a central point for managing the application's views and controllers.
Note: The actual implementation of the views and controllers is not shown in this class. Please refer to the specific view and controller classes for more details.
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrameNested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrameNested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.TypeNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AdminDashboardViewThe view for the admin dashboard.private AdminLoginViewThe view for admin login.private CustomerControllerThe controller for managing customer-related operations.private CustomerDashboardViewThe view for the customer dashboard.private CustomerLoginViewThe view for customer login.private CustomerRegistrationViewThe view for customer registration.private EditBillViewThe view for editing a bill.private EditServiceViewThe view for editing a service.private CustomerThe currently logged-in customer.private LoginSelectionViewThe view for selecting the login type.private NewBillViewThe view for creating a new bill.Fields inherited from class javax.swing.JFrame
accessibleContext, rootPane, rootPaneCheckingEnabledFields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSORFields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddNewBill(String utilityType, double meterMeasurement, String date) Adds a new bill for the logged-in customer.protected voidDisplays the admin dashboard view.protected voidDisplays the admin login view.protected voidOpens the customer dashboard view.protected voidDisplays the customer login view.protected voiddeleteBill(int id) Deletes a bill for the logged-in customer.protected voideditBill(int id, double meterMeasurement) Edits a bill for the logged-in customer.protected voideditBillPage(UtilityBill utilityBill) Opens the edit bill page for a specific utility bill.protected voideditService(ServiceType serviceType, double serviceCharges, double unitCharges) Updates the service charges and unit charges for a specific service type.protected voideditServicePage(ServiceType serviceType) Opens the edit service page for a specific service type.protected CustomerloadCustomer(String username, String password) Loads a customer based on the provided username and password.protected voidOpens the new bill view for creating a new bill.protected voidOpens the registration view for new customers.protected voidpaneChange(JPanel panel) Changes the displayed panel in the container.protected booleanregisterNewUser(String username, String email, String password) Registers a new user in the system.protected voidDisplays the selection pane for login.protected booleanvalidateCustomerLogin(String username, String password) Validates the login credentials of a customer.Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, updateMethods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecoratedMethods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFrontMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.awt.MenuContainer
getFont, postEvent
-
Field Details
-
loginSelectionView
The view for selecting the login type. -
adminLoginView
The view for admin login. -
customerLoginView
The view for customer login. -
customerRegistrationView
The view for customer registration. -
customerDashboardView
The view for the customer dashboard. -
adminDashboardView
The view for the admin dashboard. -
newBillView
The view for creating a new bill. -
editBillView
The view for editing a bill. -
editServiceView
The view for editing a service. -
customerController
The controller for managing customer-related operations. -
loggedInCustomer
The currently logged-in customer.
-
-
Constructor Details
-
App
public App()Constructs a new instance of the Utility App.This constructor initializes the main application window. It sets the title of the window to "Utility App", sets the default close operation to exit on close, sets the size of the window to 650x750 pixels, centers the window on the screen, makes the window non-resizable, and initializes the customer controller and the logged-in customer to null. Finally, it makes the window visible and displays the selection pane.
- See Also:
-
-
Method Details
-
paneChange
Changes the displayed panel in the container.This method replaces the currently displayed panel in the container with the specified
panel. It first removes all components from the content pane using theremoveAllmethod, then adds thepanelto the content pane using theaddmethod. Finally, it calls therevalidateandrepaintmethods to update the container and repaint it.- Parameters:
panel- the panel to be displayed in the container- See Also:
-
selectionPane
protected void selectionPane()Displays the selection pane for login.This method creates a new instance of the
LoginSelectionViewclass and assigns it to theloginSelectionViewfield of the current instance. It then invokes thepaneChangemethod, passing theloginSelectionViewas a parameter, to display the selection pane for login.- See Also:
-
LoginSelectionView#paneChange(View)
-
customerLogin
protected void customerLogin()Displays the customer login view.This method creates a new instance of the
CustomerLoginViewclass and assigns it to thecustomerLoginViewfield of the current instance. It then invokes thepaneChangemethod, passing thecustomerLoginViewas a parameter, to display the customer login view.- See Also:
-
CustomerLoginView#paneChange(View)
-
validateCustomerLogin
Validates the login credentials of a customer.This method validates the login credentials of a customer by invoking the
CustomerController.validateLogin(String, String)method and passing the provided username and password as parameters.- Parameters:
username- The username of the customer.password- The password of the customer.- Returns:
trueif the login credentials are valid,falseotherwise.- See Also:
-
loadCustomer
Loads a customer based on the provided username and password.This method loads a customer by invoking the
CustomerController.loadCustomer(String, String)method and passing the provided username and password as parameters. The loaded customer is then assigned to theloggedInCustomerfield of the current instance.- Parameters:
username- The username of the customer to be loaded.password- The password of the customer to be loaded.- Returns:
- The customer that has been loaded based on the provided credentials.
- See Also:
-
customerDashboard
protected void customerDashboard()Opens the customer dashboard view.This method opens the customer dashboard view by creating a new instance of the
CustomerDashboardViewclass and passing the current instance and the logged-in customer as parameters. It then calls the#paneChange(View)method to change the active pane to the customer dashboard view.- Parameters:
loggedInCustomer- The logged-in customer object.- See Also:
-
CustomerDashboardView#paneChange(View)
-
newBillView
protected void newBillView()Opens the new bill view for creating a new bill.This method opens the new bill view by creating a new instance of the
NewBillViewclass and passing the current instance as a parameter. It then calls the#paneChange(View)method to change the active pane to the new bill view.- See Also:
-
NewBillView#paneChange(View)
-
addNewBill
Adds a new bill for the logged-in customer.This method allows the logged-in customer to add a new bill by specifying the utility type, meter measurement, and date. It calls the
Customer.addBill(String, double, String)method on theloggedInCustomerobject, passing the utilityType, meterMeasurement, and date as parameters.- Parameters:
utilityType- The type of utility for the bill (e.g., electricity, water, gas).meterMeasurement- The meter measurement for the bill.date- The date of the bill in the format "yyyy-MM-dd".- Throws:
IllegalArgumentException- if the utilityType or date is invalid.- See Also:
-
editBillPage
Opens the edit bill page for a specific utility bill.This method opens the edit bill page for a specific utility bill by creating a new instance of the
EditBillViewclass and passing the current instance and the utility bill as parameters. It then calls the#paneChange(View)method to change the active pane to the edit bill view.- Parameters:
utilityBill- The utility bill to be edited.- See Also:
-
EditBillView#paneChange(View)
-
editBill
protected void editBill(int id, double meterMeasurement) Edits a bill for the logged-in customer.This method allows the logged-in customer to edit a bill by specifying the ID of the bill and the new meter measurement. It calls the
Customer.editBill(int, double)method on theloggedInCustomerobject, passing the ID and meterMeasurement as parameters.- Parameters:
id- The ID of the bill to be edited.meterMeasurement- The new meter measurement for the bill.- Throws:
IllegalArgumentException- if the ID is invalid or does not correspond to a bill for the logged-in customer.- See Also:
-
deleteBill
protected void deleteBill(int id) Deletes a bill for the logged-in customer.This method deletes the bill with the specified ID for the currently logged-in customer. It calls the
Customer.deleteBill(int)method on theloggedInCustomerobject, passing the ID as the parameter.- Parameters:
id- The ID of the bill to be deleted.- Throws:
IllegalArgumentException- if the ID is invalid or does not correspond to a bill for the logged-in customer.- See Also:
-
openRegistrationView
protected void openRegistrationView()Opens the registration view for new customers.This method creates a new instance of the
CustomerRegistrationViewclass and sets it as the active pane by calling thepaneChange(javax.swing.JPanel)method. The registration view provides a user interface for new customers to register and create an account in the system.- See Also:
-
registerNewUser
Registers a new user in the system.This method registers a new user with the specified username, email, and password. It delegates the registration process to the
CustomerControllerclass by calling itsCustomerController.registerNewUser(java.lang.String, java.lang.String, java.lang.String)method. The method returns a boolean value indicating the success or failure of the registration process.- Parameters:
username- The username of the new user.email- The email address of the new user.password- The password of the new user.- Returns:
trueif the user registration is successful,falseotherwise.- Throws:
NullPointerException- if any of the parameters (username, email, password) is null.- See Also:
-
adminLogin
protected void adminLogin()Displays the admin login view.This method creates a new instance of the
AdminLoginViewclass, passing the current instance of the class as a parameter. It then calls thepaneChange(javax.swing.JPanel)method to change the active pane to the newly created admin login view.The admin login view provides a user interface for administrators to authenticate themselves and gain access to the administrative functionalities of the system.
- See Also:
-
adminDashboard
protected void adminDashboard()Displays the admin dashboard view.This method creates a new instance of the
AdminDashboardViewclass, passing the current instance of the class as a parameter. It then calls thepaneChange(javax.swing.JPanel)method to change the active pane to the newly created admin dashboard view.- See Also:
-
editServicePage
Opens the edit service page for a specific service type.This method creates a new instance of the
EditServiceViewclass, passing the current instance of the class and the specified service type as parameters. It then calls thepaneChange(javax.swing.JPanel)method to change the active pane to the newly created edit service view.- Parameters:
serviceType- The service type for which the edit service page should be opened.- Throws:
NullPointerException- If the serviceType parameter is null.- See Also:
-
editService
Updates the service charges and unit charges for a specific service type.This method updates the service charges and unit charges for a given service type. It calls the necessary methods from the
ServiceControllerclass to perform the updates.- Parameters:
serviceType- The service type to be edited.serviceCharges- The new service charges to be set for the service type.unitCharges- The new unit charges to be set for the service type.- Throws:
NullPointerException- If the serviceType parameter is null.IllegalArgumentException- If the serviceCharges or unitCharges parameters are negative.- See Also:
-