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.AccessibleJFrame
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.Type
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Modifier and TypeFieldDescriptionprivate AdminDashboardView
The view for the admin dashboard.private AdminLoginView
The view for admin login.private CustomerController
The controller for managing customer-related operations.private CustomerDashboardView
The view for the customer dashboard.private CustomerLoginView
The view for customer login.private CustomerRegistrationView
The view for customer registration.private EditBillView
The view for editing a bill.private EditServiceView
The view for editing a service.private Customer
The currently logged-in customer.private LoginSelectionView
The view for selecting the login type.private NewBillView
The view for creating a new bill.Fields inherited from class javax.swing.JFrame
accessibleContext, rootPane, rootPaneCheckingEnabled
Fields 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_CURSOR
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addNewBill
(String utilityType, double meterMeasurement, String date) Adds a new bill for the logged-in customer.protected void
Displays the admin dashboard view.protected void
Displays the admin login view.protected void
Opens the customer dashboard view.protected void
Displays the customer login view.protected void
deleteBill
(int id) Deletes a bill for the logged-in customer.protected void
editBill
(int id, double meterMeasurement) Edits a bill for the logged-in customer.protected void
editBillPage
(UtilityBill utilityBill) Opens the edit bill page for a specific utility bill.protected void
editService
(ServiceType serviceType, double serviceCharges, double unitCharges) Updates the service charges and unit charges for a specific service type.protected void
editServicePage
(ServiceType serviceType) Opens the edit service page for a specific service type.protected Customer
loadCustomer
(String username, String password) Loads a customer based on the provided username and password.protected void
Opens the new bill view for creating a new bill.protected void
Opens the registration view for new customers.protected void
paneChange
(JPanel panel) Changes the displayed panel in the container.protected boolean
registerNewUser
(String username, String email, String password) Registers a new user in the system.protected void
Displays the selection pane for login.protected boolean
validateCustomerLogin
(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, update
Methods 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, setUndecorated
Methods 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, toFront
Methods 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, validateTree
Methods 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, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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 theremoveAll
method, then adds thepanel
to the content pane using theadd
method. Finally, it calls therevalidate
andrepaint
methods 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
LoginSelectionView
class and assigns it to theloginSelectionView
field of the current instance. It then invokes thepaneChange
method, passing theloginSelectionView
as 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
CustomerLoginView
class and assigns it to thecustomerLoginView
field of the current instance. It then invokes thepaneChange
method, passing thecustomerLoginView
as 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:
true
if the login credentials are valid,false
otherwise.- 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 theloggedInCustomer
field 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
CustomerDashboardView
class 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
NewBillView
class 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 theloggedInCustomer
object, 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
EditBillView
class 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 theloggedInCustomer
object, 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 theloggedInCustomer
object, 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
CustomerRegistrationView
class 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
CustomerController
class 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:
true
if the user registration is successful,false
otherwise.- 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
AdminLoginView
class, 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
AdminDashboardView
class, 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
EditServiceView
class, 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
ServiceController
class 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:
-