import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
 * Created by JFormDesigner on Wed Apr 27 11:27:07 CEST 2005
 */

public class TempConverter extends JFrame
{
	public TempConverter()
	{
		initComponents();
		ActionListener converter =
		 new ActionListener()
		 {
		    public void actionPerformed (ActionEvent e)
		    {
		       String input = inputField.getText();
		       try {
		          double celsius = Double.parseDouble(input);
		          double fahrenheit = toFahrenheit(celsius);
		         outputArea.append(input + " Grad Celsius => " + fahrenheit + " Grad Fahrenheit\n");
		       }
		       catch (NumberFormatException nfe)
		       {
		          outputArea.append("Eingabefehler: " + input + "\n");
		       }
		       inputField.selectAll();
		    }
		 };
		 calcButton.addActionListener(converter);
		 inputField.addActionListener(converter);
		 pack();
		 inputField.requestFocusInWindow();
		 setVisible(true);
	}

   static double toFahrenheit (double celsius)
   { return celsius * 9 / 5 + 32; }
   
	private void initComponents()
	{
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		inputPanel = new JPanel();
		fieldLabel = new JLabel();
		inputField = new JTextField();
		calcButton = new JButton();
		outputPane = new JScrollPane();
		outputArea = new JTextArea();

		//======== this ========
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("Fahrenheit-Umrechner");
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		//======== inputPanel ========
		{
			inputPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
			
			//---- fieldLabel ----
			fieldLabel.setText("Temperatur (Celsius):");
			inputPanel.add(fieldLabel);
			
			//---- inputField ----
			inputField.setColumns(8);
			inputPanel.add(inputField);
			
			//---- calcButton ----
			calcButton.setText("Umrechnen");
			inputPanel.add(calcButton);
		}
		contentPane.add(inputPanel, BorderLayout.SOUTH);

		//======== outputPane ========
		{
			
			//---- outputArea ----
			outputArea.setColumns(40);
			outputArea.setEditable(false);
			outputArea.setLineWrap(false);
			outputArea.setRows(6);
			outputPane.setViewportView(outputArea);
		}
		contentPane.add(outputPane, BorderLayout.CENTER);
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	private JPanel inputPanel;
	private JLabel fieldLabel;
	private JTextField inputField;
	private JButton calcButton;
	private JScrollPane outputPane;
	private JTextArea outputArea;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
	
	public static void main (String[] args)
	{ JFrame f = new TempConverter(); }
}

