import = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel();

import java.awt.Color;public class checkSUM extends javax.swing.JFrame {    public checkSUM() {        initComponents();    }        @SuppressWarnings(“unchecked”)    //                               private void initComponents() {        jPanel1 = new javax.swing.JPanel();        jScrollPane1 = new javax.swing.JScrollPane();        logarea = new javax.swing.JTextArea();        jScrollPane2 = new javax.swing.JScrollPane();        logarea2 = new javax.swing.JTextArea();        jLabel1 = new javax.swing.JLabel();        jLabel2 = new javax.swing.JLabel();        sent = new javax.swing.JTextField();        recived = new javax.swing.JTextField();        checkBTN = new javax.swing.JButton();        log = new javax.swing.JLabel();        jLabel4 = new javax.swing.JLabel();        jLabel5 = new javax.swing.JLabel();        jLabel3 = new javax.swing.JLabel();        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);        setTitle(“CheckSum”);        setBackground(new java.awt.Color(255, 102, 51));        jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));        jScrollPane1.setBorder(null);        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);        logarea.setEditable(false);        logarea.setColumns(20);        logarea.setRows(5);        jScrollPane1.setViewportView(logarea);        jScrollPane2.setBorder(null);        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);        logarea2.setEditable(false);        logarea2.setColumns(20);        logarea2.setRows(5);        jScrollPane2.setViewportView(logarea2);        jLabel1.setFont(new java.awt.Font(“Tahoma”, 0, 14)); // NOI18N        jLabel1.setForeground(new java.awt.Color(51, 51, 51));        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);        jLabel1.setText(“Sent”);        jLabel2.setFont(new java.awt.Font(“Tahoma”, 0, 14)); // NOI18N        jLabel2.setForeground(new java.awt.Color(51, 51, 51));        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);        jLabel2.setText(“Recived”);        sent.setBorder(null);        sent.setMargin(new java.awt.Insets(10, 2, 2, 2));        sent.setName(“sent”); // NOI18N        recived.setBorder(null);        recived.setName(“recived”); // NOI18N        checkBTN.setFont(new java.awt.Font(“Tahoma”, 0, 14)); // NOI18N        checkBTN.setText(“Check”);        checkBTN.setBorder(null);        checkBTN.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));        checkBTN.setName(“btn”); // NOI18N        checkBTN.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                checkBTNActionPerformed(evt);            }        });        log.setText(“LOG MESSAGE”);        jLabel4.setText(“Log”);        jLabel5.setText(“Math Log”);        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);        jPanel1.setLayout(jPanel1Layout);        jPanel1Layout.setHorizontalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addComponent(log, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE))            .addGroup(jPanel1Layout.createSequentialGroup()                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addGroup(jPanel1Layout.createSequentialGroup()                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)                        .addGap(141, 141, 141)                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))                    .addGroup(jPanel1Layout.createSequentialGroup()                        .addContainerGap()                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)                            .addComponent(checkBTN, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                                .addGroup(jPanel1Layout.createSequentialGroup()                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                                    .addComponent(sent, javax.swing.GroupLayout.PREFERRED_SIZE, 310, javax.swing.GroupLayout.PREFERRED_SIZE))                                .addGroup(jPanel1Layout.createSequentialGroup()                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                                    .addComponent(recived, javax.swing.GroupLayout.PREFERRED_SIZE, 310, javax.swing.GroupLayout.PREFERRED_SIZE))))))                .addGap(0, 0, Short.MAX_VALUE))        );        jPanel1Layout.setVerticalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel1Layout.createSequentialGroup()                .addGap(21, 21, 21)                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(sent, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))                .addGap(18, 18, 18)                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(recived, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))                .addGap(13, 13, 13)                .addComponent(checkBTN, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)                .addGap(18, 18, 18)                .addComponent(log)                .addGap(31, 31, 31)                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addComponent(jLabel4)                    .addComponent(jLabel5))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addContainerGap(26, Short.MAX_VALUE))        );        jLabel3.setBackground(new java.awt.Color(255, 255, 255));        jLabel3.setFont(new java.awt.Font(“Cordia New”, 0, 36)); // NOI18N        jLabel3.setForeground(new java.awt.Color(51, 51, 51));        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);        jLabel3.setText(“CHECKSUM”);        jLabel3.setName(“title”); // NOI18N        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addGap(75, 75, 75)                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 445, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(43, Short.MAX_VALUE))            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addGap(57, 57, 57))        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addGap(45, 45, 45)                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)                .addGap(18, 18, 18)                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        pack();    }//                             int generateChecksum(String s) { String hex_value = new String(); // ‘hex_value’ will be used to store various hex values as a string int x, i, checksum=0; for(i=0 ; i < s.length()-2 ; i=i+2) { x = (int) (s.charAt(i)); hex_value = Integer.toHexString(x); x = (int) (s.charAt(i+1)); hex_value = hex_value + Integer.toHexString(x); logarea2.append(s.charAt(i)+""+s.charAt(i+1) + " : "+ hex_value+" "); x = Integer.parseInt(hex_value, 16);                        checksum += x; } if(s.length()%2 == 0) { x = (int) (s.charAt(i)); hex_value = Integer.toHexString(x); x = (int) (s.charAt(i+1)); hex_value = hex_value + Integer.toHexString(x); logarea2.append(s.charAt(i)+""+s.charAt(i+1) + " : " + hex_value+" "); x = Integer.parseInt(hex_value, 16); } else {                     x = (int) (s.charAt(i)); hex_value = "00" + Integer.toHexString(x); x = Integer.parseInt(hex_value, 16); logarea2.append(s.charAt(i) + " : " + hex_value+" "); } checksum += x;                hex_value = Integer.toHexString(checksum);                 if(hex_value.length() > 4) {                    int carry = Integer.parseInt((“”+hex_value.charAt(0)), 16);                    hex_value = hex_value.substring(1,5);                    checksum = Integer.parseInt(hex_value, 16);                    checksum += carry;                } checksum = generateComplement(checksum);                return checksum; }    static int generateComplement(int checksum) {        checksum = Integer.parseInt(“FFFF”, 16) – checksum; return checksum; }        private void checkBTNActionPerformed(java.awt.event.ActionEvent evt) {                                                         logarea2.setText(“”);        logarea2.append(“>>Data Sent<< ");        String sentData = sent.getText();        int Sentchecksum = generateChecksum(sentData);        logarea.setText("CheckSUM for sent data: "+Integer.toHexString(Sentchecksum));        logarea2.append("--------------------------- ");        logarea2.append(">>Data recived<< ");        String recivedData = recived.getText();        int recivedchecksum = generateChecksum(recivedData);        logarea.append(" CheckSUM for sent data: "+Integer.toHexString(recivedchecksum));                if(Sentchecksum == recivedchecksum){            log.setText("Data Recived correctly");            logarea.append(" "+Sentchecksum+" = "+recivedchecksum);            logarea.append(" Data Recived correctly");            log.setForeground(Color.DARK_GRAY);        }        else{            log.setText("There is an error");            logarea.append(" "+Sentchecksum+" != "+recivedchecksum);            logarea.append(" There is an error");                        log.setForeground(Color.red);        }    }                                                public static void main(String args) {        /* Set the Nimbus look and feel */        //        /* 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(checkSUM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        } catch (InstantiationException ex) {            java.util.logging.Logger.getLogger(checkSUM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        } catch (IllegalAccessException ex) {            java.util.logging.Logger.getLogger(checkSUM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        } catch (javax.swing.UnsupportedLookAndFeelException ex) {            java.util.logging.Logger.getLogger(checkSUM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        }        //        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                new checkSUM().setVisible(true);            }        });    }    // Variables declaration – do not modify                         private javax.swing.JButton checkBTN;    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel2;    private javax.swing.JLabel jLabel3;    private javax.swing.JLabel jLabel4;    private javax.swing.JLabel jLabel5;    private javax.swing.JPanel jPanel1;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JScrollPane jScrollPane2;    private javax.swing.JLabel log;    private javax.swing.JTextArea logarea;    private javax.swing.JTextArea logarea2;    private javax.swing.JTextField recived;    private javax.swing.JTextField sent;    // End of variables declaration                   }

x

Hi!
I'm Johnny!

Would you like to get a custom essay? How about receiving a customized one?

Check it out