sabato 7 febbraio 2009

Calcolatrice

Salve prof! Io ci ho provato a fare la calcolatrice...però non è che sia poi così ad interfaccia grafica.
Praticamente consiste nel selezionare l'operazione da eseguire ma non con i bottoni...se poi lunedì tanto la riguardiamo la modifico così aggiorno questo post...a presto!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class Calcolatrice {
private JFrame f=new JFrame ("Calcolatrice");
private Pannello p= new Pannello();


public Calcolatrice(){
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(500,500);
f.add(p);
f.setVisible(true);

}



public class Pannello extends JPanel{
public void paintComponent(Graphics g){

}

}
public static void main(String args[]){


while(choice=0){
System.out.println("");
System.out.println("1-Addizione");
System.out.println("2-Sottrazione");
System.out.println("3-Divisione");
System.out.println("4-Moltiplicazione");
System.out.println("0-Esci");
System.out.println("");

c=JOptionPane.showInputDialog("Scegli: ");
choice=Integer.parseInt(c);
if (choice=0 && choice<=4) {
firstnum=JOptionPane.showInputDialog("Immetti primo numero: ");
secondnum=JOptionPane.showInputDialog("Immetti secondo numero: ");
first=Integer.parseInt(firstnum);
second=Integer.parseInt(secondnum);
}

if(choice==1)
{
tot=first+second;
System.out.println("Il totale e': "+tot);
}
else
if(choice==2) {
tot=first-second;
System.out.println("Il totale e': "+tot);
}
else
if(choice==3) {
tot=first/second;
System.out.println("Il totale e': "+tot);
}
else
if(choice==4) {
tot=first*second;
System.out.println("Il totale e': "+tot);
}
else
if(choice==0) {
System.exit(0);
}
}
}//chiude il while
}