Help with java digital signing code

hello people.
can anybody help me?
i have find a java code to resolve my problem with sending pay in soap envelope with digital signature and attached certificate. i compiled it with jdk jdk1.6.0_37. and it works.
i need it to work in built-in jvm in oracle 9i. in oracle 9i jvm release is 1.3.1. Java code does not work there. there is an error
class import com.sun.org.apache.xerces.internal.impl.dv.util.Base64 not found in import.
i did not find this class in network.
can anybody help with rewriting it for jvm 1.3.1?
thanks in advance.
code below:
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import java.io.*;
import java.security.Key;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.cert.Certificate;
public class Sign {
public static void main(String[] args) throws Exception {
// TODO code application logic here
BufferedReader reader = new BufferedReader(new FileReader("c:\\cert.p12"));
StringBuilder fullText = new StringBuilder();
String line = reader.readLine();
while (line != null) {
fullText.append(line);
line = reader.readLine();
KeyStore p12 = KeyStore.getInstance("pkcs12");
p12.load(new FileInputStream("c:\\cert.p12"), "Hfrtnf$5".toCharArray());
//????????? ????????? ????, ??? ????? ????? ???????????? alias ? ??????
//Key key = p12.getKey("my kkb key", "ryba-mech".toCharArray());
Key key = (Key) p12.getKey("my kkb key", "Hfrtnf$5".toCharArray());
Certificate userCert = (Certificate) p12.getCertificate("my kkb key");
String base64Cert = new String(Base64.encode(userCert.getEncoded()));
//signing
Signature signer = Signature.getInstance("SHA1withRSA");
signer.initSign((PrivateKey) key);
signer.update(fullText.toString().getBytes());
byte[] digitalSignature = signer.sign();
String base64sign = new String(Base64.encode(digitalSignature));
String base64Xml = new String(Base64.encode(fullText.toString().getBytes()));
System.out.println("<certificate>" + base64Cert+"</certificate>");
System.out.println("<xmlBody>" + base64Xml+"</xmlBody>");
System.out.println("<signature>" + base64sign+"</signature>");
Edited by: user13622283 on 22.01.2013 22:08

My first search is to see if there is an Apache commons project that provides it. Lo and behold:
http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.html
commons-codec.

Similar Messages

  • HT3209 Purchased DVD in US for Cdn viewing. Digital download will not work in Cda or US? please help with new Digital code that will work

    Purchased DVD in US for Cdn viewing. Digital download will not work in Cda or US? please help with new Digital code that will work

    You will need to contact the movie studio that produced the DVD and ask if they can issue you a new code valid for Canada. Apple cannot help you, and everyone here in these forums is just a fellow user.
    Regards.

  • Help with java mapping

    PI File adapter has a processing option u2018Empty-Message Handlingu2019 to ignore or Write Empty Files. In case there is no data created after mapping on target side then this option determines whether to write an empty file or not. But there is a catch to this option when it comes to using it with File Content Conversion which is described in SAP Note u2018821267u2019. It states following:
    I configure the receiver channel with File content conversion mode and I set the 'Empty Message Handling' option to ignore. Input payload to the receiver channel is generated out of mapping and it does not have any record sets. However, this payload has a root element. Why does file receiver create empty output file with zero byte size in the target directory?  Example of such a payload generated from mapping is as follows:                                                           
    <?xml version="1.0" encoding="UTF-8"?>                          
    <ns1:test xmlns:ns1="http://abcd.com/ab"></ns1:test>
    solution :
    If the message payload is empty (i.e., zero bytes in size), then File adapter's empty message handling feature does NOT write files into the target directory. On the other hand, if the payload is a valid XML document (as shown in example) that is generated from mapping with just a root element in it, the File Adapter does not treat it as an empty message and accordingly it writes to the target directory. To achieve your objective of not writing files (that have just a single root element) into the target directory, following could be done:
    Using a Java or ABAP Mapping in order to restrict the creation of node itself during mapping. (This cannot be achieved via Message Mapping)
    Using standard adapter modules to do content conversion first and then write file. 
    can someone help with java mapping that can be used in this case?

    Hi,
        You have not mentioned the version of PI you are working in. In case you are working with PI 7.1 or above then here is the java mapping code you need to add after message mapping in the same interface mapping
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.Map;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import com.sap.aii.mapping.api.AbstractTransformation;
    import com.sap.aii.mapping.api.StreamTransformationException;
    import com.sap.aii.mapping.api.TransformationInput;
    import com.sap.aii.mapping.api.TransformationOutput;
    public class RemoveRootNode extends AbstractTransformation{
         public void execute(InputStream in, OutputStream out)
         throws StreamTransformationException {
    // TODO Auto-generated method stub
    try
         DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
         DocumentBuilder builderel=factory.newDocumentBuilder();
         /*input document in form of XML*/
         Document docIn=builderel.parse(in);
         /*document after parsing*/
         Document docOut=builderel.newDocument();
         TransformerFactory tf=TransformerFactory.newInstance();
         Transformer transform=tf.newTransformer();
         if(docIn.getDocumentElement().hasChildNodes())
              docOut.appendChild(docOut.importNode(docIn.getDocumentElement(),true));
              transform.transform(new DOMSource(docOut), new StreamResult(out));
         else
              out.write(null);
    catch(Exception e)
    public void setParameter(Map arg0) {
    // TODO Auto-generated method stub
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    try{
         RemoveRootNode genFormat=new RemoveRootNode();
         FileInputStream in=new FileInputStream("C:\\apps\\sdn\\rootNode.xml");
         FileOutputStream out=new FileOutputStream("C:\\apps\\sdn\\rootNode1.xml");
         genFormat.execute(in,out);
         catch(Exception e)
         e.printStackTrace();
    public void transform(TransformationInput arg0, TransformationOutput arg1)
              throws StreamTransformationException {
         // TODO Auto-generated method stub
         this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
    In case you are working in PI 7.0 you can use this code
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.Map;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import com.sap.aii.mapping.api.StreamTransformation;
    import com.sap.aii.mapping.api.StreamTransformationException;
    public class RemoveRootNode implements StreamTransformation{
         public void execute(InputStream in, OutputStream out)
         throws StreamTransformationException {
    // TODO Auto-generated method stub
    try
         DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
         DocumentBuilder builderel=factory.newDocumentBuilder();
         /*input document in form of XML*/
         Document docIn=builderel.parse(in);
         /*document after parsing*/
         Document docOut=builderel.newDocument();
         TransformerFactory tf=TransformerFactory.newInstance();
         Transformer transform=tf.newTransformer();
         if(docIn.getDocumentElement().hasChildNodes())
              docOut.appendChild(docOut.importNode(docIn.getDocumentElement(),true));
              transform.transform(new DOMSource(docOut), new StreamResult(out));
         else
              out.write(null);
    catch(Exception e)
    public void setParameter(Map arg0) {
    // TODO Auto-generated method stub
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    try{
         RemoveRootNode genFormat=new RemoveRootNode();
         FileInputStream in=new FileInputStream("C:\\apps\\sdn\\rootNode.xml");
         FileOutputStream out=new FileOutputStream("C:\\apps\\sdn\\rootNode1.xml");
         genFormat.execute(in,out);
         catch(Exception e)
         e.printStackTrace();
    The code for PI 7.0 should also work for PI 7.1 provided you use the right jar files for compilation, but vice-versa is not true.
    Could you please let us know if this code was useful to you or not?
    Regards
    Anupam
    Edited by: anupamsap on Dec 15, 2011 9:43 AM

  • Need help with implementing Digital Signatures

    Hello,
    Here's an excerpt from a security book:
    To create a digital signature, a sender first takes the original plaintext message and runs it through a hash function.
    The Secure Hash Algorithm (SHA-1) is the standard for hash functions.
    The hash value is also known as a message digest.
    Next, the sender uses the its private key to encrypt the message digest. This step creates
    a digital signature and authenticates the sender, since only the owner of that private key could
    encrypt the message. The sender encrypts the original message with the receiver&rsquo;s public key
    and sends the encrypted message and the digital signature to the receiver.
    The receiver uses the sender&rsquo;s public key to decipher the original digital signature and reveal the message
    digest. The receiver then uses his or her own private key to decipher the original message.
    Finally, the receiver applies the agreed upon hash function (e.g. SHA-1 or MD5) to the original
    message. If the hash value of the original message matches the message digest included
    in the signature, there is message integrity-the message has not been altered in transmission.
    I would like to implement the sender's part and create an encrypted message and the digital signature.
    Suppose I have in hand a message (let's call it myMessage), my private key (let's call it myPrivateKey) and the receiver's public key (let's call it receiverPublicKey).
    In order to encrypt the original message with the receiver&rsquo;s public key I've implemented this piece of code:
    Cipher cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.ENCRYPT_MODE,receiverPublicKey);
    byte[] binaryCryptData = cipher.doFinal(myMessage.getBytes());
    String encPayload = Base64.byteArrayToBase64(binaryCryptData);
    return encPayload;In order to create the signature I've implemented this piece of code:
    Signature RSA = Signature.getInstance("SHA1withRSA");
    RSA.initSign(myPrivateKey);
    byte bt[] = message.getBytes();
    RSA.update(bt);
    byte[] signature = RSA.sign();My assumption is that I don't follow the exact guidlines in the book for the sender.
    Can someone please let me know what I'm missing and help me in adjusting my code with the books standards?
    Thank you in advance,
    Roy

    it's your homework, not ours.
    Congratulations on typing in everything BUT the most important part that it's all about, but that's not enough.

  • Help with Mail & Digital Signatures

    My work is moving to Common Access Cards and digitally signed email. I can't get Mail to bring up the digital signature icon when I use the CAC card. It works fine with a software certificate, but I can't use that.
    The certificates in the CAC show up in a different keychain, and I think Mail wants the certificates in the login keychain. I've tried the following:
    -- importing the certificate from the CAC (didn't allow it)
    -- changing the default keychain to the CAC keychain (caused mail and keychain access and Safari to all quit)
    I don't really want to try logging in using the CAC card -- the only instructions I've seen to do this require messing around with Terminal and other files. Seems the potential for messing things up is rather large.
    Anyone know how I can get Mail to recognise the CAC card for digital signatures?
    Mac Pro   Mac OS X (10.4.9)  

    I haven't had to do this myself, but these instructions may be of help, if you haven't already seen them.
    Matt

  • Help with java error

    Hi I got this error and i don't know what it means or how to fix it
    if you understand it please help
    Bad installation. Error invoking java vm(execv)
    C:\program Files\java\ire1.5.0_10\bin\javaw.exe
    I got this error when i went to add and remove programs in winXP
    and highlighted a program called Goban3 and clicked on change\remove
    http://www.gokgs.com/
    goban3 is sign on link to KGS
    if you check the site KGS you can see some java related items that have to be done i use this sights for years without problems
    but now im having problems with java
    thanks for serious reply
    Message was edited by: r
    revest

    That looks alot like this.

  • Help with java coding involving stacks and queues.

    I was wondering if anyone can help with tips on what to fill in for the coding.
    My project is to creating a word processor by the process of 2 stacks. The methods are given, but I'm not really sure what goes in them. So I was wonder if anyone can answer this for me, or give tips that would be great thanks.
    Example Code, similar to what were suppose to do, but instead it's CHARACTER stacks rather than String.
    [http://www.cs.jhu.edu/~jason/226/hw3/source/EditableString.java]

    /** Stack of Characters to the left of the cursor; the ones
       * near the top of the stack are closest to the cursor.
      private Stack left;
      /** Stack of Characters to the right of the cursor; the ones
       * near the top of the stack are closest to the cursor.
      private Stack right;Do you know how a stack works?
    No - Google it
    Yes - Continue on with this post
    /** Another constructor.
       * @param left The text to the left of the cursor.
       * @param right The text to the right of the cursor.
      public EditableString(String left, String right) {
        // fill this in
      }Do you know how to read?
    No - How did you answer this question then?
    Yes - Then why can't you read the comments above each method. Is it really that hard to understand?
    Mel

  • Help with Java Web Service

    Hi,
    I tried integrating java code with java embedding acitivity, but in em it is failing. Can anybody know how to convert the below java code to a webservice, so that I can pass the input paramaters directly to that webservice. I tried of converting java code to webservice in jdeveloper, but because of static void main it is not converting. Can somebody help me in this issue.
    this is the original executable java code.
    package com.holx.api.test;
    import java.util.HashMap;
    import com.agile.api.APIException;
    import com.agile.api.AgileSessionFactory;
    import com.agile.api.IAdmin;
    import com.agile.api.IAgileClass;
    import com.agile.api.IAgileList;
    import com.agile.api.IAgileSession;
    import com.agile.api.IAutoNumber;
    import com.agile.api.IDataObject;
    import com.agile.api.INode;
    import com.agile.api.IProperty;
    import com.agile.api.IServiceRequest;
    import com.agile.api.PropertyConstants;
    import com.agile.api.ServiceRequestConstants;
    import com.agile.px.ActionResult;
    import java.net.URL;
    public class TestAgileAPI {
    //     @Override
    //     public ActionResult doAction(IAgileSession arg0, INode arg1,
    //               IDataObject arg2) {
              // TODO Auto-generated method stub
    //          return null;
         * @param args
         public static void main(String[] args) {
              IAgileSession m_session = null;
              IAdmin admin = null;
              IAgileClass cls = null;
         String sr="PR-KB00028";
    String userName="*******";
    String password="*******";
    String URL="*********";
              try {
                   HashMap params = new HashMap();
                   params.put(AgileSessionFactory.USERNAME, userName);
                   params.put(AgileSessionFactory.PASSWORD, password);
                   AgileSessionFactory instance = AgileSessionFactory.getInstance(URL);     
                   m_session = instance.createSession(params);     
                   admin = m_session.getAdminInstance();
                   cls = admin.getAgileClass( "ProblemReport" );
                   IServiceRequest psr = (IServiceRequest)m_session.createObject( "ProblemReport", sr);
              psr.setValue(ServiceRequestConstants.ATT_COVER_PAGE_DESCRIPTION, "KB-Test-20121400");
              } catch (APIException e) {
                   e.printStackTrace();
              } finally {
                   m_session.close();
    Can somebody help me in converting this code into a webservice which accepts String SR as input from soa.
    Thanks,

    Hi Francois,
    I never tried to use a webservice in the value help wizzard, so I don't know if it works or not.
    But for your problem you can build your own value help to avoid the problem.
    You told us that the webservice works in the storyboard. The value help wizard "only" creates a popup iView in your model and assigns the output field of the popup to an input field in a form.
    Maybe as a solution you can insert a popup to the model by yourself. Assign the output field of your popup to the input field for which you want to have the value help. Inside the popup iView you can use your custom built webservice.
    I know that this is a little bit circuitous, but I think it will work.
    Regards
    Christophe

  • Need help with java J2Se 5.0 upgrade 2

    Having problems with Java when playing on Pogo, the Vaults of Atlantis. When loading, I am getting a message that says that I need to remove and download again, java. That it is not working correctly. I did that yesterday, 05/27/05 and am still experiencing the problem but only after signing off from Pogo and AOL and then trying to sign back on again later in the day. I have to shutdown my computer and bring it back up again and then I can load the Vaults of Atlantis. I have noticed that when I do sign-off from Pogo and AOL, that my java cup stays on in my deskbar. Is that supposed to be normal or is it supposed to disappear? If it is supposed to disappear, what can I do to fix that problem?
    Please, can anyone help?

    Go here http://www.java.com/en/ and click "Download Now".
    If that has problems, click the "Manual Download" link and download the "Windows (Offline Installation)".
    If there are problems, review the Help information to resolve.

  • Need help with Java app for user input 5 numbers, remove dups, etc.

    I'm new to Java (only a few weeks under my belt) and struggling with an application. The project is to write an app that inputs 5 numbers between 10 and 100, not allowing duplicates, and displaying each correct number entered, using the smallest possible array to solve the problem. Output example:
    Please enter a number: 45
    Number stored.
    45
    Please enter a number: 54
    Number stored.
    45 54
    Please enter a number: 33
    Number stored.
    45 54 33
    etc.
    I've been working on this project for days, re-read the book chapter multiple times (unfortunately, the book doesn't have this type of problem as an example to steer you in the relatively general direction) and am proud that I've gotten this far. My problems are 1) I can only get one item number to input rather than a running list of the 5 values, 2) I can't figure out how to check for duplicate numbers. Any help is appreciated.
    My code is as follows:
    import java.util.Scanner; // program uses class Scanner
    public class Array
         public static void main( String args[] )
          // create Scanner to obtain input from command window
              Scanner input = new Scanner( System.in);
          // declare variables
             int array[] = new int[ 5 ]; // declare array named array
             int inputNumbers = 0; // numbers entered
          while( inputNumbers < array.length )
              // prompt for user to input a number
                System.out.print( "Please enter a number: " );
                      int numberInput = input.nextInt();
              // validate the input
                 if (numberInput >=10 && numberInput <=100)
                       System.out.println("Number stored.");
                     else
                       System.out.println("Invalid number.  Please enter a number within range.");
              // checks to see if this number already exists
                    boolean number = false;
              // display array values
              for ( int counter = 0; counter < array.length; counter++ )
                 array[ counter ] = numberInput;
              // display array values
                 System.out.printf( "%d\n", array[ inputNumbers ] );
                   // increment number of entered numbers
                inputNumbers++;
    } // end close Array

    Yikes, there is a much better way to go about this that is probably within what you have already learned, but since you are a student and this is how you started, let's just concentrate on fixing what you got.
    First, as already noted by another poster, your formatting is really bad. Formatting is really important because it makes the code much more readable for you and anyone who comes along to help you or use your code. And I second that posters comment that brackets should always be used, especially for beginner programmers. Unfortunately beginner programmers often get stuck thinking that less lines of code equals better program, this is not true; even though better programmers often use far less lines of code.
                             // validate the input
       if (numberInput >=10 && numberInput <=100)
              System.out.println("Number stored.");
      else
                   System.out.println("Invalid number.  Please enter a number within range."); Note the above as you have it.
                         // validate the input
                         if (numberInput >=10 && numberInput <=100)
                              System.out.println("Number stored.");
                         else
                              System.out.println("Invalid number.  Please enter a number within range."); Note how much more readable just correct indentation makes.
                         // validate the input
                         if (numberInput >=10 && numberInput <=100) {
                              System.out.println("Number stored.");
                         else {
                              System.out.println("Invalid number.  Please enter a number within range.");
                         } Note how it should be coded for a beginner coder.
    Now that it is readable, exam your code and think about what you are doing here. Do you really want to print "Number Stored" before you checked to ensure it is not a dupe? That could lead to some really confused and frustrated users, and since the main user of your program will be your teacher, that could be unhealthy for your GPA.
    Since I am not here to do your homework for you, I will just give you some advice, you only need one if statement to do this correctly, you must drop the else and fix the if. I tell you this, because as a former educator i know the first thing running through beginners minds in this situation is to just make the if statement empty, but this is a big no no and even if you do trick it into working your teacher will not be fooled nor impressed and again your GPA will suffer.
    As for the rest, you do need a for loop inside your while loop, but not where or how you have it. Inside the while loop the for loop should be used for checking for dupes, not for overwriting every entry in the array as you currently have it set up to do. And certainly not for printing every element of the array each time a new element is added as your comments lead me to suspect you were trying to do, that would get real annoying really fast again resulting in abuse of your GPA. Printing the array should be in its own for loop after the while loop, or even better in its own method.
    As for how to check for dupes, well, you obviously at least somewhat understand loops and if statements, thus you have all the tools needed, so where is the problem?
    JSG

  • Need help with this Pascal Triangle code....

    Hey everyonr i am totally new to Java... so need your help with this code...
    the function makeRows gives me problems... main is correct ... can someone fix my makeRows... i don't see what's wrong
    public class Pascal {
      /** Return ragged array containing the first nRows rows of Pascal's
       *  triangle.
      public static int[][] makeRows(int nRows) {
            int[][] mpr  = new int[nRows+1][];
            int l=0; int r=0;
            for (int row = 0; row < nRows; row++) {
              mpr[row] = new int[row+1];  //index starts at 0
              if (row==0) {
                mpr[0][0]= 1;
                    if (row==1) {
                mpr[1][0]= 1;
                mpr[1][1]= 1;
              if (row>=2) {
                 for (int j = 0; j <= row; j++) {
                    if (j==0)               {l=0;} else {l=mpr[row-1][j-1];}
                    if (j==mpr[row].length-1) {r=0;} else{r=mpr[row-1][j];}
                    mpr[row][j] = l + r;
            return mpr;
      public static void main(String[] args) {
             if (args.length != 1) {
               System.out.println("usage: java " + Pascal.class.getName() + " N_ROWS");
               System.exit(1);
             int nRows = Integer.parseInt(args[0]);
             if (nRows > 0) {
               int[][] pascal = makeRows(nRows);
               for (int[] row : pascal) {
              for (int v : row) System.out.print(v + " ");
              System.out.println("");
         }this makeRows function should return ragged array containing the first nRows rows of Pascal's triangle
    thanks
    Edited by: magic101 on May 9, 2008 4:03 PM

    magic,
    i think corlettk meant that some people might not know what pascal's triangle is.
    also, you didnt say what was wrong with your code, just that it was wrong.
    asking smart questions is about giving as much information you can to get the
    best answer. i would throw a System.out.print between every line of your
    algorithm. i would also supply us with the values you are getting for each row.
    also, this question is asked all the time here. do a forum search.
    1
    11
    121
    1331
    14641

  • HELP WITH AN OLDER VERSION CODE!!!!!

    I am trying to figure out how to convert a code from an older version into JDK1.3.1_01.
    Please HELP!
    Here is my code............
    mport java.awt.*;
    import java.applet.*;
    public class Race extends Applet {
    private Button myButton; //use a button to start the race.
    int race_square; //record the race square 70.
    int t_square; //record the tortoise's position.
    int h_square; //record the hare's position.
    int clock; //record clock ticks.
    public void init()
    myButton=new Button("Start Clock") ; //add button to the top of panel.
    add("North",myButton);
    reset_v();
    public void reset_v()
    race_square=70; // total squares is 70
    t_square=1; //start point =1
    h_square=1; //start point=1
    clock=0; //reset the clock to zero.
    public void race() {
    int i=0; //set some integer varibles.
    int t_random=0; //random number for tortoise.
    int h_random=0; //random number for hare.
    Graphics g=getGraphics(); //define graphics.
    Rectangle r = bounds(); //define painting boundary.
    g.drawString("BANG !!!!!",100,r.height/2-80);
    g.drawString("AND THEY'RE OFF !!!!!",100,r.height/2-70);
    g.drawString(Integer.toString(clock),r.width/2,50); //show the zero clock time.
    do{
    try { Thread.sleep(1000);} //clock ticks 1 second.
    catch (InterruptedException e){}
    clock++;
    g.setColor(Color.lightGray); //clear all the old drawings
    g.fillRect(0,0,r.width,r.height);
    g.setColor(Color.black);
    g.drawString(Integer.toString(clock),r.width/2,50); //show the clock time.
    t_random=getrandom(); // FOR TORTOISE
    if (t_random<=5) t_square+=3; // 50% fast plod: 3 squares to the right.
    else if (t_random>5 && t_random<=7)t_square-=6; // 20% slip: 6 squares to the left.
    else t_square+=1; // 30% slow plod: 1 square to the right.
    h_random=getrandom(); //FOR HARE
    if (h_random<=2) {} // 20% sleep: not move at all.
    else if (h_random>2 && h_random<=4)h_square+=9;// 20% big hop: 9 squares to the right.
    else if (h_random==5) h_square-=12; // 10% big slip: 12 squares to the left.
    else if (h_random>5 && h_random<=8)h_square+=1;// 30% slow hop: 1 square to the right.
    else h_square-=2; // 20% small slip: 2 aquares to the left.
    if(t_square<=0) t_square=1; //always start from 1.
    if(t_square>race_square)t_square=race_square;
    if(h_square<=0) h_square=1; //always start from 1.
    if(h_square>race_square)h_square=race_square;
    g.setColor(Color.red); //draw the tortoise's path: use red color.
    g.fillRect(5,r.height/2-5,5*t_square,5);
    g.drawString("T",5*t_square,r.height/2-7);
    g.setColor(Color.blue); //draw the hare path: use blue color.
    g.fillRect(5,r.height/2+1,5*h_square,5);
    g.drawString("H",5*h_square,r.height/2+17);
    g.setColor(Color.black); //draw the race squares.
    g.drawLine(5,r.height/2,5+5*race_square,r.height/2);
    for(i=5;i<=5+5*race_square;i+=5)
    g.drawLine(i,r.height/2-5,i,r.height/2+5);
    if (t_square==h_square &&t_square!=race_square) // tortoise bites the hare.
    g.drawString("OUCH!!!",5+5*h_square,r.height/2-16);
    }while ( t_square=race_square && h_square=race_square && t_square<=5+5*race_square;i+=5)
    g.drawLine(i,r.height/2-5,i,r.height/2+5);
    g.drawString("T",5,r.height/2-7); //mark tortoise
    g.drawString("H",5,r.height/2+17); //mark hare
    public int getrandom()
    return( 1+(int)(Math.random()*10)); // generating the random number 1 to 10.
    public boolean action(Event e, Object arg)
    if (e.target instanceof Button)
    reset_v(); //reset the initial variables.
    race(); //use the button the start the race.
    return true;

    You posted this yesterday, at
    http://forum.java.sun.com/thread.jsp?forum=54&thread=185330
    The code you've posted doesn't seem to include Ilikejava's suggested changes - which are, as far as I can tell, the major changes required to bring your applet in line with Java 1.3.
    It will be easier to help if you show what is wrong with your code, if it's generating a compiler error message or throwing an exception.
    Regards,
    -Troy

  • Need Help with Java Homework

    This is my first post here, seeking some help with my java homework. I am required to create a program to write out a receipt for a pizza company: name of company, total number of pizzas, costs (including tax etc), and print out the receipt after taking an order from the customer.
    This is a beginner's java class and my book isn't very good at explaining (mainly because it says "will be discussed in ch 14" when we're in ch 1-3 and it's an essential part of the program).
    But anyways, if anyone is up right now, would be helpful for some help. I have a general idea of what I wanna do, but the program so far is very messy and incomplete and having trouble getting it to look nice and proper.

    well there were two ways of doing this, im only 2 weeks new in java so bear with me.....I was gonna set 3 classes, one appclass, one order form, and one receipt. I was told you can combine the order and receipt in 1 class, but I thought doing 3 woudl be better to help me learn more...anyways, I haven't worked on the appclass yet, but for the order I have a very messy set of codes. I know that it's wrong but it's a start, im looking for any input cause the book does not explain very much.
    For the order class, I will be doing showinputdialog boxes for how many pizzas, the sizes, and the toppings. Here is what I have so far ( i know it is VERY messy and disorganized but I am a bit lost in where I should go next):
    * @author AlexNguyen
    * To take the order with number of pizzas and toppings
    package project2;
    import javax.swing.JOptionPane;
    public class Order {
         public int NumberOfPizzas;
         public char Pepperoni;
         public char Sausage;
         public char Cheese;
         public Order(int n) {
         NumberOfPizzas = n;
         JOptionPane.showInputDialog("Enter Number of Pizzas"));
    String ptype; {
         public void start();
         public void takeOrder();
         public void writeReceipt();
              public void takeOrder();
              ptype = Topping
    public String selectPizza(char P, char S, char C) {
         Pepperoni = P;
         Sausage = S;
         Cheese = C;
    public void numPizza(int numberOfPizzas) {
         num = numberOfPizzas;
    JOptionPane.showInputDialog("Topping for Pizza?");
    JOptionPane.showInputDialog("Pizza Size?");
    JOptionPane.showInputDialog("Number of Pizzas?");
    }

  • Query Help with Item Master & Warehouse Code

    Forum,
    I would like help with a query to identify any items within a database where a particular warehouse code does NOT exist against it. At present I have the following:
    select T0.ItemCode, T1.WhsCode from OITM T0
    INNER JOIN OITW T1 on T0.ItemCode = T1.ItemCode
    where T0.ItemCode NOT IN ('WHS1')
    This is returning all other instance and not just a list of item codes where 'WHS1' is missing from within the 'Stock Data' tab.
    Thanks,
    Sarah

    Hi Sarah...
    Try This
    SELECT T0.ItemCode, T0.ItemName, T1.WhsCode
    FROM OITM T0 INNER JOIN OITW T1 ON T0.ItemCode = T1.ItemCode
    WHERE T1.WhsCode not in ( 'WHS1')
    Regards
    Kennedy

Maybe you are looking for

  • How can I sync with this library without erasing my data?

    The iPod "Sayira's iPod" is synced with another iTunes library. Do you want to erase this iPod and sync with this iTunes library? An iPod can be synced with only one iTunes library at a time. Erasing and syncing replaces the contents of this iPod wit

  • How to export values to a user defined function

    Hi Experts, I want to create a function module under FUNCTION EXIT_SAPMIWO0_020.How to access these values into the called function? I tried it using IMPORT parameters of the called function.But while debugging I am not getting these values. Can any1

  • Software gets stuck

    Final cut pro gets stuck for days in the middle of work. Force quit doesn't solve the problem. It happens every once in a while.

  • Human-friendly interface - allow users to customiz...

    Hello, Starting with the an error I found trying to update "Display" preferences. They seem udpated after I click "Save", but a message is displayed "An Unexpected Error has occurred". Is it possible to make certain links to certain features be selec

  • JDBC/RMI driver does not support BLOB data type

    WLS 5.1 JDBC/RMI driver does not support BLOB data type. It is said in the Weblogic e-doc. I am using DataSource for database connections, meaning JDBC/RMI driver is actually producing database connections. I need several columns of BLOB types in my