Jump to content

[Java] Calculator

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Maarek

Maarek

    Newbie

  • Members
  • Pip
  • 1 posts
Hello all!
im new to this forum but im trying to make an simple Calculator in Java. Can someone please help me with it, cause im stuck of it.

[ATTACH]3104[/ATTACH]
It's just a Simple Java calculator.. but the buttons doesnt work :(

#2
safarisoul

safarisoul

    Newbie

  • Members
  • Pip
  • 1 posts
-_-!!! where is your listener?

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
You'll need to add some listeners like:
public class MultiListener ... implements ActionListener {
    ...
    //where initialization occurs:
        button1.addActionListener(this);
        button2.addActionListener(this);

        button2.addActionListener(new Eavesdropper(bottomTextArea));
    }

    public void actionPerformed(ActionEvent e) {
        topTextArea.append(e.getActionCommand() + newline);
    }
}

or
button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textField.setText("Pressed Me");
				for (int i=Integer.MIN_VALUE/8;i<Integer.MAX_VALUE/8;i++);
			}});


#4
lynx

lynx

    Newbie

  • Members
  • Pip
  • 7 posts
import java.util.Scanner;
public class Calc{
public static void main (String []args){

int numero1;
int numero2;
double resultado;
char operador;
String letra;


Scanner Input=new Scanner (System.in);


System.out.print("Introduza o 1º valor:");
numero1=Input.nextInt();
System.out.print("Introduza o 2º valor:");
numero2=Input.nextInt();
System.out.print("Introduza o operador aritmético:");
letra=Input.next();
operador=letra.charAt(0); 

switch (operador){

case '+' : numero1 + numero2 = resultado; break;
case '-' : resultado=numero1-numero2;break; 
case '*' : resultado=numero1*numero2;break; 
case '/' : resultado=numero1/numero2;break; 

System.out.println(numero1 + operador + numero2 + " = "+ resultado  );


	   } 
	
   }
	
}