Advertisement
Guest User

ledMatrix

a guest
Oct 30th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class MyLEDMatrix {
  4. MyLEDLamp[][] ledmatrix;
  5. public MyLEDMatrix(int n){
  6. this.ledmatrix = new MyLEDLamp[n][n];
  7. int panjang = this.ledmatrix.length;
  8. int lebar = this.ledmatrix[0].length;
  9. for(int i = 0;i<panjang;i++){
  10. for(int j = 0;j<lebar;j++){
  11. this.ledmatrix[i][j]=new MyLEDLamp();
  12. }
  13. }
  14. }
  15.  
  16. public void setAll(boolean on){
  17. int panjang = this.ledmatrix.length;
  18. int lebar = this.ledmatrix[0].length;
  19. for(int i = 0;i<panjang;i++){
  20. for(int j = 0;j<lebar;j++){
  21. if(on == true){
  22. this.ledmatrix[i][j].setOn();}
  23. else{
  24. this.ledmatrix[i][j].setOff();
  25. }
  26. }
  27. }
  28. }
  29.  
  30. public String print(){
  31. int panjang = this.ledmatrix.length;
  32. int lebar = this.ledmatrix[0].length;
  33. String output = "";
  34. for(int i = 0;i<panjang;i++){
  35. for(int j = 0;j<lebar;j++){
  36. if(this.ledmatrix[i][j].getStatus() == true){
  37. output += "@";}
  38. else{
  39. output += " ";}
  40. }
  41. output += "\n";
  42. }
  43. return output;
  44. }
  45.  
  46. public void setTop(){
  47. String res = new String();
  48. int panjang = this.ledmatrix.length;
  49. int lebar = this.ledmatrix[0].length;
  50. for(int k = 0;k <= (panjang/2);k++){
  51. int l;
  52. int x;
  53. int y;
  54. for(l = 0;l<(lebar/2)-k;l++){
  55. this.ledmatrix[k][l].setOff();
  56. res=res+this.ledmatrix[k][l].print();
  57. }
  58. for(x = l;x<=(lebar/2)+k;x++){
  59. this.ledmatrix[k][l].setOn();
  60. res=res+this.ledmatrix[k][l].print();
  61. }
  62. for(y = x;y<(lebar/2);y++){
  63. this.ledmatrix[k][l].setOff();
  64. res=res+this.ledmatrix[k][l].print();
  65. }
  66. res=res+"\n";
  67. }
  68. System.out.println(res);
  69. }
  70.  
  71. public void setBottom(){
  72. int panjang = this.ledmatrix.length;
  73. int lebar = this.ledmatrix[0].length;
  74. String res = new String();
  75. for(int k = (panjang/2)+1;k < panjang;k++){
  76. int l;
  77. int i;
  78. for(l = 0;l<lebar;l++){
  79. this.ledmatrix[k][l].setOff();
  80. res=res+this.ledmatrix[k][l].print();
  81. }
  82. res=res+"\n";
  83. }
  84.  
  85. for(int i = (panjang/2)+1;i<panjang;i++){
  86. this.ledmatrix[i][(lebar/2)].setOn();
  87. res=res+this.ledmatrix[i][l].print();
  88. }
  89. }
  90.  
  91. public void setArrow(){
  92. this.setTop();
  93. this.setBottom();
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement