Währungsumrechner

Status
Nicht offen für weitere Antworten.
X

X-Shot

Gast
Hiho Leute,

ich bin zwar Fachinformatiker, aber nicht Anwendungsentwickler!!
Muss zu morgen ne Klausur schreiben, wo ich schon weiss, das es n Währungsumrechner sein wird, die wir als GUI mit java.awt konstruieren sollen!!
Bis auf den ActionListener funktionert alles, wie auch sonst?!?! : (

Da wollt ich fragen, ob mir jem helfen kann!?!?

Hab hier mein Code mal hingestellt, vielleicht sieht ja jemand meinen Newbie-Fehler!!!



--------------------------------------------------
Code:
import java.awt.*;

public class WaehrungsumrechnerGUI extends Frame
{
	//Vereinbarung von Fonts
	Font f1 = new Font("Arial", Font.BOLD,20);
	Font f2 = new Font("Arial", Font.BOLD,16);
	
	//Vereinbarung von Komponenten
	Label lblUeberschrift	= new Label("Waehrungsumrechner");
	Label lblVon			= new Label("VON €uro: ");
	Label lblNach			= new Label("NACH: ");
	TextField tfVon			= new TextField(10);
	TextField tfNach		= new TextField(10);
		
	//Button anlegen
	Button btnUmrechnen		= new Button("Umrechnen");
	Button btnRueckrechnen	= new Button("Rueckrechnen");	
	Button btnBeenden		= new Button("Beenden");
		
	//CheckboxGroup anlegen
	CheckboxGroup cbg		= new CheckboxGroup();
	Checkbox cbUSD			= new Checkbox("U$-Dollar",cbg,false);
	Checkbox cbSF			= new Checkbox("Schweizer Franken",cbg,false);
	Checkbox cbJY			= new Checkbox("Japanische Yen",cbg,false);
	Checkbox cbBP			= new Checkbox("Britische Pfund",cbg,false);
	
	Panel pnlNorth	= new Panel(new FlowLayout());
	Panel pnlCenter = new Panel(new GridLayout(4,4));
	Panel pnlSouth	= new Panel(new FlowLayout());
	
	Panel pnlZeile1 = new Panel(new GridLayout(1,4));
	Panel pnlZeile2 = new Panel(new GridLayout(1,4));
	Panel pnlZeile3 = new Panel(new GridLayout(1,4));
	Panel pnlZeile4 = new Panel(new GridLayout(1,4));
	Panel pnlDummy	= new Panel();
	 
	//Ereingishändler aufruf
	//public MyActionListener myAL = new ActionLsitener(this);
	//public MyItemListener myIL   = new ItemListner(this);
	public MyWindowListener myWL   = new MyWindowListener();
	
	
	public WaehrungsumrechnerGUI()
	{	//Konstruktor
		super ("WaehrungsumrechnerGUI");
		
		//Labels formatieren
		lblUeberschrift.setFont(f1);
		lblVon.setFont(f2);
		lblNach.setFont(f2);			
		tfVon.setFont(f2);
		tfNach.setFont(f2);
		
		//Anordung der Panels
		pnlNorth.add(lblUeberschrift);
		
		pnlZeile1.add(lblVon);
		pnlZeile1.add(pnlDummy);
		pnlZeile1.add(pnlDummy);
		pnlZeile1.add(lblNach);
		
		pnlZeile2.add(tfVon);
		pnlZeile2.add(pnlDummy);
		pnlZeile2.add(pnlDummy);
		pnlZeile2.add(tfNach);
		
		pnlZeile3.add(cbUSD);
		pnlZeile3.add(cbSF);
		pnlZeile3.add(cbJY);
		pnlZeile3.add(cbBP);
		
		pnlZeile4.add(pnlDummy);
		pnlZeile4.add(pnlDummy);
		pnlZeile4.add(pnlDummy);
		pnlZeile4.add(pnlDummy);
		
		pnlSouth.add(btnUmrechnen);
		pnlSouth.add(btnRueckrechnen);
		pnlSouth.add(btnBeenden);
	
		pnlCenter.add(pnlZeile1);
		pnlCenter.add(pnlZeile2);
		pnlCenter.add(pnlZeile3);
		pnlCenter.add(pnlZeile4);
			
		add(pnlNorth, BorderLayout.NORTH);
		add(pnlCenter, BorderLayout.CENTER);
		add(pnlSouth, BorderLayout.SOUTH);
		
		//Ereignissteurung/ Listener hinzufügen
		addWindowListener(myWL);
		//cbgVon.addActionListener(myActionListener);
		//cbgNach.addActionListener(myActionListener);
				
		show();
		pack();
	}
}
-----------------------------------------------------------------
-----------------------------------------------------------------

public class WaehrungsumrechnerAnwendung
{
	public static void main(String args[])
	{
		WaehrungsumrechnerGUI fenster = new WaehrungsumrechnerGUI();
	}
}		
-----------------------------------------------------------------
-----------------------------------------------------------------

import java.awt.event.*;

public class MyWindowListener extends WindowAdapter 
{
	public void windowClosing (WindowEvent e) 
	{
	System.exit (0);
	}
}
-----------------------------------------------------------------
-----------------------------------------------------------------

import java.awt.*;
import java.awt.event.*;
import java.text.*;
public class MyActionListener implements ActionListener
{
	public WaehrungsumrechnerGUI f;
	public class MyActionListener (WaehrungsumrechnerGUI f)
	{
		this.f=f;
	}
	public void action Performed(ActionEvent e)
	{
		DecimalFormat df = new DecimalFormat("#,##0.0");
		double von=0;
		double nach=0;
		double UDS=0;
		double SF=0;
		double JY=0;
		double BP=0;
		Object obj;
		
		obj = e.getSource();
		
		if (obj == f.btnBeenden)
		System.exit(0);
		
		try 
		{
			von=Double.parseDouble(f.tfVon.getText().replace(',','.'));
			nach=Double.parseDoube(f.tfNAch.getText().replace(',','.'));
		
			if(obj==f.btnUmrechnen)
			{
				if (f.cbUSD.getState()==true)
				USD = von *1,2048;
				f.tfNach.setText(von);
					if (f.cbSF.getState()==true)
					SF = von * 1,5461;
					f.tfNach.setText(von);
						if (f.cbJY.getState()==true)
						JY = von * 137,220;
						f.tfNach.setText(von);
							if (f.cbBP.getState()==true)
							BP = von * 06815;
							f.tfNach.setText(von);
			}
		}
	}
}

L-ectron-X hat die Code-Tags eingefügt.
 

KSG9|sebastian

Top Contributor
WaerungsumrechnerGUI
Code:
MyActionListener al = new MyActionListener(this);
btnUmrechnen.addActionListener(al);
btnRueckrechnen.addActionListener(al);
btnBeenden.addActionListener(al);
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Oben