Main Page Source Code
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.UIManager;
import javax.swing.JSlider;
import javax.swing.JTable;
import javax.swing.JProgressBar;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class MainPage extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainPage frame = new MainPage();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MainPage() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 500, 600);
contentPane = new JPanel();
contentPane.setForeground(Color.WHITE);
contentPane.setBackground(Color.BLACK);
contentPane.setBorder(UIManager.getBorder("Button.border"));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblWelcomeToConvert = new JLabel("Welcome to Converter");
lblWelcomeToConvert.setForeground(Color.WHITE);
lblWelcomeToConvert.setHorizontalAlignment(SwingConstants.CENTER);
lblWelcomeToConvert.setFont(new Font("Candara", Font.BOLD, 30));
lblWelcomeToConvert.setBounds(12, 13, 441, 79);
contentPane.add(lblWelcomeToConvert);
JButton btnT = new JButton("Temperature");
btnT.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Temperature temp = new Temperature();
temp.setVisible(true);
dispose();
}
});
btnT.setBackground(Color.BLUE);
btnT.setForeground(Color.WHITE);
btnT.setIcon(null);
btnT.setFont(new Font("Malgun Gothic Semilight", Font.BOLD, 20));
btnT.setBounds(100, 100, 250, 50);
contentPane.add(btnT);
JButton btnC = new JButton("Currency");
btnC.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Currency currency = new Currency();
currency.setVisible(true);
dispose();
}
});
btnC.setBackground(Color.BLUE);
btnC.setForeground(Color.WHITE);
btnC.setFont(new Font("Malgun Gothic Semilight", Font.BOLD, 20));
btnC.setBounds(100, 200, 250, 50);
contentPane.add(btnC);
JButton btnL = new JButton("Width");
btnL.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Length length = new Length();
length.setVisible(true);
dispose();
}
});
btnL.setBackground(Color.BLUE);
btnL.setForeground(Color.WHITE);
btnL.setFont(new Font("Malgun Gothic Semilight", Font.BOLD, 20));
btnL.setBounds(100, 300, 250, 50);
contentPane.add(btnL);
JButton btnW = new JButton("Length");
btnW.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Width width = new Width();
width.setVisible(true);
dispose();
}
});
btnW.setBackground(Color.BLUE);
btnW.setForeground(Color.WHITE);
btnW.setFont(new Font("Malgun Gothic Semilight", Font.BOLD, 20));
btnW.setBounds(100, 400, 250, 50);
contentPane.add(btnW);
JButton button = new JButton("Exit");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
button.setForeground(Color.WHITE);
button.setFont(new Font("Tahoma", Font.PLAIN, 20));
button.setBackground(Color.RED);
button.setBounds(318,507, 135, 33);
contentPane.add(button);
JButton btnRateThisWork = new JButton("Rate this work");
btnRateThisWork.setForeground(Color.WHITE);
btnRateThisWork.setFont(new Font("Tahoma", Font.PLAIN, 20));
btnRateThisWork.setBackground(Color.ORANGE);
btnRateThisWork.setBounds(12, 507, 178, 33);
contentPane.add(btnRateThisWork);
}
}
![Unit Converter using Java GUI [5 Frame] 3 Unit Converter using Java GUI [5 Frame] 3](https://old.nurnobishanto.com/wp-content/uploads/2019/10/main.png)
Temperature source code
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
public class Temperature extends JFrame {
private JPanel contentPane;
private JTextField c;
private JTextField f;
private JTextField k;
private JTextField tfOut;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Temperature frame = new Temperature();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Temperature() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 500, 600);
contentPane = new JPanel();
contentPane.setForeground(Color.WHITE);
contentPane.setBackground(Color.BLACK);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton button = new JButton("Main Menu");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MainPage home = new MainPage();
home.setVisible(true);
dispose();
}
});
button.setForeground(Color.WHITE);
button.setFont(new Font("Tahoma", Font.PLAIN, 20));
button.setBackground(Color.BLUE);
button.setBounds(12, 499, 176, 41);
contentPane.add(button);
JLabel lblTemperatureConversion = new JLabel("Temperature Conversion");
lblTemperatureConversion.setHorizontalAlignment(SwingConstants.CENTER);
lblTemperatureConversion.setForeground(Color.WHITE);
lblTemperatureConversion.setFont(new Font("Tahoma", Font.PLAIN, 30));
lblTemperatureConversion.setBounds(12, 13, 458, 54);
contentPane.add(lblTemperatureConversion);
JButton button_1 = new JButton("Exit");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
button_1.setForeground(Color.WHITE);
button_1.setFont(new Font("Tahoma", Font.PLAIN, 20));
button_1.setBackground(Color.RED);
button_1.setBounds(341, 499, 129, 41);
contentPane.add(button_1);
c = new JTextField();
c.setForeground(new Color(25, 25, 112));
c.setFont(new Font("Tahoma", Font.BOLD, 20));
c.setHorizontalAlignment(SwingConstants.CENTER);
c.setBounds(48, 94, 200, 50);
contentPane.add(c);
c.setColumns(10);
f = new JTextField();
f.setHorizontalAlignment(SwingConstants.CENTER);
f.setForeground(new Color(25, 25, 112));
f.setFont(new Font("Tahoma", Font.BOLD, 20));
f.setColumns(10);
f.setBounds(48, 330, 200, 50);
contentPane.add(f);
JLabel lblc = new JLabel("\u00B0c ");
lblc.setFont(new Font("Tahoma", Font.BOLD, 30));
lblc.setForeground(Color.WHITE);
lblc.setBounds(260, 94, 59, 46);
contentPane.add(lblc);
JLabel lblf = new JLabel("\u00B0F");
lblf.setForeground(Color.WHITE);
lblf.setFont(new Font("Tahoma", Font.BOLD, 30));
lblf.setBounds(260, 327, 59, 46);
contentPane.add(lblf);
k = new JTextField();
k.setHorizontalAlignment(SwingConstants.CENTER);
k.setForeground(new Color(25, 25, 112));
k.setFont(new Font("Tahoma", Font.BOLD, 20));
k.setColumns(10);
k.setBounds(48, 217, 200, 50);
contentPane.add(k);
JLabel lblk = new JLabel("\u00B0k");
lblk.setForeground(Color.WHITE);
lblk.setFont(new Font("Tahoma", Font.BOLD, 30));
lblk.setBounds(260, 217, 59, 46);
contentPane.add(lblk);
JButton btnC = new JButton("Convert");
btnC.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(c.getText().isEmpty())
{
tfOut.setText("Please Check your input");
}
else
{
tfOut.setText(null);
double cel = Double.parseDouble(c.getText());
double fa = cel * 1.8 +32;
double ke = cel+273.15;
String far = String.format("%.2f",fa);
String kel = String.format("%.2f", ke);
k.setText(kel);
f.setText(far);
}
}
});
btnC.setForeground(new Color(255, 255, 0));
btnC.setBackground(new Color(25, 25, 112));
btnC.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnC.setBounds(318, 94, 100, 50);
contentPane.add(btnC);
JButton btnK = new JButton("Convert");
btnK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(k.getText().isEmpty())
{
tfOut.setText("Please Check your input");
}
else
{
tfOut.setText(null);
double kel = Double.parseDouble(k.getText());
double fa =(kel - 273.15) * 1.8 + 32;
double ce = kel - 273.15;
String far = String.format("%.2f", fa);
String cel = String.format("%.2f", ce);
f.setText(far);
c.setText(cel);
}
}
});
btnK.setForeground(Color.YELLOW);
btnK.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnK.setBackground(new Color(25, 25, 112));
btnK.setBounds(318, 217, 100, 50);
contentPane.add(btnK);
JButton btnF = new JButton("Convert");
btnF.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(f.getText().isEmpty())
{
tfOut.setText("Please Check your input");
}
else
{
tfOut.setText(null);
double far = Double.parseDouble(f.getText());
double ke = (far - 32) * 5/9 + 273.15;
double ce = ke -273.15;
String kel = String.format("%.2f", ke);
String cel = String.format("%.2f", ce);
k.setText(kel);
c.setText(cel);
}
}
});
btnF.setForeground(Color.YELLOW);
btnF.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnF.setBackground(new Color(25, 25, 112));
btnF.setBounds(318, 330, 100, 50);
contentPane.add(btnF);
JButton clear = new JButton("Clear");
clear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
c.setText(null);
k.setText(null);
f.setText(null);
tfOut.setText(null);
}
});
clear.setForeground(Color.WHITE);
clear.setFont(new Font("Tahoma", Font.PLAIN, 20));
clear.setBackground(new Color(0, 100, 0));
clear.setBounds(200, 499, 129, 41);
contentPane.add(clear);
tfOut = new JTextField();
tfOut.setForeground(Color.RED);
tfOut.setBackground(Color.BLACK);
tfOut.setFont(new Font("Tahoma", Font.PLAIN, 19));
tfOut.setBounds(48, 410, 370, 54);
contentPane.add(tfOut);
tfOut.setColumns(10);
}
}
![Unit Converter using Java GUI [5 Frame] 4 Unit Converter using Java GUI [5 Frame] 4](https://old.nurnobishanto.com/wp-content/uploads/2019/10/temperature-1.png)
Length Convert Source code
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
public class Length extends JFrame {
private JPanel contentPane;
private JTextField mg;
private JTextField g;
private JTextField kg;
private JTextField t;
private JTextField tfMsg;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Length frame = new Length();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Length() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 500, 600);
contentPane = new JPanel();
contentPane.setForeground(Color.WHITE);
contentPane.setBackground(Color.BLACK);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton button = new JButton("Main Menu");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MainPage home = new MainPage();
home.setVisible(true);
dispose();
}
});
button.setForeground(Color.WHITE);
button.setFont(new Font("Tahoma", Font.PLAIN, 20));
button.setBackground(Color.BLUE);
button.setBounds(12, 499, 162, 41);
contentPane.add(button);
JLabel lblLengthConversion = new JLabel("Width Conversion");
lblLengthConversion.setHorizontalAlignment(SwingConstants.CENTER);
lblLengthConversion.setForeground(Color.WHITE);
lblLengthConversion.setFont(new Font("Tahoma", Font.PLAIN, 30));
lblLengthConversion.setBounds(12, 13, 458, 54);
contentPane.add(lblLengthConversion);
JButton button_1 = new JButton("Exit");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
button_1.setForeground(Color.WHITE);
button_1.setFont(new Font("Tahoma", Font.PLAIN, 20));
button_1.setBackground(Color.RED);
button_1.setBounds(341, 499, 129, 41);
contentPane.add(button_1);
JButton button_2 = new JButton("Clear");
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tfMsg.setText(null);
t.setText(null);
mg.setText(null);
g.setText(null);
kg.setText(null);
}
});
button_2.setForeground(Color.WHITE);
button_2.setFont(new Font("Tahoma", Font.PLAIN, 20));
button_2.setBackground(new Color(0, 100, 0));
button_2.setBounds(200, 499, 129, 41);
contentPane.add(button_2);
JLabel lblMilligram = new JLabel("Milligram");
lblMilligram.setForeground(Color.WHITE);
lblMilligram.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblMilligram.setBackground(Color.BLACK);
lblMilligram.setBounds(12, 91, 107, 40);
contentPane.add(lblMilligram);
mg = new JTextField();
mg.setHorizontalAlignment(SwingConstants.CENTER);
mg.setFont(new Font("Tahoma", Font.PLAIN, 20));
mg.setColumns(10);
mg.setBounds(131, 91, 147, 40);
contentPane.add(mg);
JLabel lblMg = new JLabel("mg");
lblMg.setForeground(Color.WHITE);
lblMg.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblMg.setBackground(Color.BLACK);
lblMg.setBounds(284, 91, 55, 40);
contentPane.add(lblMg);
JButton btnMg = new JButton("Convert");
btnMg.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(mg.getText().isEmpty())
{
tfMsg.setText("Your input is emty !");
}
else
{
tfMsg.setText(null);
double Mg = Double.parseDouble(mg.getText());
double Gm = Mg/1000;
double Kg = Gm/1000;
double Ton = Kg/1000;
String GM = String.format("%.2f", Gm);
String KG = String.format("%.2f", Kg);
String TON = String.format("%.2f", Ton);
g.setText(GM);
kg.setText(KG);
t.setText(TON);
}
}
});
btnMg.setForeground(Color.YELLOW);
btnMg.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnMg.setBackground(new Color(25, 25, 112));
btnMg.setBounds(351, 91, 100, 40);
contentPane.add(btnMg);
JLabel lblGram = new JLabel("Gram");
lblGram.setForeground(Color.WHITE);
lblGram.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblGram.setBackground(Color.BLACK);
lblGram.setBounds(12, 157, 107, 40);
contentPane.add(lblGram);
g = new JTextField();
g.setHorizontalAlignment(SwingConstants.CENTER);
g.setFont(new Font("Tahoma", Font.PLAIN, 20));
g.setColumns(10);
g.setBounds(131, 157, 147, 40);
contentPane.add(g);
JLabel lblG = new JLabel("g");
lblG.setForeground(Color.WHITE);
lblG.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblG.setBackground(Color.BLACK);
lblG.setBounds(284, 157, 55, 40);
contentPane.add(lblG);
JButton btnG = new JButton("Convert");
btnG.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(g.getText().isEmpty())
{
tfMsg.setText("Your input is emty !");
}
else
{
tfMsg.setText(null);
double Gm = Double.parseDouble(g.getText());
double Mg = Gm*1000;
double Kg = Gm/1000;
double Ton = Kg/1000;
String MG = String.format("%.2f", Mg);
String KG = String.format("%.2f", Kg);
String TON = String.format("%.2f", Ton);
mg.setText(MG);
kg.setText(KG);
t.setText(TON);
}
}
});
btnG.setForeground(Color.YELLOW);
btnG.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnG.setBackground(new Color(25, 25, 112));
btnG.setBounds(351, 157, 100, 40);
contentPane.add(btnG);
JLabel lblKilogram = new JLabel("Kilogram");
lblKilogram.setForeground(Color.WHITE);
lblKilogram.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblKilogram.setBackground(Color.BLACK);
lblKilogram.setBounds(12, 220, 107, 40);
contentPane.add(lblKilogram);
kg = new JTextField();
kg.setHorizontalAlignment(SwingConstants.CENTER);
kg.setFont(new Font("Tahoma", Font.PLAIN, 20));
kg.setColumns(10);
kg.setBounds(131, 220, 147, 40);
contentPane.add(kg);
JLabel lblKg = new JLabel("kg");
lblKg.setForeground(Color.WHITE);
lblKg.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblKg.setBackground(Color.BLACK);
lblKg.setBounds(284, 220, 55, 40);
contentPane.add(lblKg);
JButton btnKg = new JButton("Convert");
btnKg.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(kg.getText().isEmpty())
{
tfMsg.setText("Your input is emty !");
}
else
{
tfMsg.setText(null);
double Kg = Double.parseDouble(kg.getText());
double Gm = Kg*1000;
double Mg = Gm*1000;
double Ton = Kg/1000;
String GM = String.format("%.2f", Gm);
String MG = String.format("%.2f", Mg);
String TON = String.format("%.2f", Ton);
mg.setText(MG);
g.setText(GM);
t.setText(TON);
}
}
});
btnKg.setForeground(Color.YELLOW);
btnKg.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnKg.setBackground(new Color(25, 25, 112));
btnKg.setBounds(351, 220, 100, 40);
contentPane.add(btnKg);
JLabel lblTonne = new JLabel("Tonne");
lblTonne.setForeground(Color.WHITE);
lblTonne.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblTonne.setBackground(Color.BLACK);
lblTonne.setBounds(12, 281, 107, 40);
contentPane.add(lblTonne);
t = new JTextField();
t.setHorizontalAlignment(SwingConstants.CENTER);
t.setFont(new Font("Tahoma", Font.PLAIN, 20));
t.setColumns(10);
t.setBounds(131, 281, 147, 40);
contentPane.add(t);
JLabel lblTonne_1 = new JLabel("tonne");
lblTonne_1.setForeground(Color.WHITE);
lblTonne_1.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblTonne_1.setBackground(Color.BLACK);
lblTonne_1.setBounds(284, 281, 55, 40);
contentPane.add(lblTonne_1);
JButton btnT = new JButton("Convert");
btnT.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(t.getText().isEmpty())
{
tfMsg.setText("Your input is emty !");
}
else
{
tfMsg.setText(null);
double Ton = Double.parseDouble(t.getText());
double Kg = Ton*1000;
double Gm = Kg*1000;
double Mg = Gm*1000;
String GM = String.format("%.2f", Gm);
String KG = String.format("%.2f", Kg);
String MG = String.format("%.2f", Mg);
g.setText(GM);
kg.setText(KG);
mg.setText(MG);
}
}
});
btnT.setForeground(Color.YELLOW);
btnT.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnT.setBackground(new Color(25, 25, 112));
btnT.setBounds(351, 281, 100, 40);
contentPane.add(btnT);
tfMsg = new JTextField();
tfMsg.setForeground(Color.RED);
tfMsg.setBackground(Color.BLACK);
tfMsg.setFont(new Font("Tahoma", Font.PLAIN, 18));
tfMsg.setHorizontalAlignment(SwingConstants.CENTER);
tfMsg.setBounds(12, 349, 458, 137);
contentPane.add(tfMsg);
tfMsg.setColumns(10);
}
}
![Unit Converter using Java GUI [5 Frame] 5 Unit Converter using Java GUI [5 Frame] 5](https://old.nurnobishanto.com/wp-content/uploads/2019/10/length.png)
Width Convert Source code
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
public class Width extends JFrame {
private JPanel contentPane;
private JTextField mm;
private JTextField cm;
private JTextField dm;
private JTextField m;
private JTextField km;
private JTextField mile;
private JTextField inch;
private JTextField feet;
private JTextField tfMsg;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Width frame = new Width();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Width() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 500, 600);
contentPane = new JPanel();
contentPane.setForeground(Color.WHITE);
contentPane.setBackground(Color.BLACK);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnBack = new JButton("Main Menu");
btnBack.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MainPage home = new MainPage();
home.setVisible(true);
dispose();
}
});
btnBack.setBackground(Color.BLUE);
btnBack.setForeground(Color.WHITE);
btnBack.setFont(new Font("Tahoma", Font.PLAIN, 20));
btnBack.setBounds(12, 499, 162, 41);
contentPane.add(btnBack);
JLabel lblNewLabel = new JLabel("Length Conversion");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 30));
lblNewLabel.setForeground(Color.WHITE);
lblNewLabel.setBounds(12, 13, 458, 54);
contentPane.add(lblNewLabel);
JButton exit = new JButton("Exit");
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
exit.setForeground(Color.WHITE);
exit.setFont(new Font("Tahoma", Font.PLAIN, 20));
exit.setBackground(Color.RED);
exit.setBounds(341, 499, 129, 41);
contentPane.add(exit);
JButton button = new JButton("Clear");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tfMsg.setText(null);
mm.setText(null);
cm.setText(null);
dm.setText(null);
m.setText(null);
km.setText(null);
mile.setText(null);
inch.setText(null);
feet.setText(null);
}
});
button.setForeground(Color.WHITE);
button.setFont(new Font("Tahoma", Font.PLAIN, 20));
button.setBackground(new Color(0, 100, 0));
button.setBounds(200, 499, 129, 41);
contentPane.add(button);
JButton btnMm = new JButton("Convert");
btnMm.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(mm.getText().isEmpty()) {
tfMsg.setText("Your input is emty");
}
else {
tfMsg.setText(null);
double MM = Double.parseDouble(mm.getText());
double CM = MM/10;
double DM = CM/10;
double M = DM/10;
double KM = M/1000;
double ML= KM/1.609;
double FT = ML*5280;
double INCH =FT/12;
String cM = String.format("%.4f", CM);
String dM = String.format("%.4f", DM);
String Mt = String.format("%.4f", M);
String kM = String.format("%.4f", KM);
String mL = String.format("%.4f", ML);
String fT = String.format("%.4f", FT);
String inCH = String.format("%.4f", INCH);
cm.setText(cM);
dm.setText(dM);
m.setText(Mt);
km.setText(kM);
mile.setText(mL);
feet.setText(fT);
inch.setText(inCH);
}
}
});
btnMm.setForeground(Color.YELLOW);
btnMm.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnMm.setBackground(new Color(25, 25, 112));
btnMm.setBounds(359, 80, 100, 40);
contentPane.add(btnMm);
JLabel lblNewLabel_1 = new JLabel("Millimeter");
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblNewLabel_1.setBackground(Color.BLACK);
lblNewLabel_1.setForeground(Color.WHITE);
lblNewLabel_1.setBounds(20, 80, 107, 40);
contentPane.add(lblNewLabel_1);
mm = new JTextField();
mm.setHorizontalAlignment(SwingConstants.CENTER);
mm.setFont(new Font("Tahoma", Font.PLAIN, 20));
mm.setBounds(139, 80, 147, 40);
contentPane.add(mm);
mm.setColumns(10);
JLabel lblMm = new JLabel("mm");
lblMm.setForeground(Color.WHITE);
lblMm.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblMm.setBackground(Color.BLACK);
lblMm.setBounds(292, 80, 55, 40);
contentPane.add(lblMm);
JLabel lblCentimeter = new JLabel("Centimeter");
lblCentimeter.setForeground(Color.WHITE);
lblCentimeter.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblCentimeter.setBackground(Color.BLACK);
lblCentimeter.setBounds(20, 124, 107, 40);
contentPane.add(lblCentimeter);
cm = new JTextField();
cm.setHorizontalAlignment(SwingConstants.CENTER);
cm.setFont(new Font("Tahoma", Font.PLAIN, 20));
cm.setColumns(10);
cm.setBounds(139, 124, 147, 40);
contentPane.add(cm);
JLabel lblCm = new JLabel("cm");
lblCm.setForeground(Color.WHITE);
lblCm.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblCm.setBackground(Color.BLACK);
lblCm.setBounds(292, 124, 55, 40);
contentPane.add(lblCm);
JButton btnCm = new JButton("Convert");
btnCm.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(cm.getText().isEmpty()) {
tfMsg.setText("Your input is emty");
}
else {
tfMsg.setText(null);
double CM = Double.parseDouble(cm.getText());
double MM = CM*10;
double DM = CM/10;
double M = DM/10;
double KM = M/1000;
double ML= KM/1.609;
double FT = ML*5280;
double INCH =FT/12;
String mM = String.format("%.4f", MM);
String dM = String.format("%.4f", DM);
String Mt = String.format("%.4f", M);
String kM = String.format("%.4f", KM);
String mL = String.format("%.4f", ML);
String fT = String.format("%.4f", FT);
String inCH = String.format("%.4f", INCH);
mm.setText(mM);
dm.setText(dM);
m.setText(Mt);
km.setText(kM);
mile.setText(mL);
feet.setText(fT);
inch.setText(inCH);
}
}
});
btnCm.setForeground(Color.YELLOW);
btnCm.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnCm.setBackground(new Color(25, 25, 112));
btnCm.setBounds(359, 124, 100, 40);
contentPane.add(btnCm);
JLabel lblMeter = new JLabel("Meter");
lblMeter.setForeground(Color.WHITE);
lblMeter.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblMeter.setBackground(Color.BLACK);
lblMeter.setBounds(20, 169, 107, 40);
contentPane.add(lblMeter);
JLabel lblDecimeter = new JLabel("Decimeter");
lblDecimeter.setForeground(Color.WHITE);
lblDecimeter.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblDecimeter.setBackground(Color.BLACK);
lblDecimeter.setBounds(20, 213, 107, 40);
contentPane.add(lblDecimeter);
dm = new JTextField();
dm.setHorizontalAlignment(SwingConstants.CENTER);
dm.setFont(new Font("Tahoma", Font.PLAIN, 20));
dm.setColumns(10);
dm.setBounds(139, 213, 147, 40);
contentPane.add(dm);
m = new JTextField();
m.setHorizontalAlignment(SwingConstants.CENTER);
m.setFont(new Font("Tahoma", Font.PLAIN, 20));
m.setColumns(10);
m.setBounds(139, 169, 147, 40);
contentPane.add(m);
JLabel lblM = new JLabel("m");
lblM.setForeground(Color.WHITE);
lblM.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblM.setBackground(Color.BLACK);
lblM.setBounds(292, 169, 55, 40);
contentPane.add(lblM);
JLabel lblDm = new JLabel("dm");
lblDm.setForeground(Color.WHITE);
lblDm.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblDm.setBackground(Color.BLACK);
lblDm.setBounds(292, 213, 55, 40);
contentPane.add(lblDm);
JButton btnDm = new JButton("Convert");
btnDm.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(dm.getText().isEmpty()) {
tfMsg.setText("Your input is emty");
}
else {
tfMsg.setText(null);
double DM = Double.parseDouble(dm.getText());
double CM = DM*10;
double MM = CM*10;
double M = DM/10;
double KM = M/1000;
double ML= KM/1.609;
double FT = ML*5280;
double INCH =FT/12;
String cM = String.format("%.4f", CM);
String mM = String.format("%.4f", MM);
String Mt = String.format("%.4f", M);
String kM = String.format("%.4f", KM);
String mL = String.format("%.4f", ML);
String fT = String.format("%.4f", FT);
String inCH = String.format("%.4f", INCH);
cm.setText(cM);
mm.setText(mM);
m.setText(Mt);
km.setText(kM);
mile.setText(mL);
feet.setText(fT);
inch.setText(inCH);
}
}
});
btnDm.setForeground(Color.YELLOW);
btnDm.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnDm.setBackground(new Color(25, 25, 112));
btnDm.setBounds(359, 213, 100, 40);
contentPane.add(btnDm);
JButton btnM = new JButton("Convert");
btnM.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(m.getText().isEmpty()) {
tfMsg.setText("Your input is emty");
}
else {
tfMsg.setText(null);
double M = Double.parseDouble(m.getText());
double CM = M*100;
double DM = CM/10;
double MM = CM*10;
double KM = M/1000;
double ML= KM/1.609;
double FT = ML*5280;
double INCH =FT/12;
String cM = String.format("%.4f", CM);
String dM = String.format("%.4f", DM);
String Mm = String.format("%.4f", MM);
String kM = String.format("%.4f", KM);
String mL = String.format("%.4f", ML);
String fT = String.format("%.4f", FT);
String inCH = String.format("%.4f", INCH);
cm.setText(cM);
dm.setText(dM);
mm.setText(Mm);
km.setText(kM);
mile.setText(mL);
feet.setText(fT);
inch.setText(inCH);
}
}
});
btnM.setForeground(Color.YELLOW);
btnM.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnM.setBackground(new Color(25, 25, 112));
btnM.setBounds(359, 169, 100, 40);
contentPane.add(btnM);
JLabel lblKilometer = new JLabel("Kilometer");
lblKilometer.setForeground(Color.WHITE);
lblKilometer.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblKilometer.setBackground(Color.BLACK);
lblKilometer.setBounds(20, 260, 107, 40);
contentPane.add(lblKilometer);
km = new JTextField();
km.setHorizontalAlignment(SwingConstants.CENTER);
km.setFont(new Font("Tahoma", Font.PLAIN, 20));
km.setColumns(10);
km.setBounds(139, 260, 147, 40);
contentPane.add(km);
JLabel lblKm = new JLabel("km");
lblKm.setForeground(Color.WHITE);
lblKm.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblKm.setBackground(Color.BLACK);
lblKm.setBounds(292, 260, 55, 40);
contentPane.add(lblKm);
JButton btnKm = new JButton("Convert");
btnKm.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(km.getText().isEmpty()) {
tfMsg.setText("Your input is emty");
}
else {
tfMsg.setText(null);
double KM = Double.parseDouble(km.getText());
double CM = KM*100000;
double DM = CM/10;
double M = DM/10;
double MM = CM*10;
double ML= KM/1.609;
double FT = ML*5280;
double INCH =FT/12;
String cM = String.format("%.4f", CM);
String dM = String.format("%.4f", DM);
String Mt = String.format("%.4f", M);
String mM = String.format("%.4f", MM);
String mL = String.format("%.4f", ML);
String fT = String.format("%.4f", FT);
String inCH = String.format("%.4f", INCH);
cm.setText(cM);
dm.setText(dM);
m.setText(Mt);
mm.setText(mM);
mile.setText(mL);
feet.setText(fT);
inch.setText(inCH);
}
}
});
btnKm.setForeground(Color.YELLOW);
btnKm.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnKm.setBackground(new Color(25, 25, 112));
btnKm.setBounds(359, 260, 100, 40);
contentPane.add(btnKm);
JButton btnMile = new JButton("Convert");
btnMile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(mile.getText().isEmpty()) {
tfMsg.setText("Your input is emty");
}
else {
tfMsg.setText(null);
double ML = Double.parseDouble(mile.getText());
double CM = ML*160934;
double DM = CM/10;
double M = DM/10;
double KM = M/1000;
double MM= CM*10;
double FT = ML*5280;
double INCH =FT/12;
String cM = String.format("%.4f", CM);
String dM = String.format("%.4f", DM);
String Mt = String.format("%.4f", M);
String kM = String.format("%.4f", KM);
String mM = String.format("%.4f", MM);
String fT = String.format("%.4f", FT);
String inCH = String.format("%.4f", INCH);
cm.setText(cM);
dm.setText(dM);
m.setText(Mt);
km.setText(kM);
mm.setText(mM);
feet.setText(fT);
inch.setText(inCH);
}
}
});
btnMile.setForeground(Color.YELLOW);
btnMile.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnMile.setBackground(new Color(25, 25, 112));
btnMile.setBounds(359, 304, 100, 40);
contentPane.add(btnMile);
JLabel lblMile_1 = new JLabel("mile");
lblMile_1.setForeground(Color.WHITE);
lblMile_1.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblMile_1.setBackground(Color.BLACK);
lblMile_1.setBounds(292, 304, 55, 40);
contentPane.add(lblMile_1);
mile = new JTextField();
mile.setHorizontalAlignment(SwingConstants.CENTER);
mile.setFont(new Font("Tahoma", Font.PLAIN, 20));
mile.setColumns(10);
mile.setBounds(139, 304, 147, 40);
contentPane.add(mile);
JLabel lblMile = new JLabel("Mile");
lblMile.setForeground(Color.WHITE);
lblMile.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblMile.setBackground(Color.BLACK);
lblMile.setBounds(20, 304, 107, 40);
contentPane.add(lblMile);
JLabel lblFeet = new JLabel("Feet");
lblFeet.setForeground(Color.WHITE);
lblFeet.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblFeet.setBackground(Color.BLACK);
lblFeet.setBounds(20, 349, 107, 40);
contentPane.add(lblFeet);
JLabel lblInchi = new JLabel("Inchi");
lblInchi.setForeground(Color.WHITE);
lblInchi.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblInchi.setBackground(Color.BLACK);
lblInchi.setBounds(20, 393, 107, 40);
contentPane.add(lblInchi);
inch = new JTextField();
inch.setHorizontalAlignment(SwingConstants.CENTER);
inch.setFont(new Font("Tahoma", Font.PLAIN, 20));
inch.setColumns(10);
inch.setBounds(139, 393, 147, 40);
contentPane.add(inch);
JButton btnInch = new JButton("Convert");
btnInch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(inch.getText().isEmpty()) {
tfMsg.setText("Your input is emty");
}
else {
tfMsg.setText(null);
double INCH = Double.parseDouble(inch.getText());
double CM = 2.54*INCH;
double DM = CM/10;
double M = DM/10;
double KM = M/1000;
double ML= KM/1.609;
double FT = ML*5280;
double MM =CM*10;
String cM = String.format("%.4f", CM);
String dM = String.format("%.4f", DM);
String Mt = String.format("%.4f", M);
String kM = String.format("%.4f", KM);
String mL = String.format("%.4f", ML);
String fT = String.format("%.4f", FT);
String mM = String.format("%.4f", MM);
cm.setText(cM);
dm.setText(dM);
m.setText(Mt);
km.setText(kM);
mile.setText(mL);
feet.setText(fT);
mm.setText(mM);
}
}
});
btnInch.setForeground(Color.YELLOW);
btnInch.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnInch.setBackground(new Color(25, 25, 112));
btnInch.setBounds(359, 393, 100, 40);
contentPane.add(btnInch);
JLabel lblFt = new JLabel("inch");
lblFt.setForeground(Color.WHITE);
lblFt.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblFt.setBackground(Color.BLACK);
lblFt.setBounds(292, 393, 55, 40);
contentPane.add(lblFt);
JLabel lblFt_1 = new JLabel("ft");
lblFt_1.setForeground(Color.WHITE);
lblFt_1.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblFt_1.setBackground(Color.BLACK);
lblFt_1.setBounds(292, 349, 55, 40);
contentPane.add(lblFt_1);
JButton btnFeet = new JButton("Convert");
btnFeet.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(feet.getText().isEmpty()) {
tfMsg.setText("Your input is emty");
}
else {
tfMsg.setText(null);
double FT = Double.parseDouble(feet.getText());
double CM = FT*30.48;
double DM = CM/10;
double M = DM/10;
double KM = M/1000;
double ML= KM/1.609;
double MM = CM*10;
double INCH =FT/12;
String cM = String.format("%.4f", CM);
String dM = String.format("%.4f", DM);
String Mt = String.format("%.4f", M);
String kM = String.format("%.4f", KM);
String mL = String.format("%.4f", ML);
String mM = String.format("%.4f", MM);
String inCH = String.format("%.4f", INCH);
cm.setText(cM);
dm.setText(dM);
m.setText(Mt);
km.setText(kM);
mile.setText(mL);
mm.setText(mM);
inch.setText(inCH);
}
}
});
btnFeet.setForeground(Color.YELLOW);
btnFeet.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnFeet.setBackground(new Color(25, 25, 112));
btnFeet.setBounds(359, 349, 100, 40);
contentPane.add(btnFeet);
feet = new JTextField();
feet.setText(null);
feet.setHorizontalAlignment(SwingConstants.CENTER);
feet.setFont(new Font("Tahoma", Font.PLAIN, 20));
feet.setColumns(10);
feet.setBounds(139, 349, 147, 40);
contentPane.add(feet);
tfMsg = new JTextField();
tfMsg.setBackground(Color.BLACK);
tfMsg.setHorizontalAlignment(SwingConstants.CENTER);
tfMsg.setForeground(Color.RED);
tfMsg.setFont(new Font("Tahoma", Font.PLAIN, 18));
tfMsg.setBounds(20, 446, 439, 40);
contentPane.add(tfMsg);
tfMsg.setColumns(10);
}
}
![Unit Converter using Java GUI [5 Frame] 6 Unit Converter using Java GUI [5 Frame] 6](https://old.nurnobishanto.com/wp-content/uploads/2019/10/width.png)
Currency Convert Source Code
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JFormattedTextField;
import javax.swing.JList;
import javax.swing.ListSelectionModel;
import javax.swing.JTree;
import javax.swing.JMenu;
import javax.swing.JPopupMenu;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Dimension;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JCheckBox;
public class Currency extends JFrame {
private JPanel contentPane;
private JTextField tfMsg;
private JTextField bdt;
private JTextField qtr;
private JTextField inr;
private JTextField pkr;
private JTextField usd;
private JTextField hkd;
private JTextField aud;
private JTextField gbp;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Currency frame = new Currency();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Currency() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 500, 600);
contentPane = new JPanel();
contentPane.setForeground(Color.WHITE);
contentPane.setBackground(Color.BLACK);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton button = new JButton("Main Menu");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MainPage home = new MainPage();
home.setVisible(true);
dispose();
}
});
button.setForeground(Color.WHITE);
button.setFont(new Font("Tahoma", Font.PLAIN, 20));
button.setBackground(Color.BLUE);
button.setBounds(12, 499, 162, 41);
contentPane.add(button);
JLabel lblCurrencyConversion = new JLabel("Currency Conversion");
lblCurrencyConversion.setHorizontalAlignment(SwingConstants.CENTER);
lblCurrencyConversion.setForeground(Color.WHITE);
lblCurrencyConversion.setFont(new Font("Tahoma", Font.PLAIN, 30));
lblCurrencyConversion.setBounds(12, 13, 458, 54);
contentPane.add(lblCurrencyConversion);
JButton button_1 = new JButton("Exit");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
button_1.setForeground(Color.WHITE);
button_1.setFont(new Font("Tahoma", Font.PLAIN, 20));
button_1.setBackground(Color.RED);
button_1.setBounds(362, 499, 108, 41);
contentPane.add(button_1);
JButton button_2 = new JButton("Clear");
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tfMsg.setText(null);
bdt.setText(null);
qtr.setText(null);
inr.setText(null);
pkr.setText(null);
aud.setText(null);
usd.setText(null);
hkd.setText(null);
gbp.setText(null);
}
});
button_2.setForeground(Color.WHITE);
button_2.setFont(new Font("Tahoma", Font.PLAIN, 20));
button_2.setBackground(new Color(0, 100, 0));
button_2.setBounds(209, 499, 129, 41);
contentPane.add(button_2);
tfMsg = new JTextField();
tfMsg.setFont(new Font("Tahoma", Font.PLAIN, 20));
tfMsg.setHorizontalAlignment(SwingConstants.CENTER);
tfMsg.setBackground(Color.BLACK);
tfMsg.setForeground(Color.RED);
tfMsg.setBounds(12, 432, 458, 54);
contentPane.add(tfMsg);
tfMsg.setColumns(10);
bdt = new JTextField();
bdt.setHorizontalAlignment(SwingConstants.CENTER);
bdt.setFont(new Font("Tahoma", Font.PLAIN, 20));
bdt.setColumns(10);
bdt.setBounds(141, 67, 147, 40);
contentPane.add(bdt);
qtr = new JTextField();
qtr.setHorizontalAlignment(SwingConstants.CENTER);
qtr.setFont(new Font("Tahoma", Font.PLAIN, 20));
qtr.setColumns(10);
qtr.setBounds(141, 111, 147, 40);
contentPane.add(qtr);
inr = new JTextField();
inr.setHorizontalAlignment(SwingConstants.CENTER);
inr.setFont(new Font("Tahoma", Font.PLAIN, 20));
inr.setColumns(10);
inr.setBounds(141, 156, 147, 40);
contentPane.add(inr);
pkr = new JTextField();
pkr.setHorizontalAlignment(SwingConstants.CENTER);
pkr.setFont(new Font("Tahoma", Font.PLAIN, 20));
pkr.setColumns(10);
pkr.setBounds(141, 200, 147, 40);
contentPane.add(pkr);
usd = new JTextField();
usd.setHorizontalAlignment(SwingConstants.CENTER);
usd.setFont(new Font("Tahoma", Font.PLAIN, 20));
usd.setColumns(10);
usd.setBounds(141, 247, 147, 40);
contentPane.add(usd);
hkd = new JTextField();
hkd.setHorizontalAlignment(SwingConstants.CENTER);
hkd.setFont(new Font("Tahoma", Font.PLAIN, 20));
hkd.setColumns(10);
hkd.setBounds(141, 291, 147, 40);
contentPane.add(hkd);
aud = new JTextField();
aud.setText((String) null);
aud.setHorizontalAlignment(SwingConstants.CENTER);
aud.setFont(new Font("Tahoma", Font.PLAIN, 20));
aud.setColumns(10);
aud.setBounds(141, 336, 147, 40);
contentPane.add(aud);
gbp = new JTextField();
gbp.setHorizontalAlignment(SwingConstants.CENTER);
gbp.setFont(new Font("Tahoma", Font.PLAIN, 20));
gbp.setColumns(10);
gbp.setBounds(141, 380, 147, 40);
contentPane.add(gbp);
JLabel lblBritish = new JLabel("British");
lblBritish.setForeground(Color.WHITE);
lblBritish.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblBritish.setBackground(Color.BLACK);
lblBritish.setBounds(22, 380, 107, 40);
contentPane.add(lblBritish);
JLabel lblAustralia = new JLabel("Australia");
lblAustralia.setForeground(Color.WHITE);
lblAustralia.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblAustralia.setBackground(Color.BLACK);
lblAustralia.setBounds(22, 336, 107, 40);
contentPane.add(lblAustralia);
JLabel lblHongkong = new JLabel("HongKong");
lblHongkong.setForeground(Color.WHITE);
lblHongkong.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblHongkong.setBackground(Color.BLACK);
lblHongkong.setBounds(22, 291, 107, 40);
contentPane.add(lblHongkong);
JLabel lblUnitedState = new JLabel("United State");
lblUnitedState.setForeground(Color.WHITE);
lblUnitedState.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblUnitedState.setBackground(Color.BLACK);
lblUnitedState.setBounds(22, 247, 107, 40);
contentPane.add(lblUnitedState);
JLabel lblPakistan = new JLabel("Pakistan");
lblPakistan.setForeground(Color.WHITE);
lblPakistan.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblPakistan.setBackground(Color.BLACK);
lblPakistan.setBounds(22, 200, 107, 40);
contentPane.add(lblPakistan);
JLabel lblIndia = new JLabel("India");
lblIndia.setForeground(Color.WHITE);
lblIndia.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblIndia.setBackground(Color.BLACK);
lblIndia.setBounds(22, 156, 107, 40);
contentPane.add(lblIndia);
JLabel lblQatar = new JLabel("Qatar");
lblQatar.setForeground(Color.WHITE);
lblQatar.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblQatar.setBackground(Color.BLACK);
lblQatar.setBounds(22, 111, 107, 40);
contentPane.add(lblQatar);
JLabel lblBangladesh = new JLabel("Bangladesh");
lblBangladesh.setForeground(Color.WHITE);
lblBangladesh.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblBangladesh.setBackground(Color.BLACK);
lblBangladesh.setBounds(22, 67, 107, 40);
contentPane.add(lblBangladesh);
JLabel lblBdt = new JLabel("BDT");
lblBdt.setForeground(Color.WHITE);
lblBdt.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblBdt.setBackground(Color.BLACK);
lblBdt.setBounds(294, 67, 55, 40);
contentPane.add(lblBdt);
JLabel lblQar = new JLabel("QAR");
lblQar.setForeground(Color.WHITE);
lblQar.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblQar.setBackground(Color.BLACK);
lblQar.setBounds(294, 111, 55, 40);
contentPane.add(lblQar);
JLabel lblInr = new JLabel("INR");
lblInr.setForeground(Color.WHITE);
lblInr.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblInr.setBackground(Color.BLACK);
lblInr.setBounds(294, 156, 55, 40);
contentPane.add(lblInr);
JLabel lblPkr = new JLabel("PKR");
lblPkr.setForeground(Color.WHITE);
lblPkr.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblPkr.setBackground(Color.BLACK);
lblPkr.setBounds(294, 200, 55, 40);
contentPane.add(lblPkr);
JLabel lblUsd = new JLabel("USD");
lblUsd.setForeground(Color.WHITE);
lblUsd.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblUsd.setBackground(Color.BLACK);
lblUsd.setBounds(294, 247, 55, 40);
contentPane.add(lblUsd);
JLabel lblHkd = new JLabel("HKD");
lblHkd.setForeground(Color.WHITE);
lblHkd.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblHkd.setBackground(Color.BLACK);
lblHkd.setBounds(294, 291, 55, 40);
contentPane.add(lblHkd);
JLabel lblAud = new JLabel("AUD");
lblAud.setForeground(Color.WHITE);
lblAud.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblAud.setBackground(Color.BLACK);
lblAud.setBounds(294, 336, 55, 40);
contentPane.add(lblAud);
JLabel lblGbp = new JLabel("GBP");
lblGbp.setForeground(Color.WHITE);
lblGbp.setFont(new Font("Tahoma", Font.PLAIN, 18));
lblGbp.setBackground(Color.BLACK);
lblGbp.setBounds(294, 380, 55, 40);
contentPane.add(lblGbp);
JButton btnGbp = new JButton("Check");
btnGbp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(gbp.getText().isEmpty())
{
tfMsg.setText("Your input is Empty !");
}
else
{
tfMsg.setText(null);
double Gbp = Double.parseDouble(gbp.getText());
double Usd = Gbp * 0.7736;
double Pkr = Usd * 0.0064;
double Inr = Pkr * 0.45;
double Qtr = Inr * 0.051;
double Hkd = Qtr * 0.46;
double Aud = Hkd * 5.36;
double Bdt = Usd * 84.47;
String USD = String.format("%.3f", Usd);
String PKR = String.format("%.3f", Pkr);
String INR = String.format("%.3f", Inr);
String QTR = String.format("%.3f", Qtr);
String HKD = String.format("%.3f", Hkd);
String AUD = String.format("%.3f", Aud);
String BDT = String.format("%.3f", Bdt);
usd.setText(USD);
pkr.setText(PKR);
inr.setText(INR);
qtr.setText(QTR);
hkd.setText(HKD);
aud.setText(AUD);
bdt.setText(BDT);
}
}
});
btnGbp.setForeground(Color.YELLOW);
btnGbp.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnGbp.setBackground(new Color(25, 25, 112));
btnGbp.setBounds(361, 380, 100, 40);
contentPane.add(btnGbp);
JButton btnAud = new JButton("Check");
btnAud.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(aud.getText().isEmpty())
{
tfMsg.setText("Your input is Empty !");
}
else
{
tfMsg.setText(null);
double Aud = Double.parseDouble(aud.getText());
double Usd = Aud * 1.4615;
double Pkr = Usd * 0.0064;
double Inr = Pkr * 0.45;
double Qtr = Inr * 0.051;
double Hkd = Qtr * 0.46;
double Bdt = Usd * 84.47;
double Gbp = Aud * 1.889;
String USD = String.format("%.3f", Usd);
String PKR = String.format("%.3f", Pkr);
String INR = String.format("%.3f", Inr);
String QTR = String.format("%.3f", Qtr);
String HKD = String.format("%.3f", Hkd);
String BDT = String.format("%.3f", Bdt);
String GBP = String.format("%.3f", Gbp);
usd.setText(USD);
pkr.setText(PKR);
inr.setText(INR);
qtr.setText(QTR);
hkd.setText(HKD);
bdt.setText(BDT);
gbp.setText(GBP);
}
}
});
btnAud.setForeground(Color.YELLOW);
btnAud.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnAud.setBackground(new Color(25, 25, 112));
btnAud.setBounds(361, 336, 100, 40);
contentPane.add(btnAud);
JButton btnHkd = new JButton("Check");
btnHkd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(hkd.getText().isEmpty())
{
tfMsg.setText("Your input is Empty !");
}
else
{
tfMsg.setText(null);
double Hkd = Double.parseDouble(hkd.getText());
double Usd = Hkd * 7.84;
double Pkr = Usd * 0.0064;
double Inr = Pkr * 0.45;
double Qtr = Inr * 0.051;
double Bdt = Usd * 84.47;
double Aud = Hkd * 5.36;
double Gbp = Aud * 1.889;
String USD = String.format("%.3f", Usd);
String PKR = String.format("%.3f", Pkr);
String INR = String.format("%.3f", Inr);
String QTR = String.format("%.3f", Qtr);
String BDT = String.format("%.3f", Bdt);
String AUD = String.format("%.3f", Aud);
String GBP = String.format("%.3f", Gbp);
usd.setText(USD);
pkr.setText(PKR);
inr.setText(INR);
qtr.setText(QTR);
bdt.setText(BDT);
aud.setText(AUD);
gbp.setText(GBP);
}
}
});
btnHkd.setForeground(Color.YELLOW);
btnHkd.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnHkd.setBackground(new Color(25, 25, 112));
btnHkd.setBounds(361, 291, 100, 40);
contentPane.add(btnHkd);
JButton btnUsd = new JButton("Check");
btnUsd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(usd.getText().isEmpty())
{
tfMsg.setText("Your input is Empty !");
}
else
{
tfMsg.setText(null);
double Usd = Double.parseDouble(usd.getText());
double Bdt = Usd / 84.47;
double Pkr = Usd * 0.0064;
double Inr = Pkr * 0.45;
double Qtr = Inr * 0.051;
double Hkd = Qtr * 0.46;
double Aud = Hkd * 5.36;
double Gbp = Aud * 1.889;
String BDT = String.format("%.3f", Bdt);
String PKR = String.format("%.3f", Pkr);
String INR = String.format("%.3f", Inr);
String QTR = String.format("%.3f", Qtr);
String HKD = String.format("%.3f", Hkd);
String AUD = String.format("%.3f", Aud);
String GBP = String.format("%.3f", Gbp);
bdt.setText(BDT);
pkr.setText(PKR);
inr.setText(INR);
qtr.setText(QTR);
hkd.setText(HKD);
aud.setText(AUD);
gbp.setText(GBP);
}
}
});
btnUsd.setForeground(Color.YELLOW);
btnUsd.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnUsd.setBackground(new Color(25, 25, 112));
btnUsd.setBounds(361, 247, 100, 40);
contentPane.add(btnUsd);
JButton btnPkr = new JButton("Check");
btnPkr.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(pkr.getText().isEmpty())
{
tfMsg.setText("Your input is Empty !");
}
else
{
tfMsg.setText(null);
double Pkr = Double.parseDouble(pkr.getText());
double Usd = Pkr * 156.05;
double Bdt = Usd * 84.47;
double Inr = Pkr * 0.45;
double Qtr = Inr * 0.051;
double Hkd = Qtr * 0.46;
double Aud = Hkd * 5.36;
double Gbp = Aud * 1.889;
String USD = String.format("%.3f", Usd);
String BDT = String.format("%.3f", Bdt);
String INR = String.format("%.3f", Inr);
String QTR = String.format("%.3f", Qtr);
String HKD = String.format("%.3f", Hkd);
String AUD = String.format("%.3f", Aud);
String GBP = String.format("%.3f", Gbp);
usd.setText(USD);
bdt.setText(BDT);
inr.setText(INR);
qtr.setText(QTR);
hkd.setText(HKD);
aud.setText(AUD);
gbp.setText(GBP);
}
}
});
btnPkr.setForeground(Color.YELLOW);
btnPkr.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnPkr.setBackground(new Color(25, 25, 112));
btnPkr.setBounds(361, 200, 100, 40);
contentPane.add(btnPkr);
JButton btnInr = new JButton("Check");
btnInr.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(inr.getText().isEmpty())
{
tfMsg.setText("Your input is Empty !");
}
else
{
tfMsg.setText(null);
double Inr = Double.parseDouble(inr.getText());
double Usd = Inr * 70.936;
double Pkr = Usd * 0.0064;
double Bdt = Usd /84.47;
double Qtr = Inr * 0.051;
double Hkd = Qtr * 0.46;
double Aud = Hkd * 5.36;
double Gbp = Aud * 1.889;
String USD = String.format("%.3f", Usd);
String PKR = String.format("%.3f", Pkr);
String BDT = String.format("%.3f", Bdt);
String QTR = String.format("%.3f", Qtr);
String HKD = String.format("%.3f", Hkd);
String AUD = String.format("%.3f", Aud);
String GBP = String.format("%.3f", Gbp);
usd.setText(USD);
pkr.setText(PKR);
bdt.setText(BDT);
qtr.setText(QTR);
hkd.setText(HKD);
aud.setText(AUD);
gbp.setText(GBP);
}
}
});
btnInr.setForeground(Color.YELLOW);
btnInr.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnInr.setBackground(new Color(25, 25, 112));
btnInr.setBounds(361, 156, 100, 40);
contentPane.add(btnInr);
JButton btnQar = new JButton("Check");
btnQar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(qtr.getText().isEmpty())
{
tfMsg.setText("Your input is Empty !");
}
else
{
tfMsg.setText(null);
double Qtr = Double.parseDouble(qtr.getText());
double Usd = Qtr * 3.641;
double Pkr = Usd * 0.0064;
double Inr = Pkr * 0.45;
double Bdt = Usd / 84.47;
double Hkd = Qtr * 0.46;
double Aud = Hkd * 5.36;
double Gbp = Aud * 1.889;
String USD = String.format("%.3f", Usd);
String PKR = String.format("%.3f", Pkr);
String INR = String.format("%.3f", Inr);
String BDT = String.format("%.3f", Bdt);
String HKD = String.format("%.3f", Hkd);
String AUD = String.format("%.3f", Aud);
String GBP = String.format("%.3f", Gbp);
usd.setText(USD);
pkr.setText(PKR);
inr.setText(INR);
bdt.setText(BDT);
hkd.setText(HKD);
aud.setText(AUD);
gbp.setText(GBP);
}
}
});
btnQar.setForeground(Color.YELLOW);
btnQar.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnQar.setBackground(new Color(25, 25, 112));
btnQar.setBounds(361, 111, 100, 40);
contentPane.add(btnQar);
JButton btnBdt = new JButton("Check");
btnBdt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(bdt.getText().isEmpty())
{
tfMsg.setText("Your input is Empty !");
}
else
{
tfMsg.setText(null);
double Bdt = Double.parseDouble(bdt.getText());
double Usd = Bdt * 84.47;
double Pkr = Usd * 0.0064;
double Inr = Pkr * 0.45;
double Qtr = Inr * 0.051;
double Hkd = Qtr * 0.46;
double Aud = Hkd * 5.36;
double Gbp = Aud * 1.889;
String USD = String.format("%.3f", Usd);
String PKR = String.format("%.3f", Pkr);
String INR = String.format("%.3f", Inr);
String QTR = String.format("%.3f", Qtr);
String HKD = String.format("%.3f", Hkd);
String AUD = String.format("%.3f", Aud);
String GBP = String.format("%.3f", Gbp);
usd.setText(USD);
pkr.setText(PKR);
inr.setText(INR);
qtr.setText(QTR);
hkd.setText(HKD);
aud.setText(AUD);
gbp.setText(GBP);
}
}
});
btnBdt.setForeground(Color.YELLOW);
btnBdt.setFont(new Font("Tahoma", Font.PLAIN, 18));
btnBdt.setBackground(new Color(25, 25, 112));
btnBdt.setBounds(361, 67, 100, 40);
contentPane.add(btnBdt);
}
}
![Unit Converter using Java GUI [5 Frame] 7 Unit Converter using Java GUI [5 Frame] 7](https://old.nurnobishanto.com/wp-content/uploads/2019/10/currency.png)
Thank you