0% found this document useful (0 votes)
6 views8 pages

STUDENT ACTIVITY Java

Student activity of currency converter app

Uploaded by

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

STUDENT ACTIVITY Java

Student activity of currency converter app

Uploaded by

Kaivan Parikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

STUDENT ACTIVITY

CurrencyConverter app development using java containing GUI


and Database Backend.

[Link]

import [Link].*;
import [Link].*;
import [Link];
import [Link];

public class WelcomePageGUI extends JFrame {


public WelcomePageGUI() {
setTitle("Welcome Page");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel welcomePanel = new JPanel();


[Link](new BoxLayout(welcomePanel, BoxLayout.Y_AXIS));

JLabel welcomeLabel = new JLabel("Welcome to the Currency Converter");


[Link](Component.CENTER_ALIGNMENT);
[Link](new Font("Arial", [Link], 24));

JButton nextButton = new JButton("Next");


[Link](Component.CENTER_ALIGNMENT);
[Link]([Link]);
[Link](new Font("Arial", [Link], 18));
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openCurrencyConverterGUI();
}
});

[Link]([Link]());
[Link](welcomeLabel);
[Link]([Link](new Dimension(0, 20)));
[Link](nextButton);
[Link]([Link]());

setContentPane(welcomePanel);
}
}
[Link]

import [Link].*;
import [Link].*;
import [Link];
import [Link];

public class CurrencyConverterGUI extends JFrame {


private JTextField amountTextField;
private JComboBox<String> fromCurrencyComboBox;
private JComboBox<String> toCurrencyComboBox;
private JLabel resultLabel;

public CurrencyConverterGUI() {
setTitle("Currency Converter");
setSize(400, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(5, 2));

JLabel amountLabel = new JLabel("Amount:");


amountTextField = new JTextField();

JLabel fromCurrencyLabel = new JLabel("From Currency:");


fromCurrencyComboBox = new JComboBox<>(new String[]{"USD", "EUR", "JPY",
"GBP", "CAD", "AUD", "CHF", "CNY", "INR", "SGD"});

JLabel toCurrencyLabel = new JLabel("To Currency:");


toCurrencyComboBox = new JComboBox<>(new String[]{"USD", "EUR", "JPY", "GBP",
"CAD", "AUD", "CHF", "CNY", "INR", "SGD"});
JButton convertButton = new JButton("Convert");
resultLabel = new JLabel("Result: ");

add(amountLabel);
add(amountTextField);
add(fromCurrencyLabel);
add(fromCurrencyComboBox);
add(toCurrencyLabel);
add(toCurrencyComboBox);
add(convertButton);
add(resultLabel);

[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ([Link]() == convertButton) {
try {
double amount = [Link]([Link]());
String fromCurrency =
[Link]().toString();
String toCurrency =
[Link]().toString()

CurrencyData currencyData = new CurrencyData();


double exchangeRate =
[Link](fromCurrency, toCurrency);

double result = amount * exchangeRate;


[Link]("Result: " + result);
} catch (NumberFormatException ex) {
[Link]("Invalid input. Please enter a numeric amount.")
}
});
}
[Link]

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class CurrencyData {


private Connection connection;
private static final String DB_URL = "jdbc:mysql://localhost:3306/currency_db";
private static final String DB_USER = "root";
private static final String DB_PASSWORD = "dhruv09876@12345";

public CurrencyData() {
try {
connection =
[Link]("jdbc:mysql://localhost:3306/currency_db", "root",
"dhruv09876@12345");
} catch (SQLException e) {
[Link]();
}
}

public double getExchangeRate(String fromCurrency, String toCurrency) {


double exchangeRate = 0.0;

try {
String query = "SELECT rate FROM exchange_rates WHERE from_currency = ?
AND to_currency = ?";
PreparedStatement preparedStatement = [Link](query);
[Link](1, fromCurrency);
[Link](2, toCurrency);
ResultSet resultSet = [Link]();

if ([Link]()) {
exchangeRate = [Link]("rate");
}

[Link]();
[Link]();
} catch (SQLException e) {
[Link]();
}

return exchangeRate;
}
}
[Link]

import [Link];
public class CurrencyConverterMain {
public static void main(String[] args) {
[Link](() -> {
WelcomePage welcomePage = new WelcomePage();
[Link](400, 200);
[Link](null);
[Link](true);
});
}
}
OUTPUT

Fig. Welcome Page

Fig. CurrencyConverter App

You might also like