0% found this document useful (0 votes)
19 views19 pages

J Worksheet 11 GUI v1

This document provides a series of Java GUI applications focused on Object Oriented Programming concepts, including user input handling and file writing. It covers creating a simple GUI for user registration, modifying it to include additional fields, and implementing account management with interest calculations. The final part outlines a full-stack approach integrating a database for account holder management using JDBC.

Uploaded by

Kiran D C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views19 pages

J Worksheet 11 GUI v1

This document provides a series of Java GUI applications focused on Object Oriented Programming concepts, including user input handling and file writing. It covers creating a simple GUI for user registration, modifying it to include additional fields, and implementing account management with interest calculations. The final part outlines a full-stack approach integrating a database for account holder management using JDBC.

Uploaded by

Kiran D C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

VIDYASHILP UNIVERSITY

Lab Worksheet 11
Object Oriented Programming

15th April 2025


Objectives: Graphical User Interface
GUI Introduction: Frame, Button, TextArea, TextField, Action Listener

import javax.swing.*;
import java.awt.event.*;

public class jguiintro {


public static void main(String[] args) {

JFrame frame = new JFrame("Vidyashilp University");


frame.setSize(400, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);

JLabel label = new JLabel("Enter your name:");


label.setBounds(50, 30, 150, 30);
frame.add(label);

JTextField textField = new JTextField();


textField.setBounds(180, 30, 150, 30);
frame.add(textField);

JButton button = new JButton("Greet Me");


button.setBounds(140, 80, 100, 30);
frame.add(button);

button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = textField.getText();
JOptionPane.showMessageDialog(frame, "Hello,
" + name + "!");
}
}
);

frame.setVisible(true);
}
}
With Output
import javax.swing.*;
import java.awt.event.*;

public class jguiwithoutput {


public static void main(String[] args) {

JFrame frame = new JFrame("Vidyashilp Student");


frame.setSize(500,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);

JLabel label = new JLabel("Enter your name:");


label.setBounds(50, 30, 150, 30);
frame.add(label);

JTextField textField = new JTextField();


textField.setBounds(180, 30, 200, 30);
frame.add(textField);

JButton button = new JButton("Register Me");


button.setBounds(180, 70, 100, 30);
frame.add(button);

JTextArea Listed_Students = new JTextArea();


Listed_Students.setEditable(false);

JScrollPane scrollPane = new JScrollPane(Listed_Students);


scrollPane.setBounds(50, 120, 400, 100);
frame.add(scrollPane);

StringBuilder inputHistory = new StringBuilder();

button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = textField.getText().trim();
if (!name.isEmpty()) {
JOptionPane.showMessageDialog(frame, "Hello, " + name + "!");
inputHistory.append(name).append("\n");
Listed_Students.setText(inputHistory.toString());
textField.setText("");
} else {
JOptionPane.showMessageDialog(frame, "Please enter a name.");
}
}
});

frame.setVisible(true);
}}
Write to File

import javax.swing.*;
import java.awt.event.*;
import java.io.*;
public class jguiOneoutputfile {
public static void main(String[] args) {
JFrame frame = new JFrame("User Data Form");
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);

JLabel nameLabel = new JLabel("Name:");


nameLabel.setBounds(50, 30, 100, 25);
JTextField nameField = new JTextField();
nameField.setBounds(150, 30, 180, 25);

JButton submitButton = new JButton("Submit");


submitButton.setBounds(140, 200, 100, 30);

frame.add(nameLabel); frame.add(nameField);

frame.add(submitButton);
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = nameField.getText();

try {
FileWriter writer = new FileWriter("username.txt", true);
writer.write("Name: " + name + "\n");

writer.write("------------------------\n");
writer.close();

JOptionPane.showMessageDialog(frame, "Data saved


successfully!");

nameField.setText("");

} catch (IOException ex) {


JOptionPane.showMessageDialog(frame, "Error writing to file.");
}
}
});

frame.setVisible(true);
}
}

Exercise 1: Modify the Program to read Name, Age and Id and write it to
the File
Exercise 2: Modify the program to create an Account Holder Class. Read
Account Number, Name, Age and ID and write it to the file.

import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
class AccountHolder {
private String name;
private int age;
private String id;

public AccountHolder(String name, int age, String id) {


this.name = name;
this.age = age;
this.id = id;
}

public String getName() {


return name;
}

public int getAge() {


return age;
}

public String getId() {


return id;
}

@Override
public String toString() {
return "Name: " + name + ", Age: " + age + ", ID: " + id;
}
}

public class jGuiAH {


public static void main(String[] args) {

JFrame frame = new JFrame("Account Holder Registration");


frame.setSize(500, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);

JLabel nameLabel = new JLabel("Enter your name:");


nameLabel.setBounds(50, 30, 150, 30);
frame.add(nameLabel);

JLabel ageLabel = new JLabel("Enter your age:");


ageLabel.setBounds(50, 70, 150, 30);
frame.add(ageLabel);

JLabel idLabel = new JLabel("Enter your ID:");


idLabel.setBounds(50, 110, 150, 30);
frame.add(idLabel);

JTextField nameField = new JTextField();


nameField.setBounds(180, 30, 200, 30);
frame.add(nameField);

JTextField ageField = new JTextField();


ageField.setBounds(180, 70, 200, 30);
frame.add(ageField);
JTextField idField = new JTextField();
idField.setBounds(180, 110, 200, 30);
frame.add(idField);

JButton button = new JButton("Register Me");


button.setBounds(180, 160, 120, 30);
frame.add(button);

JTextArea outputArea = new JTextArea();


outputArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(outputArea);
scrollPane.setBounds(50, 210, 400, 130);
frame.add(scrollPane);

List<AccountHolder> accountHolders = new ArrayList<>();

button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String name = nameField.getText().trim();
String ageText = ageField.getText().trim();
String id = idField.getText().trim();

if (name.isEmpty() || ageText.isEmpty() || id.isEmpty()) {


JOptionPane.showMessageDialog(frame, "All fields are
required.");
return;
}

int age = Integer.parseInt(ageText);

if (age < 0 || age > 120) {


JOptionPane.showMessageDialog(frame, "Please enter a valid
age.");
return;
}

AccountHolder accountHolder = new AccountHolder(name, age,


id);
accountHolders.add(accountHolder);

JOptionPane.showMessageDialog(frame, "Registered: " +


accountHolder.getName());

StringBuilder display = new StringBuilder("Registered Account


Holders:\n");
for (AccountHolder ah : accountHolders) {
display.append(ah.toString()).append("\n");
}
outputArea.setText(display.toString());

nameField.setText("");
ageField.setText("");
idField.setText("");

} catch (NumberFormatException ex) {


JOptionPane.showMessageDialog(frame, "Age must be a valid
number.");
}
}
});

frame.setVisible(true);
}
}

Java program to compute interest of the account holder and display on


the screen

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

class AccountHolder {
private String name;
private String accountNumber;
private double balance;

public AccountHolder(String name, String accountNumber, double balance)


{
this.name = name;
this.accountNumber = accountNumber;
this.balance = balance;
}

public String getAccountNumber() {


return accountNumber;
}

public double getBalance() {


return balance;
}

public void computeInterest(double rate) {


double interest = balance * rate / 100;
balance += interest;
}

public String toString() {


return "Name: " + name + "\nAccount#: " + accountNumber + "\
nBalance: ₹" + String.format("%.2f", balance);
}
}

public class jBankinterestGui {


private static ArrayList<AccountHolder> accountList = new ArrayList<>();

public static void main(String[] args) {


// Sample data
accountList.add(new AccountHolder("Hari", "ACC001", 10000));
accountList.add(new AccountHolder("Priya", "ACC002", 15000));
accountList.add(new AccountHolder("Chanda", "ACC003", 20000));

// GUI Setup
JFrame frame = new JFrame("Interest Calculator");
frame.setSize(300, 250);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);

JPanel panel = new JPanel();


panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
frame.add(panel);

JTextField accField = new JTextField();


JTextField rateField = new JTextField();
JButton computeBtn = new JButton("Compute Interest");
JTextArea outputArea = new JTextArea(4, 20);
outputArea.setEditable(false);
outputArea.setLineWrap(true);
outputArea.setWrapStyleWord(true);

panel.add(new JLabel("Account Number:"));


panel.add(accField);
panel.add(Box.createRigidArea(new Dimension(0, 5)));
panel.add(new JLabel("Interest Rate (%):"));
panel.add(rateField);
panel.add(Box.createRigidArea(new Dimension(0, 10)));
panel.add(computeBtn);
panel.add(Box.createRigidArea(new Dimension(0, 10)));
panel.add(new JScrollPane(outputArea));

computeBtn.addActionListener(e -> {
String accNo = accField.getText().trim();
String rateText = rateField.getText().trim();
AccountHolder acc = getAccountByNumber(accNo);

if (acc == null) {
outputArea.setText("Account not found.");
return;
}

try {
double rate = Double.parseDouble(rateText);
acc.computeInterest(rate);
outputArea.setText("Interest added.\n\n" + acc.toString());
} catch (NumberFormatException ex) {
outputArea.setText("Enter a valid interest rate.");
}
});

frame.setVisible(true);
}

private static AccountHolder getAccountByNumber(String accNo) {


for (AccountHolder acc : accountList) {
if (acc.getAccountNumber().equalsIgnoreCase(accNo)) {
return acc;
}
}
return null;
}
}

Full Stack
Step 1: Database

use jBank;
CREATE TABLE AccountHolder (
name VARCHAR(100),
age INT,
account_Number VARCHAR(20) PRIMARY KEY,
balance DECIMAL(15, 2),
interest DECIMAL(5, 2)
);
INSERT INTO AccountHolder (name, age, account_Number, balance, interest)
VALUES
('Hari Prasad', 28, 'VUB001', 0, 0),
('Bijoy Shetty', 35, 'VUB1002', 0, 0),
('Chanda K', 22, 'VUB1003', 0, 0),
('Dvikar Reddy', 30, 'VUB1004', 0, 0),
('Eisha P', 40, 'VUB1005', 0, 0),
('Frank Ressul', 26, 'VUB1006', 0, 0),
('Geetha Ram', 33, 'VUB1007', 0, 0),
('Hema Sai', 29, 'VUB1008', 0, 0),
('Ian Nath', 31, 'VUB1009', 0, 0),
('Jyothi Kim', 24, 'VUB1010', 0, 0);

Java Program with GUI


import javax.swing.*;
import java.awt.event.*;
import java.sql.*;

// ---------- Separate Class for AccountHolder ----------


class AccountHolder {
private String name;
private int age;
private String accountNumber;
private double balance;
private double interest;

private static final String DB_URL = "jdbc:mysql://localhost:3306/JBank";


private static final String USER = "root";
private static final String PASS = "Password";

public AccountHolder(String name, int age, String accountNumber, double


balance, double interest) {
this.name = name;
this.age = age;
this.accountNumber = accountNumber;
this.balance = balance;
this.interest = interest;
}

public static AccountHolder loadFromDatabase(String accNumber) {


try (Connection conn = DriverManager.getConnection(DB_URL, USER,
PASS)) {
String sql = "SELECT * FROM AccountHolder WHERE account_Number =
?";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, accNumber);
ResultSet rs = stmt.executeQuery();

if (rs.next()) {
String name = rs.getString("name");
int age = rs.getInt("age");
double balance = rs.getDouble("balance");
double interest = rs.getDouble("interest");
AccountHolder AH1= new AccountHolder(name, age, accNumber,
balance, interest);
return AH1;
// return new AccountHolder(name, age, accNumber, balance, interest);

}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}

public void deposit(double amount) {


if (amount > 0) {
balance += amount;
computeInterest();
updateDatabase();
}
}

public void computeInterest() {


interest = balance * 0.05;
}

public void updateDatabase() {


try (Connection conn = DriverManager.getConnection(DB_URL, USER,
PASS)) {
String sql = "UPDATE AccountHolder SET balance = ?, interest = ?
WHERE account_Number = ?";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setDouble(1, balance);
stmt.setDouble(2, interest);
stmt.setString(3, accountNumber);
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}

// Getters
public String getName() { return name; }
public int getAge() { return age; }
public double getBalance() { return balance; }
public double getInterest() { return interest; }
}

// ---------- Main GUI Class ----------


public class jFullStackAH {

private JTextField accountNumberField, depositField;


private JLabel nameLabel, ageLabel, balanceLabel, interestLabel;
private AccountHolder accountHolder;

public void createGUI() {


JFrame frame = new JFrame("VU Bank");
frame.setSize(450, 350);
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel accLabel = new JLabel("Account Number:");


accLabel.setBounds(30, 30, 120, 25);
frame.add(accLabel);

accountNumberField = new JTextField();


accountNumberField.setBounds(160, 30, 200, 25);
frame.add(accountNumberField);

JButton loadButton = new JButton("Load Account");


loadButton.setBounds(140, 65, 150, 30);
frame.add(loadButton);

nameLabel = new JLabel("Name: ");


nameLabel.setBounds(30, 110, 300, 25);
frame.add(nameLabel);
ageLabel = new JLabel("Age: ");
ageLabel.setBounds(30, 140, 300, 25);
frame.add(ageLabel);

JLabel depositLabel = new JLabel("Deposit Amount:");


depositLabel.setBounds(30, 180, 120, 25);
frame.add(depositLabel);

depositField = new JTextField();


depositField.setBounds(160, 180, 200, 25);
frame.add(depositField);

JButton depositButton = new JButton("Deposit & Compute Interest");


depositButton.setBounds(100, 220, 230, 30);
frame.add(depositButton);

balanceLabel = new JLabel("Balance: ");


balanceLabel.setBounds(30, 270, 200, 25);
frame.add(balanceLabel);

interestLabel = new JLabel("Interest: ");


interestLabel.setBounds(240, 270, 200, 25);
frame.add(interestLabel);

loadButton.addActionListener(e -> {
String accNum =
accountNumberField.getText().trim();
if (!accNum.isEmpty()) {
accountHolder =
AccountHolder.loadFromDatabase(accNum);
if (accountHolder != null) {
updateLabels();
} else {
JOptionPane.showMessageDialog(frame, "Account
not found.");
}
}
});

depositButton.addActionListener(e -> {
if (accountHolder == null) {
JOptionPane.showMessageDialog(frame, "Load an account first.");
return;
}

try {
double amount = Double.parseDouble(depositField.getText());
accountHolder.deposit(amount);
updateLabels();
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Enter a valid amount.");
}
});

frame.setVisible(true);
}

private void updateLabels() {


nameLabel.setText("Name: " + accountHolder.getName());
ageLabel.setText("Age: " + accountHolder.getAge());
balanceLabel.setText("Balance: ₹" + accountHolder.getBalance());
interestLabel.setText("Interest: ₹" + accountHolder.getInterest());
}

public static void main(String[] args) {


try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "MySQL JDBC Driver not found.");
return;
}
jFullStackAH FSFun =new jFullStackAH();
FSFun.createGUI();
}
}

Compilation

javac -cp ".;mysql-connector-j-9.2.0.jar" jFullStack.java

java -cp ".;mysql-connector-j-9.2.0.jar" jFullStack

javac -cp ".;mysql-connector-j-9.2.0.jar" jFullStackBanktwo.java

Multiple Frames
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;

// ---------- AccountHolder CLASS ----------


class AccountHolder {
private String name;
private int age;
private String accountNumber;
private double balance;
private double interest;

private static final String DB_URL = "jdbc:mysql://localhost:3306/JBank";


private static final String USER = "root";
private static final String PASS = "Password";

public AccountHolder(String name, int age, String accountNumber, double balance, double
interest) {
this.name = name;
this.age = age;
this.accountNumber = accountNumber;
this.balance = balance;
this.interest = interest;
}

public AccountHolder(String name, int age, String accountNumber) {


this(name, age, accountNumber, 0.0, 0.0);
}

public boolean saveToDatabase() {


try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS)) {
String sql = "INSERT INTO AccountHolder (name, age, account_Number, balance, interest)
VALUES (?, ?, ?, ?, ?)";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, name);
stmt.setInt(2, age);
stmt.setString(3, accountNumber);
stmt.setDouble(4, balance);
stmt.setDouble(5, interest);
return stmt.executeUpdate() > 0;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}

public static AccountHolder loadFromDatabase(String accNumber) {


try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS)) {
String sql = "SELECT * FROM AccountHolder WHERE account_Number = ?";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, accNumber);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
String name = rs.getString("name");
int age = rs.getInt("age");
double balance = rs.getDouble("balance");
double interest = rs.getDouble("interest");
return new AccountHolder(name, age, accNumber, balance, interest);
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}

public void deposit(double amount) {


if (amount > 0) {
balance += amount;
computeInterest();
updateDatabase();
}
}

public void computeInterest() {


interest = balance * 0.05;
}

public void updateDatabase() {


try (Connection conn = DriverManager.getConnection(DB_URL, USER, PASS)) {
String sql = "UPDATE AccountHolder SET balance = ?, interest = ? WHERE account_Number
= ?";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setDouble(1, balance);
stmt.setDouble(2, interest);
stmt.setString(3, accountNumber);
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}

public String getName() { return name; }


public int getAge() { return age; }
public double getBalance() { return balance; }
public double getInterest() { return interest; }
}

// ---------- AccountCreationFrame CLASS ----------


class AccountCreationFrame {
public void launch() {
JFrame frame = new JFrame("Create Account");
frame.setSize(400, 350);
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel nameLbl = new JLabel("Name:");


nameLbl.setBounds(30, 30, 100, 25);
frame.add(nameLbl);
JTextField nameField = new JTextField();
nameField.setBounds(150, 30, 200, 25);
frame.add(nameField);

JLabel ageLbl = new JLabel("Age:");


ageLbl.setBounds(30, 70, 100, 25);
frame.add(ageLbl);
JTextField ageField = new JTextField();
ageField.setBounds(150, 70, 200, 25);
frame.add(ageField);

JLabel accNumLbl = new JLabel("Account Number:");


accNumLbl.setBounds(30, 110, 120, 25);
frame.add(accNumLbl);
JTextField accNumField = new JTextField();
accNumField.setBounds(150, 110, 200, 25);
frame.add(accNumField);

JButton createBtn = new JButton("Create Account");


createBtn.setBounds(100, 160, 180, 30);
frame.add(createBtn);

JButton goToDepositBtn = new JButton("Go to Deposit");


goToDepositBtn.setBounds(100, 210, 180, 30);
frame.add(goToDepositBtn);

createBtn.addActionListener(e -> {
try {
String name = nameField.getText().trim();
int age = Integer.parseInt(ageField.getText().trim());
String accNum = accNumField.getText().trim();

AccountHolder newAcc = new AccountHolder(name, age, accNum);


if (newAcc.saveToDatabase()) {
JOptionPane.showMessageDialog(frame, "Account created successfully!");
nameField.setText(""); ageField.setText(""); accNumField.setText("");
} else {
JOptionPane.showMessageDialog(frame, "Account creation failed.");
}
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Invalid age.");
}
});

goToDepositBtn.addActionListener(e -> {
frame.dispose();
new DepositFrame().launch();
});

frame.setVisible(true);
}
}

// ---------- DepositFrame CLASS ----------


class DepositFrame {
public void launch() {
JFrame frame = new JFrame("Deposit & Interest");
frame.setSize(500, 450);
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel accNumLbl = new JLabel("Enter Account Number:");


accNumLbl.setBounds(30, 30, 180, 25);
frame.add(accNumLbl);
JTextField accNumField = new JTextField();
accNumField.setBounds(210, 30, 200, 25);
frame.add(accNumField);

JButton loadBtn = new JButton("Load");


loadBtn.setBounds(150, 70, 150, 30);
frame.add(loadBtn);

JLabel nameLbl = new JLabel("Name: ");


nameLbl.setBounds(30, 120, 300, 25);
frame.add(nameLbl);

JLabel ageLbl = new JLabel("Age: ");


ageLbl.setBounds(30, 150, 300, 25);
frame.add(ageLbl);

JLabel balLbl = new JLabel("Balance: ");


balLbl.setBounds(30, 180, 300, 25);
frame.add(balLbl);

JLabel interestLbl = new JLabel("Interest: ");


interestLbl.setBounds(30, 210, 300, 25);
frame.add(interestLbl);

JLabel depLbl = new JLabel("Deposit Amount:");


depLbl.setBounds(30, 250, 150, 25);
frame.add(depLbl);
JTextField depField = new JTextField();
depField.setBounds(180, 250, 150, 25);
frame.add(depField);

JButton depositBtn = new JButton("Deposit & Compute Interest");


depositBtn.setBounds(100, 290, 250, 30);
frame.add(depositBtn);

JButton backBtn = new JButton("← Create New Account");


backBtn.setBounds(140, 340, 200, 30);
frame.add(backBtn);

final AccountHolder[] holder = new AccountHolder[1]; // Trick to access in lambda

loadBtn.addActionListener(e -> {
String accNum = accNumField.getText().trim();
if (!accNum.isEmpty()) {
holder[0] = AccountHolder.loadFromDatabase(accNum);
if (holder[0] != null) {
nameLbl.setText("Name: " + holder[0].getName());
ageLbl.setText("Age: " + holder[0].getAge());
balLbl.setText("Balance: ₹" + holder[0].getBalance());
interestLbl.setText("Interest: ₹" + holder[0].getInterest());
} else {
JOptionPane.showMessageDialog(frame, "Account not found.");
}
}
});

depositBtn.addActionListener(e -> {
if (holder[0] == null) {
JOptionPane.showMessageDialog(frame, "Load an account first.");
return;
}
try {
double amount = Double.parseDouble(depField.getText());
holder[0].deposit(amount);
balLbl.setText("Balance: ₹" + holder[0].getBalance());
interestLbl.setText("Interest: ₹" + holder[0].getInterest());
depField.setText("");
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Enter a valid deposit amount.");
}
});

backBtn.addActionListener(e -> {
frame.dispose();
new AccountCreationFrame().launch();
});

frame.setVisible(true);
}
}

public class jFullStackBanktwo {


public static void main(String[] args) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "MySQL JDBC Driver not found.");
return;
}
new AccountCreationFrame().launch();
}
}

You might also like