CHAPTER 5 IMPLEMENTATION AND TESTING

  

CHAPTER 5

IMPLEMENTATION AND TESTING

The first windows will be 2 button the Gui view the code :

  1. public static void main (String[] args){

  2. JFrame frame = new JFrame("Test"); 3. frame.setVisible(true); 4. frame.setSize(500,200); 5. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  6. JPanel panel = new JPanel(); 7. frame.add(panel);

  8. JButton button = new JButton("read"); 9. panel.add(button); 10. button.addActionListener (new Action1());

  11. JButton button2 = new JButton("create"); 12. panel.add(button2); 13. button2.addActionListener (new Action2()); 14. } 15. static class Action1 implements ActionListener { 16. public void actionPerformed (ActionEvent e) {

  17. Pixel baru = new Pixel(); 18. } 19. } 20. static class Action2 implements ActionListener { 21. public void actionPerformed (ActionEvent e) { 22. ascii buka= new ascii(); 23. 24. } 25. } 26. }

  The code from the 2nd line until 14 is the Gui create the button and the

window that popup. The 15th line until the 24th line is the creating action when

the button is clicked.

  This the code window that pop up for inputting data:

  1. String str=JOptionPane.showInputDialog("input yang akan dirubah"); 2. char[] arrCharStr = str.toCharArray(); 3. for (char ch : arrCharStr){ 4. multi[test]=(int)ch;test++ 5. }

  In line 1, used to create the joption panel window, in line 2 about the string arraylist and change into array. In line 3,the header of the windows and

line 4 and 5 for the array that grap the data inputed. And the test is for the

checking the input length. After that make the code for checking data.

  

This the code for the checking the file for inputed of data 16 lenght

