I'm new to java and I'm trying to create a currency converter right now. I've made this little currency converter that converts Dollars into euros and pounds. When ran, it pops up the java screen and you can enter the amount of dollars you would like to convert, and it will give you the amount of euros/pounds it would be.
Now i would like to display a little Jpannel message first. I can't quite seem to figure out how. Im sure its quite easy so forgive me for my newbieness. Help would be fantastic
Sorry if the layout of my question seems odd. im not familiar with this website yet. I will improve.
Thanks in advance for any help given.
I've made this so far:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.JOptionPane;
class converter extends JFrame {
private static final double DOLLAR_PER_EURO = 0.77;
//private static final double DOLLAR_PER_POUND = 0.66;
private JTextField _dollarsTF = new JTextField(3);
private JTextField _eurosTF = new JTextField(3);
private JTextField _poundsTF = new JTextField(3);
public converter() {
JButton convertBtn = new JButton("Convert");
convertBtn.addActionListener(new ConvertBtnListener());
_dollarsTF.addActionListener((ActionListener) new ConvertBtnListener());
_eurosTF.setEditable(false);
_poundsTF.setEditable(false);
JPanel content = new JPanel();
content.setLayout(new FlowLayout());
content.add(new JLabel("Enter amounts of dollars to compare: "));
content.add(_dollarsTF);
content.add(convertBtn);
content.add(new JLabel("Euros: "));
content.add(_eurosTF);
// content.add(new JLabel("English Pounds: "));
// content.add(_poundsTF);
setContentPane(content);
pack();
setTitle("Currency converter");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}
class ConvertBtnListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String dyStr = _dollarsTF.getText();
int Dollars = Integer.parseInt(dyStr);
double Euros = Dollars * DOLLAR_PER_EURO;
//double Pounds = Dollars * DOLLAR_PER_POUND;
_eurosTF.setText("" + Euros);
// _poundsTF.setText("" + Pounds);
}
}
public static void main(String[] args) {
converter window = new converter();
window.setVisible(true);
}
}