|
1 | 1 | # 20CYS383 Java Programming Lab
|
2 | 2 |   
|
3 | 3 |
|
4 |
| -### JPL-XX |
| 4 | +### Secure Internet Banking |
5 | 5 |
|
6 |
| -#### Team Members |
| 6 | +### Code |
| 7 | + |
| 8 | +``` |
| 9 | +import javax.swing.*; |
| 10 | +import java.awt.*; |
| 11 | +import java.awt.event.ActionEvent; |
| 12 | +import java.awt.event.ActionListener; |
| 13 | +
|
| 14 | +public class InternetBankingSystem extends JFrame { |
| 15 | + private JPanel loginPanel; |
| 16 | + private JPanel mobileNumberPanel; |
| 17 | + private JPanel otpPanel; |
| 18 | + private JPanel bankPanel; |
| 19 | +
|
| 20 | + // Simulated database (for demonstration purposes only) |
| 21 | + private String correctUsername = "Nishant V"; |
| 22 | + private String correctPassword = "password123"; |
| 23 | + private String correctMobileNumber = "25817"; // Last 5 digits of the mobile number |
| 24 | +
|
| 25 | + public InternetBankingSystem() { |
| 26 | + // Set up the main frame |
| 27 | + setTitle("Secure Internet Banking"); |
| 28 | + setSize(500, 300); |
| 29 | + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 30 | + setLayout(new CardLayout()); |
| 31 | +
|
| 32 | + // Create panels |
| 33 | + loginPanel = new JPanel(); |
| 34 | + mobileNumberPanel = new JPanel(); |
| 35 | + otpPanel = new JPanel(); |
| 36 | + bankPanel = new JPanel(); |
| 37 | +
|
| 38 | + setupLoginPanel(); |
| 39 | + setupMobileNumberPanel(); |
| 40 | + setupOTPPanel(); |
| 41 | + setupBankPanel(); |
| 42 | +
|
| 43 | + // Initially, show the login panel |
| 44 | + add(loginPanel, "Login"); |
| 45 | + add(mobileNumberPanel, "MobileNumber"); |
| 46 | + add(otpPanel, "OTP"); |
| 47 | + add(bankPanel, "Bank"); |
| 48 | +
|
| 49 | + showPanel("Login"); |
| 50 | + } |
| 51 | +
|
| 52 | + private void showPanel(String panelName) { |
| 53 | + CardLayout cardLayout = (CardLayout) getContentPane().getLayout(); |
| 54 | + cardLayout.show(getContentPane(), panelName); |
| 55 | + } |
| 56 | +
|
| 57 | + private void setupLoginPanel() { |
| 58 | + loginPanel.setLayout(new GridBagLayout()); |
| 59 | + GridBagConstraints gbc = new GridBagConstraints(); |
| 60 | + gbc.gridx = 0; |
| 61 | + gbc.gridy = 0; |
| 62 | + gbc.insets = new Insets(30, 10, 5, 10); // Padding for top, left, bottom, right |
| 63 | +
|
| 64 | + JLabel titleLabel = new JLabel("Welcome to Secure Internet Banking"); |
| 65 | + titleLabel.setFont(new Font("Arial", Font.BOLD, 18)); |
| 66 | + loginPanel.add(titleLabel, gbc); |
| 67 | +
|
| 68 | + gbc.gridy = 1; |
| 69 | + JLabel usernameLabel = new JLabel("Username:"); |
| 70 | + loginPanel.add(usernameLabel, gbc); |
| 71 | +
|
| 72 | + gbc.gridy = 2; |
| 73 | + JLabel passwordLabel = new JLabel("Password:"); |
| 74 | + loginPanel.add(passwordLabel, gbc); |
| 75 | +
|
| 76 | + gbc.gridx = 1; |
| 77 | + gbc.gridy = 1; |
| 78 | + gbc.fill = GridBagConstraints.HORIZONTAL; |
| 79 | + JTextField usernameField = new JTextField(20); // Increased width |
| 80 | + loginPanel.add(usernameField, gbc); |
| 81 | +
|
| 82 | + gbc.gridy = 2; |
| 83 | + JPasswordField passwordField = new JPasswordField(20); // Increased width |
| 84 | + loginPanel.add(passwordField, gbc); |
| 85 | +
|
| 86 | + gbc.gridy = 3; |
| 87 | + gbc.gridx = 0; |
| 88 | + gbc.gridwidth = 2; |
| 89 | + gbc.anchor = GridBagConstraints.CENTER; |
| 90 | + JButton loginButton = new JButton("Login"); |
| 91 | + loginPanel.add(loginButton, gbc); |
| 92 | +
|
| 93 | + loginButton.addActionListener(new ActionListener() { |
| 94 | + @Override |
| 95 | + public void actionPerformed(ActionEvent e) { |
| 96 | + String username = usernameField.getText(); |
| 97 | + char[] passwordChars = passwordField.getPassword(); |
| 98 | + String password = new String(passwordChars); |
| 99 | +
|
| 100 | + if (!username.isEmpty() && !password.isEmpty()) { |
| 101 | + if (username.equals(correctUsername) && password.equals(correctPassword)) { |
| 102 | + showPanel("MobileNumber"); |
| 103 | + } else { |
| 104 | + JOptionPane.showMessageDialog(null, "Invalid username or password."); |
| 105 | + } |
| 106 | + } else { |
| 107 | + JOptionPane.showMessageDialog(null, "Please enter both username and password."); |
| 108 | + } |
| 109 | + // Clear the password field after use |
| 110 | + passwordField.setText(""); |
| 111 | + } |
| 112 | + }); |
| 113 | + } |
| 114 | +
|
| 115 | + private void setupMobileNumberPanel() { |
| 116 | + mobileNumberPanel.setLayout(new GridBagLayout()); |
| 117 | + GridBagConstraints gbc = new GridBagConstraints(); |
| 118 | + gbc.gridx = 0; |
| 119 | + gbc.gridy = 0; |
| 120 | + gbc.insets = new Insets(20, 10, 5, 10); // Padding for top, left, bottom, right |
| 121 | +
|
| 122 | + JLabel mobileNumberLabel = new JLabel("Enter the last 5 digits of your mobile number:"); |
| 123 | + mobileNumberPanel.add(mobileNumberLabel, gbc); |
| 124 | +
|
| 125 | + gbc.gridy = 1; |
| 126 | + gbc.fill = GridBagConstraints.HORIZONTAL; |
| 127 | + JTextField mobileNumberField = new JTextField(10); |
| 128 | + mobileNumberPanel.add(mobileNumberField, gbc); |
| 129 | +
|
| 130 | + gbc.gridy = 2; |
| 131 | + gbc.gridx = 0; |
| 132 | + gbc.gridwidth = 2; |
| 133 | + gbc.anchor = GridBagConstraints.CENTER; |
| 134 | + JButton submitMobileNumberButton = new JButton("Submit"); |
| 135 | + mobileNumberPanel.add(submitMobileNumberButton, gbc); |
| 136 | +
|
| 137 | + submitMobileNumberButton.addActionListener(new ActionListener() { |
| 138 | + @Override |
| 139 | + public void actionPerformed(ActionEvent e) { |
| 140 | + String mobileNumber = mobileNumberField.getText(); |
| 141 | + if (mobileNumber.equals(correctMobileNumber)) { |
| 142 | + showPanel("OTP"); |
| 143 | + } else { |
| 144 | + JOptionPane.showMessageDialog(null, "Incorrect mobile number."); |
| 145 | + } |
| 146 | + // Clear the mobile number field after use |
| 147 | + mobileNumberField.setText(""); |
| 148 | + } |
| 149 | + }); |
| 150 | + } |
| 151 | +
|
| 152 | + private void setupOTPPanel() { |
| 153 | + otpPanel.setLayout(new GridBagLayout()); |
| 154 | + GridBagConstraints gbc = new GridBagConstraints(); |
| 155 | + gbc.gridx = 0; |
| 156 | + gbc.gridy = 0; |
| 157 | + gbc.insets = new Insets(20, 10, 5, 10); // Padding for top, left, bottom, right |
| 158 | +
|
| 159 | + JLabel otpMessageLabel = new JLabel("OTP sent to your registered mobile number."); |
| 160 | + otpPanel.add(otpMessageLabel, gbc); |
| 161 | +
|
| 162 | + gbc.gridy = 1; |
| 163 | + JLabel otpLabel = new JLabel("Enter OTP:"); |
| 164 | + otpPanel.add(otpLabel, gbc); |
| 165 | +
|
| 166 | + gbc.gridy = 2; |
| 167 | + gbc.fill = GridBagConstraints.HORIZONTAL; |
| 168 | + JTextField otpField = new JTextField(10); |
| 169 | + otpPanel.add(otpField, gbc); |
| 170 | +
|
| 171 | + gbc.gridy = 3; |
| 172 | + gbc.gridx = 0; |
| 173 | + gbc.gridwidth = 2; |
| 174 | + gbc.anchor = GridBagConstraints.CENTER; |
| 175 | + JButton submitOtpButton = new JButton("Submit OTP"); |
| 176 | + otpPanel.add(submitOtpButton, gbc); |
| 177 | +
|
| 178 | + gbc.gridy = 4; |
| 179 | + JButton resendOtpButton = new JButton("Resend OTP"); |
| 180 | + otpPanel.add(resendOtpButton, gbc); |
| 181 | +
|
| 182 | + submitOtpButton.addActionListener(new ActionListener() { |
| 183 | + @Override |
| 184 | + public void actionPerformed(ActionEvent e) { |
| 185 | + String otp = otpField.getText(); |
| 186 | +
|
| 187 | + // For this example, just show the bank panel without actual OTP verification |
| 188 | + showPanel("Bank"); |
| 189 | + } |
| 190 | + }); |
| 191 | +
|
| 192 | + resendOtpButton.addActionListener(new ActionListener() { |
| 193 | + @Override |
| 194 | + public void actionPerformed(ActionEvent e) { |
| 195 | + // Simulate OTP resend process |
| 196 | + otpMessageLabel.setText("OTP resent to your registered mobile number."); |
| 197 | + } |
| 198 | + }); |
| 199 | + } |
| 200 | +
|
| 201 | + private void setupBankPanel() { |
| 202 | + bankPanel.setLayout(new GridBagLayout()); |
| 203 | + GridBagConstraints gbc = new GridBagConstraints(); |
| 204 | + gbc.gridx = 0; |
| 205 | + gbc.gridy = 0; |
| 206 | + gbc.insets = new Insets(20, 10, 5, 10); // Padding for top, left, bottom, right |
| 207 | +
|
| 208 | + JButton viewBalanceButton = new JButton("View Balance"); |
| 209 | + JButton transferAmountButton = new JButton("Transfer Amount"); |
| 210 | +
|
| 211 | + bankPanel.add(viewBalanceButton, gbc); |
| 212 | + gbc.gridy = 1; |
| 213 | + bankPanel.add(transferAmountButton, gbc); |
| 214 | +
|
| 215 | + // Add action listeners for bank panel buttons |
| 216 | + viewBalanceButton.addActionListener(new ActionListener() { |
| 217 | + @Override |
| 218 | + public void actionPerformed(ActionEvent e) { |
| 219 | + // Implement view balance functionality |
| 220 | + JOptionPane.showMessageDialog(null, "View Balance functionality is not implemented yet."); |
| 221 | + } |
| 222 | + }); |
| 223 | +
|
| 224 | + transferAmountButton.addActionListener(new ActionListener() { |
| 225 | + @Override |
| 226 | + public void actionPerformed(ActionEvent e) { |
| 227 | + // Implement transfer amount functionality |
| 228 | + JOptionPane.showMessageDialog(null, "Transfer Amount functionality is not implemented yet."); |
| 229 | + } |
| 230 | + }); |
| 231 | + } |
| 232 | +
|
| 233 | + public static void main(String[] args) { |
| 234 | + SwingUtilities.invokeLater(new Runnable() { |
| 235 | + @Override |
| 236 | + public void run() { |
| 237 | + InternetBankingSystem bankingSystem = new InternetBankingSystem(); |
| 238 | + bankingSystem.setVisible(true); |
| 239 | + } |
| 240 | + }); |
| 241 | + } |
| 242 | +} |
| 243 | +
|
| 244 | +``` |
| 245 | +### Demo |
| 246 | + |
| 247 | +<p align="center"> |
| 248 | +<img src="Assets/demo.gif" width=800> |
| 249 | +</p> |
7 | 250 |
|
8 | 251 |
|
9 |
| -### Deliverables |
10 | 252 |
|
0 commit comments