Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. import controlP5.*;//importation de la librairie
  2.  
  3. ControlP5 cp5;//déclaration d'une variable cp5 de la class ControlP5
  4.  
  5.  
  6. String numeroSecuString1;
  7. String numeroSecuString2;
  8. String numeroSecuString3;
  9. String cle;
  10.  
  11. int choix=0;
  12.  
  13. long numeroSecuLong1;
  14. long numeroSecuLong2;
  15. long numeroSecuLong3;
  16. long numeroSecuLong;
  17. long cleLong;
  18.  
  19.  
  20. void setup(){
  21.  
  22. cp5 = new ControlP5(this);//la variable cp5 est un objet de la class ControlP5
  23. size(300,100);//définition de la taille de l'IHM
  24. PFont font = createFont ("arial", 20);
  25.  
  26. cp5.addTextfield("1")
  27. .setPosition(5,5)
  28. .setSize(30,30)
  29. .setFont(font)
  30. .setFocus(true)
  31. .setColor(color(255,0,0))
  32. ;
  33.  
  34. cp5.addTextfield("23")
  35. .setPosition(40,5)
  36. .setSize(30,30)
  37. .setFont(font)
  38. .setFocus(true)
  39. .setColor(color(255,0,0))
  40. ;
  41.  
  42. cp5.addTextfield("45")
  43. .setPosition(75,5)
  44. .setSize(30,30)
  45. .setFont(font)
  46. .setFocus(true)
  47. .setColor(color(255,0,0))
  48. ;
  49.  
  50. cp5.addTextfield("67")
  51. .setPosition(110,5)
  52. .setSize(30,30)
  53. .setFont(font)
  54. .setFocus(true)
  55. .setColor(color(255,0,0))
  56. ;
  57.  
  58. cp5.addTextfield("8910")
  59. .setPosition(145,5)
  60. .setSize(40,30)
  61. .setFont(font)
  62. .setFocus(true)
  63. .setColor(color(255,0,0))
  64. ;
  65.  
  66. cp5.addTextfield("111213")
  67. .setPosition(190,5)
  68. .setSize(40,30)
  69. .setFont(font)
  70. .setFocus(true)
  71. .setColor(color(255,0,0))
  72. ;
  73.  
  74. cp5.addTextfield("cle")
  75. .setPosition(235,5)
  76. .setSize(40,30)
  77. .setFont(font)
  78. .setFocus(true)
  79. .setColor(color(255,0,0))
  80. ;
  81.  
  82. cp5.addButton("Effacer")
  83. .setPosition(5,50)
  84. .setValue(0)
  85. .updateSize()
  86. ;
  87.  
  88. cp5.addButton("Calcul")
  89. .setPosition(100,50)
  90. .setValue(0)
  91. .updateSize()
  92. ;
  93. }
  94.  
  95. void draw(){
  96.  
  97.  
  98. if (choix == 1) {
  99.  
  100. numeroSecuString1 = cp5.get(Textfield.class,"1").getText()+cp5.get(Textfield.class,"23").getText()+cp5.get(Textfield.class,"45").getText();
  101.  
  102. numeroSecuLong1 = int(numeroSecuString1);
  103.  
  104. }
  105.  
  106. if (choix == 2){
  107.  
  108. numeroSecuString2 = cp5.get(Textfield.class,"67").getText();
  109.  
  110.  
  111. if (cp5.get(Textfield.class,"67").getText().equals( "2A")){
  112.  
  113. numeroSecuString2 = "19";
  114.  
  115. }
  116.  
  117. else if (cp5.get(Textfield.class,"67").getText().equals("2B")){
  118.  
  119. numeroSecuString2 = "18";
  120.  
  121. }
  122.  
  123.  
  124.  
  125. numeroSecuLong2 = int (numeroSecuString2);
  126.  
  127.  
  128.  
  129.  
  130.  
  131. }
  132.  
  133. if (choix == 3){
  134.  
  135. numeroSecuString3 = cp5.get(Textfield.class,"8910").getText()+cp5.get(Textfield.class,"111213").getText();
  136.  
  137. numeroSecuLong3 = int(numeroSecuString3);
  138.  
  139.  
  140.  
  141. }
  142.  
  143.  
  144. numeroSecuLong = numeroSecuLong1*100000000+numeroSecuLong2*1000000+numeroSecuLong3;
  145. //println (numeroSecuLong);
  146.  
  147.  
  148. }
  149.  
  150.  
  151. void keyPressed(){
  152. if(mouseX>5 && mouseX<105 && mouseY>5 && mouseY<30){
  153. choix = 1;
  154. }
  155. if (mouseX>110 && mouseX<135 && mouseY>5 && mouseY<30){
  156. choix = 2;
  157. }
  158.  
  159. if (mouseX>140 && mouseX<225 && mouseY>5 && mouseY<30){
  160. choix = 3;
  161. }
  162.  
  163. }
  164.  
  165. public void controlEvent (ControlEvent theEvent){
  166. if (theEvent.getController().getName()=="Effacer"){
  167. choix=0;
  168. cp5.get(Textfield.class,"1").setText("");
  169. cp5.get(Textfield.class, "23").setText("");
  170. cp5.get(Textfield.class, "45").setText("");
  171. cp5.get(Textfield.class,"67").setText("");
  172. cp5.get(Textfield.class,"8910").setText("");
  173. cp5.get(Textfield.class,"111213").setText("");
  174. }
  175.  
  176. if (theEvent.getController().getName()=="Calcul"){
  177.  
  178. cleLong = 97-(numeroSecuLong%97);
  179. cle = str(cleLong);
  180. cp5.get(Textfield.class,"cle").setText(cle);
  181. }
  182.  
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement