Advertisement
tegusta

kimmi

May 5th, 2013
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import javax.swing.Action;
  3. import javax.swing.JButton;
  4. import javax.swing.JLabel;
  5. import javax.swing.JPanel;
  6. import java.awt.GridLayout;
  7. import javax.swing.JOptionPane;
  8. import java.awt.TextField;
  9. import java.awt.event.KeyAdapter;
  10. import java.awt.event.KeyEvent;
  11. import java.awt.event.MouseAdapter;
  12. import java.awt.event.MouseEvent;
  13.  
  14. public class Calcolatrice extends JFrame{
  15.  
  16. private JButton[] numeri = new JButton[12];
  17. private JButton[] operatori = new JButton[4];
  18. private TextField casellaDiCalcolo = new TextField();
  19. private String stampa = "";
  20.  
  21.  
  22. public Calcolatrice(){
  23. setVisible(true);
  24. setSize(500,500);
  25. setLayout(new GridLayout(3,1));
  26. add(casellaDiCalcolo);
  27. add(new TabNumeri());
  28. add(new TabOperatori());
  29. addMouseListener(new AscoltatoreMouse());
  30. setDefaultCloseOperation(EXIT_ON_CLOSE);
  31. }//Calcolatrice
  32.  
  33.  
  34. class AscoltatoreMouse extends MouseAdapter{
  35. public void mousePressed(MouseEvent e){
  36. JButton bottoneMagico;
  37. if(e.getComponent() instanceof JButton) {
  38. bottoneMagico = (JButton)e.getComponent();
  39. casellaDiCalcolo.setText(bottoneMagico.getText());
  40. }//if
  41. }//mousePressed
  42. }//AscoltatoreMouse
  43.  
  44.  
  45. class TabNumeri extends JPanel{
  46. public TabNumeri(){
  47. setLayout(new GridLayout(4,3));
  48. for(int i=9;i>-1;i--){
  49. numeri[i] = new JButton(""+i);
  50. add(numeri[i]);
  51. }//for
  52. numeri[10] = new JButton("=");
  53. add(numeri[10]);
  54. numeri[11] = new JButton(".");
  55. add(numeri[11]);
  56. }//TabNumeri
  57. }//TabNumeri
  58.  
  59. class TabOperatori extends JPanel{
  60. public TabOperatori(){
  61. setLayout(new GridLayout(1,4));
  62. operatori[0] = new JButton("/");
  63. add(operatori[0]);
  64. operatori[1] = new JButton("*");
  65. add(operatori[1]);
  66. operatori[2] = new JButton("-");
  67. add(operatori[2]);
  68. operatori[3] = new JButton("+");
  69. add(operatori[3]);
  70. }//TabOperatori
  71. }//TabOperatori
  72.  
  73. }//Calcolatrice
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement