CURRENCY
CONVETER BY
USING JAVA
LEAD:- DURGA
PRASAD
&
HTML
[Link]
[Link]
[Link]
[Link]
[Link]
TOPICS :
JFrame
JLabel
JTextField
JButton
JFRAME :
JFrameis a java class that is extended by
Frame class of Java. JFrame is treated as the
main window. In JFrame different elements
such as labels, text fields, buttons can be
added. These elements on JFrame create
Graphical User Interface. JFrame is also known
as Swing top-level container.
JLABEL:
The object of JLabel class is a component for
placing text in a container. It is used to display
a single line of read only text. The text can be
changed by an application but a user cannot
edit it directly. It inherits JComponent class.
JTEXTFIELD:
JTextFieldis a part of [Link] package. The
class JTextField is a component that allows
editing of a single line of text. JTextField
inherits the JTextComponent class and uses the
interface SwingConstants.
JBUTTON :
TheJButton class is used to create a labeled
button that has platform independent
implementation. The application result in some
action when the button is pushed. It inherits
AbstractButton class.
CURRENCY CONVETER
PROGRAME :
// Java program to convert from
import [Link].*;
import [Link].*;
import [Link].*;
public class Project{
// Function to convert from rupee
// to the dollar and vice-versa
// using Java Swing
public static void converter()
{
// Creating a new frame using JFrame
JFrame f = new JFrame("CONVERTER");
// Creating two labels
JLabel l1, l2;
// Creating two text fields
// One for rupee and one for
// the dollar
JTextField t1, t2;
// Creating three buttons
JButton b1, b2, b3;
// Naming the labels and setting
// the bounds for the labels
l1 = new JLabel("Rupees:");
[Link](20, 40, 60, 30);
l2 = new JLabel("Dollars:");
[Link](170, 40, 60, 30);
// Initializing the text fields with
// 0 by default and setting the
// bounds for the text fields
t1 = new JTextField("0");
[Link](240, 40, 50, 30);
// Creating a button for INR,
// one button for the dollar
// and one button to close
// and setting the bounds
b1 = new JButton("INR");
[Link](50, 80, 60, 15);
b2 = new JButton("Dollar");
[Link](190, 80, 60, 15);
b3 = new JButton("close");
[Link](150, 150, 60, 30);
// Adding action listener
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e)
{
// Converting to double
double d
= [Link]([Link]());
// Converting rupees to dollars
double d1 = (d / 65.25);
// Getting the string value of the
// calculated value
String str1 = [Link](d1);
// Placing it in the text box
[Link](str1);
}
});
// Adding action listener
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e)
{
// Converting to double
double d2
= [Link]([Link]());
// converting Dollars to rupees
double d3 = (d2 * 65.25);
// Getting the string value of the
// calculated value
String str2 = [Link](d3);
// Placing it in the text box
[Link](str2);
}
});
// Action listener to close the form
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e)
{
[Link]();
}
});
// Default method for closing the frame
[Link](new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
[Link](0);
}
});
[Link](l1);
[Link](t1);
[Link](l2);
[Link](t2);
[Link](b1);
[Link](b2);
[Link](b3);
[Link](null);
[Link](400, 300);
[Link](true);
}
public static void main(String args[])
{
converter();
}
}
OUTPUT OF THE PROGRAME :
THANK YOU