# Java - Crypto ISBN number verification, GUI program

• October 4th, 2011, 09:32 AM
djl1990
Java - Crypto ISBN number verification, GUI program
Hi,

im all new to this i am doing a cryptography module and i have been given the following task.

Practical 2  NetBeans Workshop

We ask you to implement a little program which can

· verify ISBN code and

· generate the check number from a given 9 digits

Task 1: GUI  two input text fields and one text area for printing messages, three buttons (verify, generate, and clear).

Use the following lines to clear up text boxes:

jTextField1.setText("");

jTextField2.setText("");

jTextArea1.setText("");

Task 2: Write code to achieve the about two functions (i.e. verifying and generating ISBN code)

We need 10 integers, you can use array, but to make thinks simple, lets use 10 integers:

int d1,d2,d3,.d10;

To read input from the text field, use

String s;

s = jTextField1.getText();

The following line gets the first char in the string, and convert it to an integer

d1 = Integer.parseInt(String.valueOf(s.charAt(0)));

Remember the all ten digits d1,d2, , d10, must satisfy the following condition:

(d1+2*d2+3*d3+4*d4+5*d5+6*d6+7*d7+8*d8+9*d9+10*d10 ) mod 11 = 0

That is, the check number, d10, must satisfy the following condition:

d10 = (d1+2*d2+3*d3+4*d4+5*d5+6*d6+7*d7+8*d8+9*d9) mod 11

working

10*d10 = ( (d1+2*d2+3*d3+4*d4+5*d5+6*d6+7*d7+8*d8+9*d9) mod 11), that is,

(-10)*d10 = (d1+2*d2+3*d3+4*d4+5*d5+6*d6+7*d7+8*d8+9*d9) mod 11

because -10 mod 11 = 1 mod 11, so

d10 = (d1+2*d2+3*d3+4*d4+5*d5+6*d6+7*d7+8*d8+9*d9) mod 11

Note that, In Java, the mod operation is %.

Firstly, Im in Netbeans do i use a Main class, a normal class, a java interface class, or what...?

I dont really get what to do to be honest.
• October 4th, 2011, 12:28 PM
KevinWorkman
Re: Java - Crypto ISBN number verification, GUI program
• October 4th, 2011, 12:34 PM
kenster421
Re: Java - Crypto ISBN number verification, GUI program
You need to create a new project and make sure it's a Java Desktop Application. It will create the initial Window and Frame for you. You just need to drag and drop the controls and name them appropriately.
• October 5th, 2011, 06:41 AM
KevinWorkman
Re: Java - Crypto ISBN number verification, GUI program
Quote:

Originally Posted by kenster421
You need to create a new project and make sure it's a Java Desktop Application. It will create the initial Window and Frame for you. You just need to drag and drop the controls and name them appropriately.

For the record, I absolutely disagree with this advice. The GUI creator that comes with netbeans is not a tool for novices, and it encourages tons of bad practices. Best to bust out the Swing tutorial and ask a more specific question instead of fumbling with the drag-and-drop nonsense.
• October 6th, 2011, 02:51 PM
djl1990
Re: Java - Crypto ISBN number verification, GUI program
I have done it as a Java Desktop Application as this is what my tutor said to do.

I have the 2 text fields, 1 text area and 3 buttons by just dragging and dropping them over.

And have renamed the 3 buttons; generate, verify and clear. Do you think generate should be the 1st one or the verify one?

anyway......

I have added an event handler: mouseClicked on the first button and have the following code in this section:

jTextField1.setText("");
jTextField2.setText("");
jTextArea1.setText("");

On the second mouseClicked section i have this:

String s;
s = jTextField1.getText();

int d1 = Integer.parseInt(String.valueOf(s.charAt(0)));
int d2 = Integer.parseInt(String.valueOf(s.charAt(1)));
int d3 = Integer.parseInt(String.valueOf(s.charAt(2)));
int d4 = Integer.parseInt(String.valueOf(s.charAt(3)));
int d5 = Integer.parseInt(String.valueOf(s.charAt(4)));
int d6 = Integer.parseInt(String.valueOf(s.charAt(5)));
int d7 = Integer.parseInt(String.valueOf(s.charAt(6)));
int d8 = Integer.parseInt(String.valueOf(s.charAt(7)));
int d9 = Integer.parseInt(String.valueOf(s.charAt(8)));
int d10 = Integer.parseInt(String.valueOf(s.charAt(9)));

Next bit is.............

Remember the all ten digits d1,d2, , d10, must satisfy the following condition:

(d1+2*d2+3*d3+4*d4+5*d5+6*d6+7*d7+8*d8+9*d9+10*d10 ) mod 11 = 0

Is mine okay so far? ive heared i need to use an if statement to test the condition, but is it all correct so far?I will copy out the whole code i have so far so you can see:

package isbnverify;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;

public class ISBNVerifyView extends FrameView {

public ISBNVerifyView(SingleFrameApplication app) {
super(app);

initComponents();

ResourceMap resourceMap = getResourceMap();
int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout") ;
messageTimer = new Timer(messageTimeout, new ActionListener() {

public void actionPerformed(ActionEvent e) {
statusMessageLabel.setText("");
}
});
messageTimer.setRepeats(false);
int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRat e");
for (int i = 0; i < busyIcons.length; i++) {
busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
}
busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

public void actionPerformed(ActionEvent e) {
busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
}
});
idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);

public void propertyChange(java.beans.PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if ("started".equals(propertyName)) {
if (!busyIconTimer.isRunning()) {
statusAnimationLabel.setIcon(busyIcons[0]);
busyIconIndex = 0;
busyIconTimer.start();
}
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
} else if ("done".equals(propertyName)) {
busyIconTimer.stop();
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
progressBar.setValue(0);
} else if ("message".equals(propertyName)) {
String text = (String) (evt.getNewValue());
statusMessageLabel.setText((text == null) ? "" : text);
messageTimer.restart();
} else if ("progress".equals(propertyName)) {
int value = (Integer) (evt.getNewValue());
progressBar.setVisible(true);
progressBar.setIndeterminate(false);
progressBar.setValue(value);
}
}
});
}

@Action
JFrame mainFrame = ISBNVerifyApp.getApplication().getMainFrame();
}
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

mainPanel = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
statusPanel = new javax.swing.JPanel();
javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
statusMessageLabel = new javax.swing.JLabel();
statusAnimationLabel = new javax.swing.JLabel();
progressBar = new javax.swing.JProgressBar();

mainPanel.setName("mainPanel"); // NOI18N

org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(i sbnverify.ISBNVerifyApp.class).getContext().getRes ourceMap(ISBNVerifyView.class);
jTextField1.setText(resourceMap.getString("jTextFi eld1.text")); // NOI18N
jTextField1.setName("jTextField1"); // NOI18N

jTextField2.setText(resourceMap.getString("jTextFi eld2.text")); // NOI18N
jTextField2.setName("jTextField2"); // NOI18N

jButton1.setText(resourceMap.getString("jButton1.t ext")); // NOI18N
jButton1.setName("jButton1"); // NOI18N
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});

jButton2.setText(resourceMap.getString("jButton2.t ext")); // NOI18N
jButton2.setName("jButton2"); // NOI18N
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});

jButton3.setText(resourceMap.getString("jButton3.t ext")); // NOI18N
jButton3.setName("jButton3"); // NOI18N

jScrollPane1.setName("jScrollPane1"); // NOI18N

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jTextArea1.setName("jTextArea1"); // NOI18N
jScrollPane1.setViewportView(jTextArea1);

javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
);
mainPanelLayout.setVerticalGroup(
);

javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(i sbnverify.ISBNVerifyApp.class).getContext().getAct ionMap(ISBNVerifyView.class, this);

statusPanel.setName("statusPanel"); // NOI18N

statusPanelSeparator.setName("statusPanelSeparator "); // NOI18N

statusMessageLabel.setName("statusMessageLabel"); // NOI18N

statusAnimationLabel.setHorizontalAlignment(javax. swing.SwingConstants.LEFT);
statusAnimationLabel.setName("statusAnimationLabel "); // NOI18N

progressBar.setName("progressBar"); // NOI18N

javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
statusPanel.setLayout(statusPanelLayout);
statusPanelLayout.setHorizontalGroup(
);
statusPanelLayout.setVerticalGroup(
);

setComponent(mainPanel);
setStatusBar(statusPanel);
}// </editor-fold>

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {

jTextField1.setText("");
jTextField2.setText("");
jTextArea1.setText("");

}