less or more:

  1. if(test==0) 2. {System.out.println("data tidak sesuai"); 3. } 4. else if(test<17) 5. {

  Line 1 until 5 is the code for checking the inputed data 16 lenght less than 16 or more than 16. This code below is for creating template the null value:

  1. for(int datas=0;datas<32;datas=datas+4) 2. { 3. for(int dataz=0;dataz<32;dataz=dataz+4) 4. { 5. matrix[datas][dataz]=1; 6. matrix[datas][dataz+1]=1; 7. matrix[datas+1][dataz]=1; 8. matrix[datas+1][dataz+1]=0; 9. matrix[datas][dataz+2]=0; 10. matrix[datas][dataz+3]=0; 11. matrix[datas+1][dataz+2]=1; 12. matrix[datas+1][dataz+3]=0; 13. matrix[datas+2][dataz]=0; 14. matrix[datas+2][dataz+1]=1; 15. matrix[datas+3][dataz]=0; 16. matrix[datas+3][dataz+1]=0; 17. matrix[datas+2][dataz+2]=1; 18. matrix[datas+2][dataz+3]=0; 19. matrix[datas+3][dataz+2]=1; 20. matrix[datas+3][dataz+3]=1; 21. } 22. } Line 1 until 22 for coding template.

  1. for (int i=0;i<test;i++) 2. { 3. int look=multi[i]/7; 4. int modul=multi[i]%7; 5. int hitung1=multi[i]-modul; 6. int nilaia=hitung1/7-(3*beda); 7. for(int j=0;j<7;j++) 8. { 9. nilaidesimal[i][j]=nilaia+(j*beda); 10. } That code above is for the calculate ascii number become arithmatic array.

  

Line 3 is for looking divided value. Line 4 for modulo value. Line 5 for searching

the value of total Sn. Line 6 for A value, line 7 until 10 for looping arithmatic

value.

  1. for(int k=0;k<test;k++) 2. { int tol=0; 3. for(int l=0;l<14;l=l+2) 4. { 5. nilaiokta[i][l]=nilaidesimal[i][tol]/8; 6. nilaiokta[i][l+1]=nilaidesimal[i][tol]%8; 7. tol++; 8. } 9. nilaiokta[i][14]=0; 10. nilaiokta[i][15]=multi[i]%7;

  The code above is the calculated for the converted from the arithmatic

array decimal to okta and divided into 2 number for each decimal. Line 9-10 to

inputed eight value.

  The code below is the code for converting by looping from the okta value to the template image:

  1. int bug=0;int hurufz=0; 2. for(int x=0;x<16;x++) 3. { 4. int count2=0; 5. for(int datas=0;datas<8;datas=datas+2) 6. { 7. for(int dataz=0;dataz<8;dataz=dataz+2) 8. { 9. if(nilaiokta[x][count2]==0) 10. {

  11. matrix[bug+datas][hurufz+dataz]=0; 12. matrix[bug+datas][hurufz+dataz+1]=1; 13. matrix[bug+datas+1][hurufz+dataz]=0; 14. matrix[bug+datas+1][hurufz+dataz+1]=1; 15. } 16. else if(nilaiokta[x][count2]==1) 17. { 18. matrix[bug+datas][hurufz+dataz]=1; 19. matrix[bug+datas][hurufz+dataz+1]=1; 20. matrix[bug+datas+1][hurufz+dataz]=0; 21. matrix[bug+datas+1][hurufz+dataz+1]=0; 22. } 23. else if(nilaiokta[x][count2]==2) 24. { 25. matrix[bug+datas][hurufz+dataz]=1; 26. matrix[bug+datas][hurufz+dataz+1]=0; 27. matrix[bug+datas+1][hurufz+dataz]=1; 28. matrix[bug+datas+1][hurufz+dataz+1]=0; 29. } 30. else if(nilaiokta[x][count2]==3) 31. { 32. matrix[bug+datas][hurufz+dataz]=0; 33. matrix[bug+datas][hurufz+dataz+1]=1; 34. matrix[bug+datas+1][hurufz+dataz]=1; 35. matrix[bug+datas+1][hurufz+dataz+1]=0; 36. } 37. else if(nilaiokta[x][count2]==4) 38. { 39. matrix[bug+datas][hurufz+dataz]=0; 40. matrix[bug+datas][hurufz+dataz+1]=0; 41. matrix[bug+datas+1][hurufz+dataz]=1; 42. matrix[bug+datas+1][hurufz+dataz+1]=1; 43. } 44. else if(nilaiokta[x][count2]==5) 45. { 46. matrix[bug+datas][hurufz+dataz]=1; 47. matrix[bug+datas][hurufz+dataz+1]=0; 48. matrix[bug+datas+1][hurufz+dataz]=0; 49. matrix[bug+datas+1][hurufz+dataz+1]=1; 50. } 51. else if(nilaiokta[x][count2]==6) 52. { 53. matrix[bug+datas][hurufz+dataz]=0; 54. matrix[bug+datas][hurufz+dataz+1]=1; 55. matrix[bug+datas+1][hurufz+dataz]=1; 56. matrix[bug+datas+1][hurufz+dataz+1]=1; 57. } 58. else if(nilaiokta[x][count2]==7) 59. { 60. matrix[bug+datas][hurufz+dataz]=0; 61. matrix[bug+datas][hurufz+dataz+1]=0; 62. matrix[bug+datas+1][hurufz+dataz]=0; 63. matrix[bug+datas+1][hurufz+dataz+1]=1; 64. }

  65. count2++; 66. } 67. } 68. hurufz=hurufz+8; 69. if((x+1)%4==0){bug=bug+8;hurufz=0;} 70. }

  Line 1-70 for looping octa value transform into image with library from QR code. The code for creating image as follows:

  1. try 2. { 3. //** creating image **

  

4. BufferedImage gambarza = new BufferedImage(320,320,BufferedImage.TYPE_INT_RGB);

  5. for(int gambarz=0;gambarz<32;gambarz++) 6. { 7. for(int gambarz2=0;gambarz2<32;gambarz2++) 8. { 9. for(int xx=0;xx<10;xx++) 10. {for(int yy=0;yy<10;yy++) 11. { 12. if(matrix[gambarz][gambarz2]==0) 13. {

  14. Color newColor= new Color(255,255,255); 16. } 17. else if(matrix[gambarz][gambarz2]==1) 18. {

  19. Color newColor= new Color(0,0,0);

  20. gambarza.setRGB((gambarz2*10+xx),(gambarz*10+yy),newColor.getRGB());

  21. } 22. } 23. } 24. } 25. }

  Line 4 until 25 to make image 32 x32 change bigger 10 times from template and transform into 320 x 320. The code for save as follows:

  1. JFileChooser fileChooser = new JFileChooser();

  2. if(fileChooser.showSaveDialog(null)==JFileChooser.APPROVE_OPTION) {

  3. File datazes = fileChooser.getSelectedFile();

  4. ImageIO.write(gambarza,"jpg",datazes) 5. } Line 1-5 is the code for save file as.

  The code for open file: (how to read, the second section)

  1. JFileChooser dat = new JFileChooser(); 2. int result = dat.showOpenDialog(null); 3. if (result == JFileChooser.APPROVE_OPTION) 4. {

  5. File input = dat.getSelectedFile();

  Line 1 until 5 is the code for open file or read the image that has been save

as. The code for inputing the open image to template for easy reverence reading

image as follows:

  1. image = ImageIO.read(input); 2. width = image.getWidth(); 3. height = image.getHeight(); 4. int countz = 0; 5. int count = 0; 6. int change=width/32; 7. for(int i=0;i<height;i++) 8. { 9. for(int j=0;j<width;j++) 10. { 11. count++;

  12. Color c = new Color(image.getRGB(j,i)); 13. int rd = (c.getRed()); 14. int gn =(c.getGreen()); 15. int bl = (c.getBlue()); 17. if(avgz<128) 18. { 19. nilaiz=1; 20. } 21. else 22. { 23. nilaiz=0; 24. } 25. multi[i][j]=nilaiz; 26. } 27. }

  Line 1-27 is the code for entering picture or image into template and

change into binary (0 and 1). The code for take some point for the reverence the

reading image as follows:

  1. int loncat1=0; 2. for(int k=0;k<32;k++) 3. { 4. int loncat2=0; 5. for(int n=0;n<32;n++) 6. { 7. multiz[k][n]=multi[loncat1][loncat2]; 8. loncat2=loncat2+change;

  9. } 10. loncat1=loncat1+change; 11. } Line 1-11 for rescale from certain point and change into new template.

  Meanwhile, the code for searcing the value pattern in image:

  1. for(int z=0;z<32;z=z+2) 2. { 3. int jk=0; 4. for(int x=0;x<32;x=x+2) 5. {countz++; 6. if(multiz[z][x]==0 && multiz[z+1][x]==0 && multiz[z] [x+1]==1 && multiz[z+1][x+1]==1) 7. { kultix[po][jk]=0;} 8. else if(multiz[z][x]==1 && multiz[z+1][x]==0 && multiz[z][x+1]==1 && multiz[z+1][x+1]==0) 9. { kultix[po][jk]=1;} else if(multiz[z][x]==1 && multiz[z+1][x]==1 && multiz[z][x+1]==0 && multiz[z+1][x+1]==0) 10. { kultix[po][jk]=2;} 11. else if(multiz[z][x]==0 && multiz[z+1][x]==1 && multiz[z][x+1]==1 && multiz[z+1][x+1]==0) 12. { kultix[po][jk]=3;} 13. else if(multiz[z][x]==0 && multiz[z+1][x]==1 && multiz[z][x+1]==0 && multiz[z+1][x+1]==1) 14. { kultix[po][jk]=4;} 15. else if(multiz[z][x]==1 && multiz[z+1][x]==0 && multiz[z][x+1]==0 && multiz[z+1][x+1]==1) 16. { kultix[po][jk]=5;} 17. else if(multiz[z][x]==0 && multiz[z+1][x]==1 && multiz[z][x+1]==1 && multiz[z+1][x+1]==1) 18. { kultix[po][jk]=6;} 19. else if(multiz[z][x]==0 && multiz[z+1][x]==0 && multiz[z][x+1]==0 && multiz[z+1][x+1]==1) 20. { kultix[po][jk]=7;} 21. else 22. {kultix[po][jk]=0;} 23. jk++; 24. } 25. po++; 26. }

  Line 1-26 is the code for check the pattern and change into value in new template.

  The code for counting sum of the value arithmatic array from the number

converted to decimal and sum then the value of ascii converted to character as

follows:

  1. for(int op=0;op<16;op=op+4) 2. { 3. for(int x=0;x<16;x=x+4) 4. { multix[o]=0; 5. for(int kalo=0;kalo<4;kalo=kalo+2) 6. { 7. for(int kalo2=0;kalo2<4;kalo2++) 8. {

  9. multix[o]=multix[o]+(kultix[op+kalo2][x+kalo]*8)+kultix[op+kalo2][x+kalo+1];

  10. } 11. } 12. if(multix[o]==0){} 13. else{ 14. char ax= (char)multix[o];

  15. System.out.print("" +ax);} 16. o++; 17. } 18. }

  Line 1-18 for change or convert the number of arithmatic array into decimal. In testing programmes, the output after make QR Code with own pattern, the first steps is how to make the main menu with 2 button: Illustration 5.1: main menu with 2 option button

  After that make input data: Illustration 5.2: input data

  For example input INFORMATIKA: Illustration 5.3: Example input data

  INFORMATIKA After that save as: Save as INFORMATIKA: Illustration 5.5: Save as INFORMATIKA

  After that image for Informatka appear: Illustration 5.6: Output image

  

open file try choose informatika file to check the data :

output the data that saved in image: Illustration 5.7: INFORMATKA save as output Illustration 5.8: output file