• Liebe User, bitte beachtet folgendes Thema: Was im Forum passiert, bleibt im Forum! Danke!
  • Hallo Gemeinde! Das Problem leidet zurzeit unter technischen Problemen. Wir sind da dran, aber das Zeitkontingent ist begrenzt. In der Zwischenzeit dürfte den meisten aufgefallen sein, dass das Erstellen von Posts funktioniert, auch wenn das Forum erstmal eine Fehlermeldung wirft. Um unseren Löschaufwand zu minimieren, bitten wir euch darum, nicht mehrmals auf 'Post Reply' zu klicken, da das zur Mehrfachposts führt. Grußworte.

Taschenrechner in Java

Jazar

Guest
hat von euch zufällig jemand schon einmal nen taschenrechner in java programmiert? und könnte mir seinen quellcode stiften? :P
wäre wirklich sehr sehr nett : - )
 
Mitglied seit
08.12.2001
Beiträge
2.053
Reaktionen
0
wo ist das problem?
kannst du programmieren dann sollte es np sein?
kannstes nicht was willste dann damit?

verdacht: hausaufgabenforum? :elefant:
 

PvP-BABA-PvP

Guest
hier eine sehr sehr billige Version :cool:
das ist meine erste Version gewesen :D
dient eher als Wegweiser...
machs auf jedenfall alleine sonst bringt es nichts

import java.awt.*;
import java.awt.event.*;

class taschenrechner extends Frame
{

TextField tf1;
TextField tf2;
TextField tf3;
Button bPlus;
Button bMinus;
Button bMal;
Button bTeilen;

public taschenrechner (String title)
{

this.setLayout(null);
this.setVisible(true);
this.setSize(800,600);
this.setTitle("Taschenrechner");


tf1=new TextField();
tf1.setBounds(150,80,200,25);
this.add(tf1);
tf2=new TextField();
tf2.setBounds(150,160,200,25);
this.add(tf2);
tf3=new TextField();
tf3.setBounds(150,240,200,25);
this.add(tf3);


bPlus = new Button();
bPlus.setLabel("+");
bPlus.setBounds(450,200,50,25);
bPlus.setFont(new Font("Arial", Font.PLAIN,10));
bPlus.setBackground(new Color(0xEEEFFF));
this.add(bPlus);
bPlus.addActionListener(new Aktion());


bMinus = new Button();
bMinus.setLabel("-");
bMinus.setBounds(450,250,50,25);
bMinus.setFont(new Font("Arial", Font.PLAIN,10));
bMinus.setBackground(new Color(0xEEEFFF));
this.add(bMinus);
bMinus.addActionListener(new Aktion());



bMal = new Button();
bMal.setLabel("*");
bMal.setBounds(550,200,50,25);
bMal.setFont(new Font("Arial", Font.PLAIN,10));
bMal.setBackground(new Color(0xEEEFFF));
this.add(bMal);
bMal.addActionListener(new Aktion());


bTeilen = new Button();
bTeilen.setLabel("/");
bTeilen.setBounds(550,250,50,25);
bTeilen.setFont(new Font("Arial", Font.PLAIN,10));
bTeilen.setBackground(new Color(0xEEEFFF));
this.add(bTeilen);
bTeilen.addActionListener(new Aktion());
}


//Filter
class Aktion implements ActionListener
{
public void actionPerformed(ActionEvent a)
{

Object object = a.getSource();

if (object==bPlus)
plus(a);

if (object==bMinus)
minus(a);

if (object==bMal)
mal(a);

if (object==bTeilen)
teilen(a);

}
}


//Plus Methode
void plus(ActionEvent ev)
{
String Stf1 = tf1.getText();
String Stf2 = tf2.getText();

Float f1 = new Float(Stf1);
Float f2 = new Float(Stf2);


float ff1 = f1.floatValue();
float ff2 = f2.floatValue();


float summe = (ff1+ff2);
tf3.setText(String.valueOf(summe));
}

//Minus Methode
void minus(ActionEvent ev)
{
String Stf1 = tf1.getText();
String Stf2 = tf2.getText();

Float f1 = new Float(Stf1);
Float f2 = new Float(Stf2);


float ff1 = f1.floatValue();
float ff2 = f2.floatValue();


float summe = (ff1-ff2);
tf3.setText(String.valueOf(summe));
}


//Mal Methode
void mal(ActionEvent ev)
{
String Stf1 = tf1.getText();
String Stf2 = tf2.getText();

Float f1 = new Float(Stf1);
Float f2 = new Float(Stf2);


float ff1 = f1.floatValue();
float ff2 = f2.floatValue();


float summe = (ff1*ff2);
tf3.setText(String.valueOf(summe));
}



//Teilen Methode
void teilen(ActionEvent ev)
{
String Stf1 = tf1.getText();
String Stf2 = tf2.getText();

Float f1 = new Float(Stf1);
Float f2 = new Float(Stf2);


float ff1 = f1.floatValue();
float ff2 = f2.floatValue();


float summe = (ff1/ff2);
tf3.setText(String.valueOf(summe));

//tf3.setText(String.valueOf(((new Float (tf1.getText())).floatValue())/((new Float (tf2.getText())).floatValue())));
}






public static void main (String args[])
{
taschenrechner a= new taschenrechner("taschenrechner");
}




}
 
Oben