Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package compareframetest;
  7.  
  8. import java.io.File;
  9. import java.io.FileInputStream;
  10. import java.io.FileNotFoundException;
  11. import java.io.IOException;
  12. import java.util.logging.Level;
  13. import java.util.logging.Logger;
  14. import javax.swing.table.DefaultTableModel;
  15. import javax.swing.table.TableModel;
  16.  
  17. /**
  18. *
  19. * @author tony
  20. */
  21. public class NewJFrame extends javax.swing.JFrame {
  22.  
  23. /**
  24. * Creates new form NewJFrame
  25. */
  26. public NewJFrame() throws IOException, InterruptedException {
  27. initComponents();
  28. this.setLocationRelativeTo(null);
  29. funStuff();
  30. }
  31.  
  32. final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
  33.  
  34. public static String bytesToHex(byte[] bytes) {
  35. char[] hexChars = new char[bytes.length * 2];
  36. for (int j = 0; j < bytes.length; j++) {
  37. int v = bytes[j] & 0xFF;
  38. hexChars[j * 2] = hexArray[v >>> 4];
  39. hexChars[j * 2 + 1] = hexArray[v & 0x0F];
  40. }
  41. String hexString = new String(hexChars);
  42. String[] split = hexString.split("(?<=\\G.{2})");
  43. return hexString;
  44. }
  45.  
  46. private void funStuff() throws FileNotFoundException, IOException {
  47.  
  48. FileInputStream diskIn = new FileInputStream(new File("c:\\testing\\butts"));
  49. FileInputStream ramIn = new FileInputStream(new File("c:\\testing\\butts"));
  50.  
  51. byte[] buffer = new byte[diskIn.available()];
  52. diskIn.read(buffer);
  53.  
  54. Object[] hexColumns = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"};
  55.  
  56. DefaultTableModel model = new DefaultTableModel(hexColumns, 0);
  57.  
  58. testtable.setModel(model);
  59.  
  60. String hex = bytesToHex(buffer);
  61.  
  62. String[] firstSplit = hex.split("(?<=\\G.{32})");
  63. Object[] cellData;
  64.  
  65. for (int i = 0; i < firstSplit.length; i++) {
  66. cellData = firstSplit[i].split("(?<=\\G.{2})");
  67. model.addRow(cellData);
  68. }
  69.  
  70. }
  71.  
  72. /**
  73. * This method is called from within the constructor to initialize the form.
  74. * WARNING: Do NOT modify this code. The content of this method is always
  75. * regenerated by the Form Editor.
  76. */
  77. @SuppressWarnings("unchecked")
  78. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  79. private void initComponents() {
  80.  
  81. jScrollPane3 = new javax.swing.JScrollPane();
  82. testtable = new javax.swing.JTable();
  83. jScrollPane4 = new javax.swing.JScrollPane();
  84. jTable2 = new javax.swing.JTable();
  85.  
  86. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  87.  
  88. testtable.setModel(new javax.swing.table.DefaultTableModel(
  89. new Object [][] {
  90. {},
  91. {},
  92. {},
  93. {}
  94. },
  95. new String [] {
  96.  
  97. }
  98. ));
  99. jScrollPane3.setViewportView(testtable);
  100.  
  101. jTable2.setModel(new javax.swing.table.DefaultTableModel(
  102. new Object [][] {
  103. {null, null, null, null},
  104. {null, null, null, null},
  105. {null, null, null, null},
  106. {null, null, null, null}
  107. },
  108. new String [] {
  109. "Title 1", "Title 2", "Title 3", "Title 4"
  110. }
  111. ));
  112. jScrollPane4.setViewportView(jTable2);
  113.  
  114. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  115. getContentPane().setLayout(layout);
  116. layout.setHorizontalGroup(
  117. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  118. .addGroup(layout.createSequentialGroup()
  119. .addContainerGap()
  120. .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 480, javax.swing.GroupLayout.PREFERRED_SIZE)
  121. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 95, Short.MAX_VALUE)
  122. .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 471, javax.swing.GroupLayout.PREFERRED_SIZE)
  123. .addContainerGap())
  124. );
  125. layout.setVerticalGroup(
  126. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  127. .addGroup(layout.createSequentialGroup()
  128. .addContainerGap()
  129. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  130. .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE)
  131. .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
  132. .addContainerGap(71, Short.MAX_VALUE))
  133. );
  134.  
  135. pack();
  136. }// </editor-fold>
  137.  
  138. /**
  139. * @param args the command line arguments
  140. */
  141. public static void main(String args[]) {
  142. /* Set the Nimbus look and feel */
  143. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  144. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  145. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  146. */
  147. try {
  148. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  149. if ("Nimbus".equals(info.getName())) {
  150. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  151. break;
  152. }
  153. }
  154. } catch (ClassNotFoundException ex) {
  155. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  156. } catch (InstantiationException ex) {
  157. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  158. } catch (IllegalAccessException ex) {
  159. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  160. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  161. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  162. }
  163. //</editor-fold>
  164.  
  165. /* Create and display the form */
  166. java.awt.EventQueue.invokeLater(new Runnable() {
  167. public void run() {
  168. try {
  169. new NewJFrame().setVisible(true);
  170. } catch (IOException ex) {
  171. Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
  172. } catch (InterruptedException ex) {
  173. Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
  174. }
  175. }
  176. });
  177. }
  178.  
  179. // Variables declaration - do not modify
  180. private javax.swing.JScrollPane jScrollPane3;
  181. private javax.swing.JScrollPane jScrollPane4;
  182. private javax.swing.JTable jTable2;
  183. private javax.swing.JTable testtable;
  184. // End of variables declaration
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement