hi i am trying to make a currency converter to convert British pounds, US Dollars and Euros . i have the GUI made but i wanted to make a separate class to handle the conversion of the currencys but im not sure where to start so i was wondering if any one could help me.
/*
* Interface.java
*
* Created on 11 August 2010, 18:40
*/
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
*
* @author Matt
*/
public class Interface extends javax.swing.JFrame {
//Variables
//starts the static user control method
private static final String CONTROL = "This is a currency converter it converts Pounds, Euros and US Dollars";
// To Check for button clicks
int decimalClick;
/** Creates new form Interface */
public Interface() {
initComponents();
Money.setHorizontalAlignment(Money.RIGHT);
}
/**
* About the Programmer and Currency Converter.
*/
private void showAbout()
{ JOptionPane.showMessageDialog(Frame,
"Programmer: Matthew Donoghue " + CONTROL,
"Currency Converter Help",
JOptionPane.INFORMATION_MESSAGE);
}
/**
* quit the game.
*/
private void quit() {
System.exit(0);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jMenuBar2 = new javax.swing.JMenuBar();
jMenu2 = new javax.swing.JMenu();
Frame = new javax.swing.JPanel();
Money = new javax.swing.JTextField();
One = new javax.swing.JButton();
Two = new javax.swing.JButton();
Three = new javax.swing.JButton();
Four = new javax.swing.JButton();
Seven = new javax.swing.JButton();
Decimal = new javax.swing.JButton();
Five = new javax.swing.JButton();
Eight = new javax.swing.JButton();
Zero = new javax.swing.JButton();
Six = new javax.swing.JButton();
Nine = new javax.swing.JButton();
Equals = new javax.swing.JButton();
Clear = new javax.swing.JButton();
GBP = new javax.swing.JToggleButton();
EUR = new javax.swing.JToggleButton();
USD = new javax.swing.JToggleButton();
Menu = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
quitMenu = new javax.swing.JMenuItem();
currencyMenu = new javax.swing.JMenu();
gbpMenu = new javax.swing.JMenuItem();
eurMenu = new javax.swing.JMenuItem();
usdMenu = new javax.swing.JMenuItem();
helpMenu = new javax.swing.JMenu();
helpItem = new javax.swing.JMenuItem();
AboutMenu = new javax.swing.JMenuItem();
updateMenu = new javax.swing.JMenu();
checkUpdateMenu = new javax.swing.JMenuItem();
jMenu2.setText("Menu");
jMenuBar2.add(jMenu2);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
formMouseClicked(evt);
}
});
Frame.setBorder(javax.swing.BorderFactory.createEtchedBorder());
Money.setEditable(false);
Money.setFont(new java.awt.Font("Tahoma", 0, 24));
Money.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
Money.setText("0");
One.setFont(new java.awt.Font("Tahoma", 1, 11));
One.setText("1");
One.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
OneActionPerformed(evt);
}
});
Two.setFont(new java.awt.Font("Tahoma", 1, 11));
Two.setText("2");
Two.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
TwoActionPerformed(evt);
}
});
Three.setFont(new java.awt.Font("Tahoma", 1, 11));
Three.setText("3");
Three.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ThreeActionPerformed(evt);
}
});
Four.setFont(new java.awt.Font("Tahoma", 1, 11));
Four.setText("4");
Four.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
FourActionPerformed(evt);
}
});
Seven.setFont(new java.awt.Font("Tahoma", 1, 11));
Seven.setText("7");
Seven.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SevenActionPerformed(evt);
}
});
Decimal.setFont(new java.awt.Font("Tahoma", 1, 11));
Decimal.setText(".");
Decimal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
DecimalActionPerformed(evt);
}
});
Five.setFont(new java.awt.Font("Tahoma", 1, 11));
Five.setText("5");
Five.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
FiveActionPerformed(evt);
}
});
Eight.setFont(new java.awt.Font("Tahoma", 1, 11));
Eight.setText("8");
Eight.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EightActionPerformed(evt);
}
});
Zero.setFont(new java.awt.Font("Tahoma", 1, 11));
Zero.setText("0");
Zero.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ZeroActionPerformed(evt);
}
});
Six.setFont(new java.awt.Font("Tahoma", 1, 11));
Six.setText("6");
Six.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SixActionPerformed(evt);
}
});
Nine.setFont(new java.awt.Font("Tahoma", 1, 11));
Nine.setText("9");
Nine.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
NineActionPerformed(evt);
}
});
Equals.setFont(new java.awt.Font("Tahoma", 1, 11));
Equals.setText("=");
Equals.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EqualsActionPerformed(evt);
}
});
Clear.setFont(new java.awt.Font("Tahoma", 1, 11));
Clear.setText("Clear");
Clear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ClearActionPerformed(evt);
}
});
javax.swing.GroupLayout FrameLayout = new javax.swing.GroupLayout(Frame);
Frame.setLayout(FrameLayout);
FrameLayout.setHorizontalGroup(
FrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(FrameLayout.createSequentialGroup()
.addContainerGap()
.addGroup(FrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Money, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE)
.addGroup(FrameLayout.createSequentialGroup()
.addComponent(Decimal, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Zero, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Equals, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(85, 85, 85))
.addGroup(FrameLayout.createSequentialGroup()
.addGroup(FrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(FrameLayout.createSequentialGroup()
.addComponent(Seven, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Eight, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Nine, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(FrameLayout.createSequentialGroup()
.addGroup(FrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(FrameLayout.createSequentialGroup()
.addComponent(One, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Two, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(FrameLayout.createSequentialGroup()
.addComponent(Four, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Five, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(FrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Three, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Six, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Clear)))
.addGap(28, 28, 28)))
.addContainerGap())
);
FrameLayout.setVerticalGroup(
FrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(FrameLayout.createSequentialGroup()
.addContainerGap()
.addComponent(Money, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(15, 15, 15)
.addGroup(FrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(FrameLayout.createSequentialGroup()
.addGroup(FrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(One, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Two, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Three, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(FrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(FrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Five, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Six, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(Four, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(FrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Seven, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Eight, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Nine, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(FrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Decimal, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Zero, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Equals, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(Clear, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(46, Short.MAX_VALUE))
);
GBP.setText("GBP \u00a3");
EUR.setText("EUR \u20ac");
EUR.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
EURMouseClicked(evt);
}
});
USD.setText("USD $");
USD.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
USDMouseClicked(evt);
}
});
fileMenu.setText("File");
fileMenu.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
fileMenuMouseClicked(evt);
}
});
quitMenu.setText("Quit");
quitMenu.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
quitMenuMouseClicked(evt);
}
});
quitMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
quitMenuActionPerformed(evt);
}
});
fileMenu.add(quitMenu);
Menu.add(fileMenu);
currencyMenu.setText("Currency");
gbpMenu.setText("British Pound");
currencyMenu.add(gbpMenu);
eurMenu.setText("Euro");
currencyMenu.add(eurMenu);
usdMenu.setText("US Dollar ");
currencyMenu.add(usdMenu);
Menu.add(currencyMenu);
helpMenu.setText("Help");
helpItem.setText("Help!");
helpItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
helpItemActionPerformed(evt);
}
});
helpMenu.add(helpItem);
AboutMenu.setText("About");
AboutMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AboutMenuActionPerformed(evt);
}
});
helpMenu.add(AboutMenu);
Menu.add(helpMenu);
updateMenu.setText("Update");
checkUpdateMenu.setText("Check Update");
updateMenu.add(checkUpdateMenu);
Menu.add(updateMenu);
setJMenuBar(Menu);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(Frame, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(GBP)
.addGap(32, 32, 32)
.addComponent(EUR)
.addGap(37, 37, 37)
.addComponent(USD)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(GBP)
.addComponent(EUR)
.addComponent(USD))
.addGap(19, 19, 19)
.addComponent(Frame, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(97, 97, 97))
);
pack();
}// </editor-fold>
private void helpItemActionPerformed(java.awt.event.ActionEvent evt) {
}
private void AboutMenuActionPerformed(java.awt.event.ActionEvent evt) {
showAbout();
}
private void quitMenuActionPerformed(java.awt.event.ActionEvent evt) {
quit();
}
private void quitMenuMouseClicked(java.awt.event.MouseEvent evt) {
}
private void fileMenuMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
}
private void USDMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
}
private void EURMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
}
private void formMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
}
private void EqualsActionPerformed(java.awt.event.ActionEvent evt) {
}
private void DecimalActionPerformed(java.awt.event.ActionEvent evt) {
if(decimalClick==0){
Money.setText(Money.getText()+Decimal.getText());
decimalClick=1;
}
}
private void ZeroActionPerformed(java.awt.event.ActionEvent evt) {
Money.setText(Money.getText()+Zero.getText());
}
private void NineActionPerformed(java.awt.event.ActionEvent evt) {
Money.setText(Money.getText()+Nine.getText());
}
private void EightActionPerformed(java.awt.event.ActionEvent evt) {
Money.setText(Money.getText()+Eight.getText());
}
private void SevenActionPerformed(java.awt.event.ActionEvent evt) {
Money.setText(Money.getText()+Seven.getText());
}
private void SixActionPerformed(java.awt.event.ActionEvent evt) {
Money.setText(Money.getText()+Six.getText());
}
private void FiveActionPerformed(java.awt.event.ActionEvent evt) {
Money.setText(Money.getText()+Five.getText());
}
private void FourActionPerformed(java.awt.event.ActionEvent evt) {
Money.setText(Money.getText()+Four.getText());
}
private void ThreeActionPerformed(java.awt.event.ActionEvent evt) {
Money.setText(Money.getText()+Three.getText());
}
private void TwoActionPerformed(java.awt.event.ActionEvent evt) {
Money.setText(Money.getText()+Two.getText());
}
private void OneActionPerformed(java.awt.event.ActionEvent evt) {
Money.setText(Money.getText()+One.getText());
}
private void ClearActionPerformed(java.awt.event.ActionEvent evt) {
Money.setText("0");
decimalClick=0;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Interface().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenuItem AboutMenu;
private javax.swing.JButton Clear;
private javax.swing.JButton Decimal;
private javax.swing.JToggleButton EUR;
private javax.swing.JButton Eight;
private javax.swing.JButton Equals;
private javax.swing.JButton Five;
private javax.swing.JButton Four;
private javax.swing.JPanel Frame;
private javax.swing.JToggleButton GBP;
private javax.swing.JMenuBar Menu;
private javax.swing.JTextField Money;
private javax.swing.JButton Nine;
private javax.swing.JButton One;
private javax.swing.JButton Seven;
private javax.swing.JButton Six;
private javax.swing.JButton Three;
private javax.swing.JButton Two;
private javax.swing.JToggleButton USD;
private javax.swing.JButton Zero;
private javax.swing.JMenuItem checkUpdateMenu;
private javax.swing.JMenu currencyMenu;
private javax.swing.JMenuItem eurMenu;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenuItem gbpMenu;
private javax.swing.JMenuItem helpItem;
private javax.swing.JMenu helpMenu;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar2;
private javax.swing.JMenuItem quitMenu;
private javax.swing.JMenu updateMenu;
private javax.swing.JMenuItem usdMenu;
// End of variables declaration
}