package umrechner;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Euro extends JFrame
{
JTextField euro=new JTextField();
JTextField dollar=new JTextField();
JButton button1=new JButton("Euro in Dollar");
JButton button2=new JButton("Dollar in Euro");
JButton button3=new JButton("und tschüss");
JComboBox combo=new JComboBox();
//
public Euro(String titel)
{
super(titel);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container cont1= getContentPane();
JPanel panel=new JPanel();
panel.setLayout(new GridLayout(3,3));
cont1.add(panel);
JPanel panel1=new JPanel();
button1.setPreferredSize(new Dimension(150,30));
panel1.add(button1);
panel.add(panel1);
JPanel panel4=new JPanel();
JLabel label4=new JLabel("Eingabe in €");
euro.setPreferredSize(new Dimension(100,20));
panel4.add(label4);
panel4.add(euro);
panel.add(panel4);
JPanel panel2=new JPanel();
button2.setPreferredSize(new Dimension(150,30));
panel2.add(button2);
panel.add(panel2);
JPanel panel5=new JPanel();
JLabel label3=new JLabel("Eingabe in $");
dollar.setPreferredSize(new Dimension(100,20));
panel4.add(label3);
panel4.add(dollar);
panel.add(panel5);
JPanel panel3=new JPanel();
button3.setPreferredSize(new Dimension(150,30));
panel3.add(button3);
panel.add(panel3);
ActionListener listener=new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
euro_in_dollar();
}
};
button1.addActionListener(listener);
ActionListener listener1=new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dollar_in_euro();
}
};
button2.addActionListener(listener1);
ActionListener listener2=new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
};
button3.addActionListener(listener2);
}
public void euro_in_dollar()
{
try
{
//1 Euro=1,2713 USD
double eingabe_euro=Double.parseDouble(euro.getText());
double erg=eingabe_euro/(1.2713);
JOptionPane.showMessageDialog(null,"Ergebnis lautet: "+erg);
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null,"Du hast leider keine Zahl eingeben!!!:D");
}
}
public void dollar_in_euro()
{
try
{
double eingabe_dollar=Double.parseDouble(dollar.getText());
double erg=1.2713*eingabe_dollar;
JOptionPane.showMessageDialog(null,"Ergebnis lautet: "+erg);
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null,"Du hast leider keine Zahl eingeben!!!:D");
}
}
public void centerFrame()
{
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
int mx=d.width;
int my=d.height;
int fx=getSize().width;
int fy=getSize().height;
setLocation((mx-fx)/2,(my-fy)/2);
}
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //Windows Look and feel
}
catch (Exception e)
{
e.printStackTrace();
}
Euro frame = new Euro("Umrechner € <> $");
frame.setSize(400,200);
frame.setLocation(450,450);
frame.centerFrame();
frame.setVisible(true);
frame.setResizable(false);
}
}