private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {

String s;
s = jTextField1.getText();

int d1 = Integer.parseInt(String.valueOf(s.charAt(0)));
int d2 = Integer.parseInt(String.valueOf(s.charAt(1)));
int d3 = Integer.parseInt(String.valueOf(s.charAt(2)));
int d4 = Integer.parseInt(String.valueOf(s.charAt(3)));
int d5 = Integer.parseInt(String.valueOf(s.charAt(4)));
int d6 = Integer.parseInt(String.valueOf(s.charAt(5)));
int d7 = Integer.parseInt(String.valueOf(s.charAt(6)));
int d8 = Integer.parseInt(String.valueOf(s.charAt(7)));
int d9 = Integer.parseInt(String.valueOf(s.charAt(8)));
int d10 = Integer.parseInt(String.valueOf(s.charAt(9)));

}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JPanel mainPanel;
private javax.swing.JProgressBar progressBar;
private javax.swing.JLabel statusAnimationLabel;
private javax.swing.JLabel statusMessageLabel;
private javax.swing.JPanel statusPanel;
// End of variables declaration
private final Timer messageTimer;
private final Timer busyIconTimer;
private final Icon idleIcon;
private final Icon[] busyIcons = new Icon[15];
private int busyIconIndex = 0;
}
• October 7th, 2011, 08:53 AM
KevinWorkman
Re: Java - Crypto ISBN number verification, GUI program
That's really not how this works. I recommend you read the link in my signature on asking questions the smart way before you post again. There are hundreds of posts here every day, and we simply don't have time to be your debugger. You ask whether it's okay so far- you have to tell us! Does it work? Does it do what you expect?

If it doesn't work or do what you expect, then you have to boil the problem down to an SSCCE- again, we simply don't have time to go through that much code, much of which has nothing to do with your problem, and much of which has been generated by a GUI creator, which makes helping you even harder.
• October 7th, 2011, 10:32 AM
djl1990
Re: Java - Crypto ISBN number verification, GUI program
Im just asking for help, i have no idea what to do.
• October 7th, 2011, 12:51 PM
KevinWorkman
Re: Java - Crypto ISBN number verification, GUI program
Quote:

Originally Posted by djl1990
Im just asking for help, i have no idea what to do.

I've given you several links that should help with that. Go through the steps outlined in the "How to Program" link, then if you get stuck, create an SSCCE and follow the directions in the "how to ask questions the smart way" link.
• October 13th, 2011, 08:26 AM
djl1990
Re: Java - Crypto ISBN number verification, GUI program
could someone help with the if statement for the following requirement please:

as i understand it % symbol is for mod ?

Remember the all ten digits d1,d2, , d10, must satisfy the following condition:

(d1+2*d2+3*d3+4*d4+5*d5+6*d6+7*d7+8*d8+9*d9+10*d10 ) mod 11 = 0
• October 13th, 2011, 08:41 AM
KevinWorkman
Re: Java - Crypto ISBN number verification, GUI program
Quote:

Originally Posted by djl1990
could someone help with the if statement for the following requirement please:

as i understand it % symbol is for mod ?

Remember the all ten digits d1,d2, ……, d10, must satisfy the following condition:

(d1+2*d2+3*d3+4*d4+5*d5+6*d6+7*d7+8*d8+9*d9+10*d10 ) mod 11 = 0

Is this a different question? If so, please post this in its own thread (and for posterity's sake, post a link to it here, and a link here to it). Again, all of the advice and links I gave you apply here as well.
• October 13th, 2011, 11:14 AM
djl1990
Re: Java - Crypto ISBN number verification, GUI program
Hi,

no this if statement is part of the original question.

I am told by my tutor to use an if statement to test for the condition, but i dont really know what to do if the condition is true or false. :confused:
• October 13th, 2011, 11:22 AM
KevinWorkman
Re: Java - Crypto ISBN number verification, GUI program
Quote:

Originally Posted by djl1990
Hi,

no this if statement is part of the original question.

I am told by my tutor to use an if statement to test for the condition, but i dont really know what to do if the condition is true or false. :confused:

Neither do we, because you haven't really told us what you're trying to do. Read the links I gave you. Post an SSCCE, ask a specific question, and we'll go from there. Otherwise, I'm done trying to help you, as we are getting nowhere.