Advertisement
Guest User

ciao

a guest
May 23rd, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. package valutaEspressione;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.GridLayout;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import javax.swing.JLabel;
  10. import javax.swing.JPanel;
  11. import javax.swing.JTextField;
  12.  
  13.  
  14. public class Calcolatrice { //DA COMPLETARE
  15. private static class FrontEnd extends JFrame implements ActionListener{
  16. private static final long serialVersionUID = 1L;
  17. JPanel q,p0,k,p1,p2,j = new JPanel();
  18. JTextField jtf;
  19. JButton zero,uno,due,tre,quattro,cinque,sei,sette,otto,nove,buh,history,
  20. diviso,per,piu,meno,pow,uguale,mod,punto,pa,pc,back,del = new JButton("0");
  21. public FrontEnd(){
  22. setTitle("Calcolatrice");
  23. setSize(500,250);
  24. setLocation(500,200);
  25. //...
  26. JPanel q=new JPanel();
  27. JTextField jtf=new JTextField("",35);
  28. jtf.addActionListener(this);
  29. q.add(jtf);
  30. JPanel p0=new JPanel();
  31. p0.setLayout( new GridLayout(2,1,5,5));
  32. p0.add(q,BorderLayout.NORTH);
  33. JPanel k=new JPanel();
  34. k.setLayout( new GridLayout(1,2,5,5));
  35. //...
  36. JPanel p1=new JPanel();
  37. p1.setLayout( new GridLayout(3,6,5,5) );
  38. JPanel p2=new JPanel();
  39. p2.setLayout( new GridLayout(1,2,5,5));
  40. JPanel j=new JPanel();
  41. j.setLayout(new GridLayout(1,3,5,5));
  42. //JButton buh= new JButton("?");
  43. //buh.addActionListener(this);
  44. //JButton history= new JButton("HISTORY");
  45. //history.addActionListener(this);
  46. //JButton sette=new JButton("7");
  47. //sette.addActionListener(this);
  48. //JButton otto=new JButton("8");
  49. //otto.addActionListener(this);
  50. //JButton nove=new JButton("9");
  51. //nove.addActionListener(this);
  52. //JButton diviso=new JButton("/");
  53. //diviso.addActionListener(this);
  54. //JButton quattro=new JButton("4");
  55. //quattro.addActionListener(this);
  56. //JButton cinque=new JButton("5");
  57. //cinque.addActionListener(this);
  58. //JButton sei=new JButton("6");
  59. //sei.addActionListener(this);
  60. //JButton per=new JButton("X");
  61. //per.addActionListener(this);
  62. //JButton uno=new JButton("1");
  63. //uno.addActionListener(this);
  64. //JButton due=new JButton("2");
  65. //due.addActionListener(this);
  66. //JButton tre=new JButton("3");
  67. //tre.addActionListener(this);
  68. //JButton meno=new JButton("-");
  69. //meno.addActionListener(this);
  70. //JButton zero=new JButton("0");
  71. //zero.addActionListener(this);
  72. //JButton punto=new JButton(",");
  73. //punto.addActionListener(this);
  74. //JButton uguale=new JButton("=");
  75. //uguale.addActionListener(this);
  76. //JButton piu=new JButton("+");
  77. //piu.addActionListener(this);
  78. //JButton back=new JButton("BACK");
  79. //back.addActionListener(this);
  80. //JButton del= new JButton("CLEAR");
  81. //del.addActionListener(this);
  82. //JButton pa= new JButton("(");
  83. //pa.addActionListener(this);
  84. //JButton pc=new JButton(")");
  85. //pc.addActionListener(this);
  86. //JButton mod=new JButton("%");
  87. //mod.addActionListener(this);
  88. //JButton pow=new JButton("EXP");
  89. //pow.addActionListener(this);
  90.  
  91. //...
  92. j.add(zero); j.add(punto); j.add(mod);
  93. k.add(history); k.add(buh);
  94. p1.add(sette); p1.add(otto); p1.add(nove); p1.add(diviso); p1.add(back); p1.add(del);
  95. p1.add(quattro); p1.add(cinque); p1.add(sei); p1.add(per); p1.add(pa); p1.add(pc);
  96. p1.add(uno); p1.add(due); p1.add(tre); p1.add(meno); p1.add(piu); p1.add(pow);
  97. //...
  98. p0.add(k,BorderLayout.SOUTH);
  99. p2.add(j,BorderLayout.WEST);
  100. p2.add(uguale,BorderLayout.EAST);
  101. add( p0, BorderLayout.NORTH ); //aggiunta del pannello p alla JFrame
  102. add( p1, BorderLayout.CENTER);
  103. add( p2, BorderLayout.SOUTH);
  104. zero.addActionListener(this);
  105. }//costruttore
  106. public void actionPerformed(ActionEvent evt){
  107. if(evt.getSource()==zero) jtf.setText(jtf.getText()+"0");
  108. else if(evt.getSource()==uno) jtf.setText(jtf.getText()+"1");
  109. else if(evt.getSource()==due) jtf.setText(jtf.getText()+"2");
  110. else if(evt.getSource()==tre) jtf.setText(jtf.getText()+"3");
  111.  
  112. }
  113. }//FrontEnd
  114. public static void main( String[] args ){
  115. FrontEnd fe=new FrontEnd();
  116. fe.setVisible(true);
  117.  
  118.  
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement