0% found this document useful (0 votes)
10 views

Computer Prog

The ConfigManager class manages configuration settings in a properties file, allowing for loading, saving, setting, retrieving, and clearing a remembered username. It utilizes Java's Properties for storing settings and includes exception handling for file operations. The RegistrationForm class sets up a GUI for user registration with validation for input data and interaction with a UserManager instance.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Computer Prog

The ConfigManager class manages configuration settings in a properties file, allowing for loading, saving, setting, retrieving, and clearing a remembered username. It utilizes Java's Properties for storing settings and includes exception handling for file operations. The RegistrationForm class sets up a GUI for user registration with validation for input data and interaction with a UserManager instance.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Config Manager:

public class ConfigManager {

private static final String CONFIG_FILE = "config.properties";

private Properties properties;

}
- This file will be used to store and retrieve configuration properties.
- This declares a Properties object that will be used to manage the key-value pairs of configuration settings.

public ConfigManager() {

properties = new Properties();

loadConfig();

}
- It initializes a new instance of the class.
- This calls the loadConfig method to load the configuration from the properties file.

private void loadConfig() {

try (InputStream input = new FileInputStream(CONFIG_FILE)) {

properties.load(input);

} catch (IOException ex) {

// File might not exist yet; this is expected for first run

}
- is responsible for loading the configuration from the properties file.
public void saveConfig() {

try (OutputStream output = new FileOutputStream(CONFIG_FILE)) {

properties.store(output, null);

} catch (IOException ex) {

ex.printStackTrace();

}
- that is responsible for saving the properties to the configuration file.
public void setRememberedUser(String username) {

properties.setProperty("rememberedUser", username);

saveConfig();
- This calls the saveConfig method to save the updated properties to the configuration file.
public String getRememberedUser() {
return properties.getProperty("rememberedUser");

}
- This defines a public method named getRememberedUser that returns a string.
public void clearRememberedUser() {

properties.remove("rememberedUser");

saveConfig();

}
- This removes the property with the key "rememberedUser" from the properties object.
summary - The ConfigManager class manages configuration settings in a properties file. It
can load and save configurations, set, retrieve, and clear a remembered username. The
class uses Java's Properties for storing settings and includes exception handling for file
operations to ensure robustness.

Class Definition and Field Declarations:

o public class RegistrationForm extends JFrame: A class


named RegistrationForm extending JFrame, making it a window in a GUI.
o Various private fields for text fields, password fields, and a UserManager instance are declared.
2. Constructor:
o public RegistrationForm(): Initializes the registration form, setting up the window and form components.
o userManager = new UserManager(): Instantiates the UserManager.
3. Window Setup:
o Sets the window title, size, default close operation, and location.
o JPanel panel = new JPanel(new GridBagLayout()): Creates a panel with a grid bag layout.
o Customizes the panel's background and border.
4. Title Label:
o JLabel titleLabel = new JLabel("Create Your Bank Account"): Creates and customizes the title
label.
o Adds the title label to the panel with specific layout constraints.
5. Form Fields and Labels:
o Various JLabel and JTextField components for username, password, confirm password, first name, last name, and
age.
o Customizes each label's font and color.
o Adds each label and text field to the panel with layout constraints.
6. Register Button:
o JButton registerButton = new JButton("Register"): Creates and customizes the register button.
o Adds an action listener to handle registration when clicked.
7. Adding Components to Panel:
o Adds all labels, text fields, and the register button to the panel using grid bag constraints.
8. Making the Window Visible:
o setVisible(true): Makes the window visible.
9. registerUser Method:
o Retrieves user input from the text fields.
o Validates the inputs (alphanumeric username, matching passwords, and numeric age).
o Attempts to register the user via userManager.registerUser().
o Displays appropriate messages for success or failure.
o Disposes of the registration form and opens a new login form upon successful registration.
10. Main Method:
o public static void main(String[] args): Entry point of the application, creating an instance
of RegistrationForm.
This code sets up a user registration form with fields for username, password, confirm password, first name, last name, and age. It includes
validation for the input data and attempts to register the user using a UserManager instance, displaying messages for success or errors.

You might also like