Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package compareframetest;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.table.DefaultTableModel;
- import javax.swing.table.TableModel;
- /**
- *
- * @author tony
- */
- public class NewJFrame extends javax.swing.JFrame {
- /**
- * Creates new form NewJFrame
- */
- public NewJFrame() throws IOException, InterruptedException {
- initComponents();
- this.setLocationRelativeTo(null);
- funStuff();
- }
- final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
- public static String bytesToHex(byte[] bytes) {
- char[] hexChars = new char[bytes.length * 2];
- for (int j = 0; j < bytes.length; j++) {
- int v = bytes[j] & 0xFF;
- hexChars[j * 2] = hexArray[v >>> 4];
- hexChars[j * 2 + 1] = hexArray[v & 0x0F];
- }
- String hexString = new String(hexChars);
- String[] split = hexString.split("(?<=\\G.{2})");
- return hexString;
- }
- private void funStuff() throws FileNotFoundException, IOException {
- FileInputStream diskIn = new FileInputStream(new File("c:\\testing\\butts"));
- FileInputStream ramIn = new FileInputStream(new File("c:\\testing\\butts"));
- byte[] buffer = new byte[diskIn.available()];
- diskIn.read(buffer);
- Object[] hexColumns = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"};
- DefaultTableModel model = new DefaultTableModel(hexColumns, 0);
- testtable.setModel(model);
- String hex = bytesToHex(buffer);
- String[] firstSplit = hex.split("(?<=\\G.{32})");
- Object[] cellData;
- for (int i = 0; i < firstSplit.length; i++) {
- cellData = firstSplit[i].split("(?<=\\G.{2})");
- model.addRow(cellData);
- }
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jScrollPane3 = new javax.swing.JScrollPane();
- testtable = new javax.swing.JTable();
- jScrollPane4 = new javax.swing.JScrollPane();
- jTable2 = new javax.swing.JTable();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- testtable.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {},
- {},
- {},
- {}
- },
- new String [] {
- }
- ));
- jScrollPane3.setViewportView(testtable);
- jTable2.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null}
- },
- new String [] {
- "Title 1", "Title 2", "Title 3", "Title 4"
- }
- ));
- jScrollPane4.setViewportView(jTable2);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 480, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 95, Short.MAX_VALUE)
- .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 471, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE)
- .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
- .addContainerGap(71, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- new NewJFrame().setVisible(true);
- } catch (IOException ex) {
- Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
- } catch (InterruptedException ex) {
- Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JScrollPane jScrollPane3;
- private javax.swing.JScrollPane jScrollPane4;
- private javax.swing.JTable jTable2;
- private javax.swing.JTable testtable;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement