// Processed by NMI\'s Java Code Viewer 4.8.3 © 1997-2000 B. Lemaire
// Website:
http://njcv.htmlplanet.com E-mail: info@njcv.htmlplanet.com
// Copy registered to Evaluation Copy
// Source File Name: ISBN.java
import java.applet.Applet;
import java.awt.*;
import symantec.itools.awt.BaseTabbedPanel;
import symantec.itools.awt.TabPanel;
public class ISBN extends Applet {
Label lblStatus;
TabPanel tabPanel2;
TextArea txtPennyPress;
TextArea txtISBNs;
Panel pnlProg;
Label label1;
TextField txtGroupID;
Label label2;
TextField txtPublisherID;
Label label3;
TextArea txtISBN;
Button cmdGo;
public void init() {
super.init();
setLayout(null);
addNotify();
resize(327, 317);
lblStatus = new Label(\"OK so far\");
lblStatus.reshape(0, 288, 340, 24);
add(lblStatus);
tabPanel2 = new TabPanel();
tabPanel2.setLayout(null);
tabPanel2.reshape(0, 0, 336, 284);
add(tabPanel2);
String tempString[] = new String[3];
tempString[0] = new String(\"Penny Press\");
tempString[1] = new String(\"About ISBNs\");
tempString[2] = new String(\"Generator\");
tabPanel2.setPanelLabels(tempString);
txtPennyPress = new TextArea(0, 10);
txtPennyPress.reshape(12, 33, 312, 240);
tabPanel2.add(txtPennyPress);
txtISBNs = new TextArea();
txtISBNs.reshape(12, 33, 312, 240);
tabPanel2.add(txtISBNs);
pnlProg = new Panel();
pnlProg.setLayout(null);
pnlProg.reshape(12, 33, 312, 240);
tabPanel2.add(pnlProg);
label1 = new Label(\"Group ID\");
label1.reshape(0, 3, 112, 20);
pnlProg.add(label1);
txtGroupID = new TextField();
txtGroupID.reshape(132, 3, 149, 22);
pnlProg.add(txtGroupID);
label2 = new Label(\"Publisher ID\");
label2.reshape(0, 27, 112, 20);
pnlProg.add(label2);
txtPublisherID = new TextField();
txtPublisherID.reshape(132, 27, 149, 22);
pnlProg.add(txtPublisherID);
label3 = new Label(\"ISBNs\");
label3.reshape(0, 51, 112, 20);
pnlProg.add(label3);
txtISBN = new TextArea();
txtISBN.reshape(0, 75, 283, 151);
pnlProg.add(txtISBN);
cmdGo = new Button(\"Go!\");
cmdGo.reshape(132, 51, 52, 20);
pnlProg.add(cmdGo);
String message = new String(\"This Java applet is provided free as a service to\\npublishers. Click the Generator tab, enter the group\\nand publisher identifier, and press Go to generate \\nall ISBNs for that publisher.\\n\\nPenny Press provides computer consultancy to \\npublishers and others.\\nServices we provide include\\n -- Creating Java applets such as this one;\\n -- Consultancy in Visual Basic, Delphi, Oracle, \\n Access etc;\\n -- Converting printed books to electronic media.\\n\\nOrder the PC version of this applet from: \\n sales@pennyprs.demon.co.uk\");
txtPennyPress.setText(message);
message = \"An International Standard Book Number uniquely \\nidentifies a book or piece of software. \\nIt consists of 10 characters made up of\\n-- a group identifier indicating the national, \\n geographic, language or other group\\n-- a publisher identifier\\n-- a title identifier\\n-- a check digit\\n\\nYou can obtain a group and publisher identifier \\nfrom your national agency.\\nThis software calculates the title identifier \\nand check digits for all the ISBNs within your range.\\n\\nFor a list of national agencies see \\
nhttp://www.bowker.com/standards/home/isbn/international/group_agencies.html\";; txtISBNs.setText(message);
tabPanel2.setCurrentPanelNdx(0);
}
public boolean handleEvent(Event event) {
if(event.target == cmdGo && event.id == 1001) {
cmdGo_Clicked(event);
return true;
} else {
return super.handleEvent(event);
}
}
void cmdGo_Clicked(Event event) {
int iGroupID = 0;
int iPublisherID = 0;
int iTitleMax = 0;
int iGroupLen = 0;
int iPublisherLen = 0;
int iTitleLen = 0;
String strGroupID = txtGroupID.getText();
String strPublisherID = txtPublisherID.getText();
String strCheck = new String(\"\");
if(strGroupID.equals(\"\")) {
showMessage(\"Enter GroupID\");
return;
}
try {
iGroupID = Integer.valueOf(strGroupID).intValue();
}
catch(NumberFormatException e) {
showMessage(e.toString());
return;
}
if(iGroupID < 0 || iGroupID > 0x1869f) {
showMessage(\"GroupID must be 1 to 5 digits\");
return;
}
if(strPublisherID.equals(\"\")) {
showMessage(\"Enter PublisherID\");
return;
}
try {
iPublisherID = Integer.valueOf(strPublisherID).intValue();
}
catch(NumberFormatException e) {
showMessage(e.toString());
return;
}
if(iPublisherID < 0 || iPublisherID > 0x98967f) {
showMessage(\"PublisherID must be 1 to 7 digits\");
return;
}
String oldText = txtISBN.getText();
txtISBN.replaceText(\"\", 0, oldText.length());
iGroupLen = String.valueOf(iGroupID).length();
iPublisherLen = String.valueOf(iPublisherID).length();
iTitleLen = 9 - iGroupLen - iPublisherLen;
if(iTitleLen < 1 || iTitleLen > 6) {
showMessage(\"GroupID + PublisherID must be 3 to 8 digits\");
return;
}
iTitleMax = (int)Math.pow(10D, iTitleLen);
for(int iTitleID = 0; iTitleID < iTitleMax; iTitleID++) {
String strTitleID = String.valueOf(iTitleID);
for(int iThisLen = strTitleID.length(); iThisLen < iTitleLen; iThisLen = strTitleID.length())
strTitleID = \"0\" + strTitleID;
String strISBN = strGroupID + strPublisherID + strTitleID;
strCheck = strGetCheck(strISBN);
txtISBN.appendText(strGroupID + \"-\" + strPublisherID + \"-\" + strTitleID + \"-\" + strCheck + \"\\n\");
}
showMessage(\"ISBNs generated OK\");
}
private void showMessage(String strMessage) {
lblStatus.setText(strMessage);
}
private String strGetCheck(String strISBN) {
if(strISBN.length() != 9) {
showMessage(\"strGetCheck got \" + strISBN + \" which is not 9 digits\");
return \"\";
}
int iSum = 0;
for(int i = 0; i < 9; i++) {
int iWeight = 10 - i;
int iDigit = strISBN.charAt(i) - 48;
iSum += iWeight * iDigit;
}
iSum %= 11;
if(iSum == 0)
return \"0\";
int iCheck = 11 - iSum;
if(iCheck == 10)
return \"X\";
else
return String.valueOf(iCheck);
}
public ISBN() {
}
}