/*
* CheckDigitApplet.java
*
* Created on September 5, 2002, 10:58 AM
*/
import javax.swing.*;
/**
*
* @author alex
*/
public class CheckDigitApplet extends javax.swing.JApplet {
/** Creates new form CheckDigitApplet */
public CheckDigitApplet() {
initComponents();
}
/** 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.
*/
private void initComponents() {//GEN-BEGIN:initComponents
java.awt.GridBagConstraints gridBagConstraints;
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
inputTextField = new JTextField(new AllCapsLimitDocument(10),null,0);
jLabel3 = new javax.swing.JLabel();
goButton = new javax.swing.JButton();
resultLabel = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jPanel1.setLayout(new java.awt.GridBagLayout());
jLabel1.setText("Container Number CheckDigit");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = 3;
gridBagConstraints.insets = new java.awt.Insets(15, 15, 1, 15);
jPanel1.add(jLabel1, gridBagConstraints);
jLabel2.setText("Input 10 Characters:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(15, 10, 15, 10);
jPanel1.add(jLabel2, gridBagConstraints);
inputTextField.setFont(new java.awt.Font("Courier New", 0, 12));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.ipadx = 100;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
jPanel1.add(inputTextField, gridBagConstraints);
jLabel3.setText("Result is:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(15, 10, 15, 10);
jPanel1.add(jLabel3, gridBagConstraints);
goButton.setText("CRC?");
goButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
goButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;
jPanel1.add(goButton, gridBagConstraints);
resultLabel.setFont(new java.awt.Font("Courier New", 1, 12));
resultLabel.setText("-----------");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
jPanel1.add(resultLabel, gridBagConstraints);
jLabel4.setFont(new java.awt.Font("Dialog", 2, 12));
jLabel4.setText("(ISO 6346)");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 15, 0);
jPanel1.add(jLabel4, gridBagConstraints);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
}//GEN-END:initComponents
private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goButtonActionPerformed
// Add your handling code here:
if(inputTextField.getText()==null){
return;
}
if(inputTextField.getText().length()!=10){
JOptionPane.showMessageDialog(this,"Input must be 10 characters",
"ERROR",JOptionPane.ERROR_MESSAGE);
resultLabel.setText("-----------");
return;
}
int crc = ContCheckDigit.getCRC(inputTextField.getText());
if(crc == -1){
JOptionPane.showMessageDialog(this,"Please use this Format: ABCD123456",
"ERROR",JOptionPane.ERROR_MESSAGE);
resultLabel.setText("-----------");
return;
}
if(crc == 10){
JOptionPane.showMessageDialog(this,"It is recomended not to use this number because the CRC is 10 ",
"ERROR",JOptionPane.INFORMATION_MESSAGE);
crc=0;
}
resultLabel.setText(inputTextField.getText() + crc);
System.out.println("OK: finished");
}//GEN-LAST:event_goButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton goButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField inputTextField;
private javax.swing.JLabel resultLabel;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel1;
// End of variables declaration//GEN-END:variables
}