Advertisement
Guest User

Tes

a guest
Nov 25th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. /**
  2. * @(#)GUI.java
  3. *
  4. *
  5. * @Filbert Nicholas
  6. * @version 1.00 2014/7/9
  7. */
  8.  
  9. import java.io.*;
  10. import java.awt.*;
  11. import java.awt.event.*;
  12. import javax.swing.*;
  13. //import javax.swing.filechooser.*;
  14.  
  15. public class GUI extends JFrame implements ActionListener {
  16.  
  17. private Label lbl;
  18. public TextField tf;
  19. private Button bwsbtn, idbtn;
  20. public String path;
  21. File selectedFile;
  22.  
  23. // Constructor to setup GUI components and event handling
  24. public GUI() {
  25. setLayout(null);
  26. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  27. setTitle("File Fragment Identifier");
  28. setSize(300,150);
  29. setVisible(true);
  30. setResizable(false);
  31.  
  32. lbl = new Label("Input File Fragment");
  33. add(lbl);
  34. lbl.setBounds(55,5,200,25);
  35. lbl.setFont(new Font("Arial", Font.PLAIN, 20));
  36.  
  37. tf = new TextField("");
  38. add(tf);
  39. tf.setBounds(25,35,225,25);
  40.  
  41. bwsbtn = new Button("Browse");
  42. add(bwsbtn);
  43. bwsbtn.addActionListener(this);
  44. bwsbtn.setBounds(25,70,110,35);
  45.  
  46. idbtn = new Button("Identify");
  47. add(idbtn);
  48. idbtn.addActionListener(this);
  49. idbtn.setBounds(155,70,110,35);
  50.  
  51. }
  52.  
  53. public void actionPerformed(ActionEvent e){
  54. //Handle browse event
  55. try{
  56. if(e.getSource() == bwsbtn){
  57. JFileChooser fc = new JFileChooser();
  58. fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
  59. int returnVal = fc.showOpenDialog(GUI.this);
  60. if(returnVal == JFileChooser.APPROVE_OPTION){
  61. selectedFile = fc.getSelectedFile();
  62. path = selectedFile.getAbsolutePath();
  63. tf.setText(selectedFile + ".");
  64. }else{
  65. JOptionPane.showMessageDialog(null, "Please choose a file.");
  66. }
  67. }
  68.  
  69. //Handle identify button
  70. if(e.getSource() == idbtn){
  71. if(tf.getText().equals("")){
  72. JOptionPane.showMessageDialog(null,"Please select fragment file.");
  73. }else{
  74.  
  75. try{
  76.  
  77. long startpx = 0;
  78. long startpy = 0;
  79. long readSize = 2048;
  80. String temp = "";
  81.  
  82. while(true){
  83. StringResult sr = new StringResult();
  84.  
  85. String x = LCSf.readFile("D:\\TA\\Skripsi\\PDF.txt", startpx, readSize);
  86. String y = LCSf.GenStr2(selectedFile, startpy, readSize);
  87. temp = temp + sr.Compare(x, y);
  88.  
  89. if(sr.posx == -1 && sr.posy == -1){
  90. startpx = startpx + readSize;
  91. startpy = startpy + readSize;
  92. }
  93.  
  94. else{
  95. startpx += sr.posx + 1;
  96. startpy += sr.posy + 1;
  97. }
  98.  
  99. System.out.println(sr.posx);
  100.  
  101. if(startpx > "D:\\TA\\Skripsi\\PDF.txt".length()){
  102. System.out.println("LCS: " + temp);
  103. System.out.println("Length: " + temp.length());
  104. break;
  105. }
  106. if(startpy > selectedFile.length()){
  107. System.out.println("LCS: " + temp);
  108. System.out.println("Length: " + temp.length());
  109. break;
  110. }
  111. }
  112.  
  113. }finally{
  114. }
  115. }
  116. }
  117. }catch(IOException f){
  118.  
  119. }
  120. finally{
  121.  
  122. }
  123. }
  124.  
  125. public static void main (String[] args){
  126. GUI app = new GUI();
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement