Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. package cortexM0;
  2.  
  3. import java.util.Observable;
  4. import java.util.Observer;
  5. import java.util.Scanner;
  6.  
  7. /**
  8. * Write a description of class KonsolowaPrezentacjaSysTick here.
  9. *
  10. * @author (your name)
  11. * @version (a version number or a date)
  12. */
  13. public class CortexM0Console implements Observer {
  14. // instance variables - replace the example below with your own
  15. private CortexM0SysTick myCounter;
  16.  
  17. /**
  18. * Constructor for objects of class KonsolowaPrezentacjaSysTick
  19. */
  20. public CortexM0Console() {
  21. myCounter = new CortexM0SysTick();
  22. myCounter.addObserver(this);
  23. counterShow();
  24. }
  25.  
  26. /*
  27. * exception handler
  28. */
  29. public void update(Observable subject, Object arg) {
  30. display("interrupt!!");
  31. }
  32.  
  33. public void counterShow() {
  34. Scanner in = new Scanner(System.in);
  35. display("Pokaz działania licznika. Wciśnij odpowiedni klawisz, aby wybrać akcję:\n"
  36. + "[1] Wyświetl stan licznika.\n" + "[2] Impuls.\n" + "[3] Włącz licznik.\n"
  37. + "[4] Włącz przerwania.\n"
  38. + "[5] Wyjdz konsoli.\n\n");
  39. while (true) {
  40. int choose = in.nextInt();
  41. switch (choose) {
  42.  
  43. case 1:
  44. display("Stan licznika:\n" + myCounter);
  45. break;
  46. case 2:
  47. myCounter.impuls();
  48. display("Impuls wysłany.");
  49. break;
  50. case 3:
  51. myCounter.setEnableFlag(true);
  52. display("Licznik włączony.");
  53. break;
  54. case 5:
  55. System.exit(0);
  56. case 4:
  57. myCounter.setTickingFlag(true);
  58. break;
  59. default :
  60. display("Zły klawisz.");
  61. }
  62. }
  63. }
  64.  
  65. public void display(String msg) {
  66. System.out.println(msg);
  67. }
  68.  
  69. /**************************
  70. * main (klasa wiodąca)
  71. */
  72. public static void main(String[] args) {
  73. new CortexM0Console();
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement