NullPointerException in the attack method.

Hi Guys i getting a NullPointerException on the attack() method,i've been trying to figure it out for some hours but i failed.Pls help.
* Intruder.java
* Created on March 2, 2007, 7:31 AM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package org.biyela.security;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.*;
public class Intruder
    private String host_name = "localhost";
    private static final int PORT = 8000;
    private ObjectInputStream objectReader;
    private ObjectOutputStream objectWriter;
    private Socket socket;
    public Intruder()
    public void connect()
        try
                socket = new Socket(host_name,PORT);
                System.out.println("Creating the client socket......");
                objectReader = new ObjectInputStream(socket.getInputStream());
                System.out.println("Opening the input channel for object data.....");
                objectWriter = new ObjectOutputStream(socket.getOutputStream());
                System.out.println("Opening the output channel for object data.....");
                //return true;
        catch(Exception ex)
            ex.printStackTrace();
           // return false;
    public void attack()
            Sender s = new Sender();
            s.setIdentity("Alice");
            s.setSenderChallenge("encryptthis");
            try
                objectWriter.writeObject(s);
                objectWriter.flush();
                objectWriter.close();
                System.out.println("<Intruder Instance>.............");
                System.out.println("Starting reflection attack......");
               // ObjectInputStream objectReader = new ObjectInputStream(socket.getInputStream());
                Sender sender = (Sender)objectReader.readObject();
                System.out.println("Ecrypted challenge:"+sender.getSenderChallenge());
                System.out.println("Bob challenge:"+sender.getReceiverChallenge());
               // sender.setSenderChallenge(sender.getReceiverChallenge());
                //sender.setReceiverChallenge(null);
               // objectWriter.writeObject(sender);
            catch(Exception ioex)
                ioex.printStackTrace();
//    public Object []  handleServerResponse()
//            Object [] objects = null;
//            Object obj = null;
//            int i = 0;
//            try
//                    int length =  objectReader.available();
//                    objects = new Object[length];
//                    while((obj = objectReader.readObject()) != null)
//                            objects[i] = obj;
//                            i++;
//            catch(Exception ex)
//                ex.printStackTrace();
//            return objects;
    public void disconnect()
        try
            //Checking if the client socket is connected
            if(socket != null)
                if(objectReader != null && objectWriter != null)
                    objectReader = null;
                    System.out.println("Closing the object input stream.......");
                    objectWriter = null;
                    System.out.println("Closing the object output stream.......");
                socket = null;
                System.out.println("Closing the client socket......");
           // return true;
        catch(Exception ex)
            ex.printStackTrace();
           // return false;
}

You only have to look at the stack trace to get the line number where the NPE is happening so there's no reason why you can't solve it yourself.
However there are several other problems with your code:
(a) You are closing the object output stream in the attack() method, which will disconnect you completely. Closing an input stream or output stream of a socket closes the other stream and the socket. You should just flush the object output stream here.
(b) You are creating the ObjectInputStream before the ObjectOutputStream. Reverse this, and flush the ObjectOutputStream before you create the ObjectInputStream.
(c) Your disconnect() method doesn't disconnect. It sets things to null instead of closing something. It should close the object output stream. Because of (a), closing anything else is redundant.
(d) Your commented-out code based on using available() to determine the size of an array will never work because available() can't do that, and it can't do too much else either. Just read objects in from the stream until you get an EOFException and put them into some form of a List.

Similar Messages

  • NullPointerException caused by the use of the addDoubleField method

    I develop most of my programs in BreezySwing GUI because I like the simplicity of it compared to AWT. I recently bought a new computer that I wanted to make Java equipped; just like my other two computers. I will get back to that later.
    Before I got a new computer, I made all of my programs on the first computer successfully. One of my most significant ones is a multiple conversion program developed in BreezySwing. After I made it, I wanted to make it runnable on my other computer. Using the BreezySwing jar file, the application's class file, an installed JDK, and a batch file, I now know how to make my programs work on new computers.
    Things changed when I tried to put my program on my newest computer. I moved all the necessary files (except the JDK and BreezySwing; which I downloaded again) from the original computer to my newest one. The first two computers had JDK version 7 while the newest one got JDK version 14. I made all the necessary changes to the batch file for the program (such as changing the classpath for the JDK and the class directory). However, upon running this program, Java throws a NullPointerException. This exception does not occur on either of my two other computers.
    Right away, I was determined to find the cause. I have no idea why the exception occurs, but I do know what part of the code causes the exception. By commenting out parts of a test program, I managed to find out that the use of the addDoubleField method causes the exception because it is thrown when not commented out, but it is not thrown when commented out. Here is the code for the test program:
    application: DFTest.class
    import javax.swing.*;
    import BreezySwing.*;
    class DFTest extends GBFrame {
    JTextField txtFld = addTextField("abcdefg",1,1,1,1);
    DoubleField valueFld = addDoubleField(0.0 ,2,1,1,1); /*this line causes the NullPointerException*/
    static public void main(String[] args){
    DFTest obj = new DFTest();
    obj.setSize(300,100);
    obj.setVisible(true);
    }Both my conversion program and this program use the addDoubleField method. I also tested the BreezySwing variable type DoubleField by seperating it from addDoubleField with a constructor. Java did not throw an exception for the DoubleField variable type.
    What do I need to do to get my programs working again?

    I will give one last detailed synopsis of the problem that I am having. I will do my best to include every detail and make the explanation as useful as possible.
    About a year ago I became interested in Java programming. I was learning it at school but I wanted to continue with it on my own as well. The first time I installed Java was on my first computer. I will call this computer Computer A. The first thing I did was download the JDK that was available at the time. It ended up being jdk1.6.0_07. Then I downloaded JCreator IDE because it was the same IDE that I was familiar with in the classroom. The classroom textbook was The Fundamentals of Java, by Lambert and Osborne. This textbook uses the add-on package BreezySwing which is available from their website. I downloaded whatever version or update that was available at the time. Computer A still has that same download.
    In the classroom I became very familar with BreezySwing to the point where I could use all the methods for it comfortably. During the school year, I ended up using about five different computers. There were no problems with them as far as odd errors go. Every time there was an error, it was clearly the fault of the programmer and easily fixable.
    Back to Computer A: Since almost all of the programs I wanted to write used BreezySwing, it had to be set up properly. After some instructions were given to me from my teacher, I created the PATH environment variable and set it to the location of the BreezySwing documentation; which on Computer A was:
    'C:\Program Files\Java\jdk1.6.0_07\bin'
    Every kind of program that I made on Computer A works perfectly; including my test program mentioned earlier:
    application: DFTest.class
    import javax.swing.*;
    import BreezySwing.*;
    class DFTest extends GBFrame {
    JTextField txtFld = addTextField("abcdefg",1,1,1,1);
    DoubleField valueFld = addDoubleField(0.0 ,2,1,1,1);
    static public void main(String[] args){
    DFTest obj = new DFTest();
    obj.setSize(300,100);
    obj.setVisible(true);
    }By now I was getting good at making programs. Some of them I found very useful, so I wanted to make them into some type of executable file. I became familiar with all of them including .jar and .exe. However, the only one that worked for me was the batch file. I also liked its simplicity. I quickly became good at using them to execute Java bytecode.
    The next thing I wanted to do was put the useful programs I had made on a computer that was in the other room. This computer will be called Computer B. Computer B is much older than Computer A, but still a Windows.
    I knew this computer first needed Java installed on it, so I returned to the Sun download site. This time, the newest Java JDK download was jdk1.6.0_13. I also downloaded jre6 and NetBeans IDE to see if I liked it better than JCreator and to have the option to develop Java on Computer B. Next, I had to download BreezySwing again to Computer B.
    A very odd thing occurred next:
    Upon trying to extract the files of BreezySwing to the proper directory 'C:\Program Files\Java\jdk1.6.0_13\bin', a message came saying that every file in BreezySwing required a password. It also said that all the files in the 'bin' folder (of jdk1.6.0_13) were read-only and it would not let any files be placed there. I still do not know why I did not have this issue with Computer A. I did not know what to do for weeks.
    In the end, I had to copy jdk1.6.0_07 from Computer A to Computer B. It already had BreezySwing in it. However, I was unable to set up NetBeans to work with BreezySwing. Part of the problem was that Computer B is too old and slow for such an advanced program like NetBeans. It was at this point that I started using batch and command prompt entirely to execute all the programs I made or used on Computer B.
    Just like I expected, every type of program I made or put on Computer B worked perfectly.
    About a month ago, I got a third computer; Computer C. By now I knew what I wanted in it so again I returned to the Sun download site. This time, I downloaded jdk1.6.0_14 and nothing else. Both Computer A and Computer B also had jre6; but not Computer C because I saw no need for it if I already had the JDK. I also did not bother with IDEs for Computer C; I just used notepad and command prompt to develop programs.
    The first program I put on Computer C was the one that I had made on Computer A. I already got it to work on Computer B, so I used that knowledge to do everything correctly for Computer C. The program would be executed by batch file which would tell the computer it was interacting with:
    1. The directory of the .class file
    2. The directory of the JDKs bin folder
    3. To include BreezySwing.jar in the execution path (needed to recognize all the methods used in the program)
    Everything about the batch files was correct. An error in the batch file would clearly cause an error not Java related; but rather cmd.exe related.
    After placing the .class file into the directory of all my other .class files (and BreezySwing)
    'C:\Documents and Settings\Java Applications\classes+src',
    I changed the information in the batch file to match the jdk update and match the correct class directory. Upon double clicking the batch file, a NullPointerException was thrown.
    Jump ahead to my test program; DFTest.class. After creating several other test programs to try to isolate the cause of the exception, this is what I found:
    When I attempt to execute the following code (after successful compilation):
    application: DFTest.class
    import javax.swing.*;
    import BreezySwing.*;
    class DFTest extends GBFrame {
    JTextField txtFld = addTextField("abcdefg",1,1,1,1);
    DoubleField valueFld = addDoubleField(0.0 ,2,1,1,1);
    static public void main(String[] args){
    DFTest obj = new DFTest();
    obj.setSize(300,100);
    obj.setVisible(true);
    }My message is too long so I will continue...

  • How to code the ejbCreate() method without initailizing primary key?

    Hi all,
    I've just started learning about EJBs, and now am at the stage of learning how to create, deploy and test a CMP Entity Bean.
    Ran into a problem which I'm hoping someone can help out with.
    I'm using SQL Server 2000 as my backend database, and have created a simple table called TEST with 2 fields, id and name. id is set as the primary key, and as an identity conlumn. What this means is that when we do inserts, we don't need to specify a value for the id column. SQL Servers automatically generates that value.
    Here's my ejbCreate method in my bean class:
    public Integer ejbCreate(String name) throws CreateException {
        this.setName(name);
    }When I tried to run the create method from a web client, I got this error:
    javax.ejb.CreateException: [EJB:010148]In EJB 'SampleEJB', the primary key field 'id' was not set during ejbCreate. All primary key fields must be initialized during ejbCreate. at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:186) at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:284) at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:244) at everbright.ejb.SampleEJB_uzc4wg_HomeImpl_813_WLStub.create(Unknown Source) at jsp_servlet.__index._jspService(__index.java:152) at weblogic.servlet.jsp.JspBase.service(JspBase.java:33) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118) at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661) at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
    So it seems like I can't leave the id field uninitialized in the ejbCreate method. However I don't know what to initialize it with either, because in order to know what value I need to initialize it to, I'll need to run a db query to retrieve the next primary key value for the id field. This doesn't sound very efficient to me.
    I tried to initailize it to null, but that gave me a NullPointerException.
    Why do we need to initialize the primary key field in ejbCreate? Should the container do the insert and then get it from the table accordingly?
    Is there any other way I can get this set-up working?
    Thanks!

    Hi Fusion777,
    Ya, I've been searching around forums for an answer also. Apparently this is indeed a problem that has no general solution. It depends on 2 factors:
    1) Whether or not the database supports autogenerate key (which most does) and how (Oracle does it by sequences while SQL Server by identities)
    2) Whether or not the application server supports 1).
    In my case, I'm using SQL Server and Weblogic Server 8.1 and most fortunately, Weblogic does support identities and sequences. Just define the <auto-key-generation> stanza in your weblogic-cmp-rdbms-jar.xml deployment descriptor, as follows:
    <automatic-key-generation>
         <generator-type>ORACLE</generator-type>
         <generator-name>test_sequence</generator-name>
         <key-cache-size>10</key-cache-size>
    </automatic-key-generation>
    <automatic-key-generation>
         <generator-type>SQL-SERVER</generator-type>
    </automatic-key-generation>
    <automatic-key-generation>
         <generator-type>NAMED_SEQUENCE_TABLE</generator-type>
         <generator-name>MY_SEQUENCE_TABLE_NAME</generator-name>
         <key-cache-size>100</key-cache-size>
    </automatic-key-generation>I've tried that and it works :-)
    I gather from your reply that those who are using JBoss are equally fortunate :-)
    So I thought I'll share this in case some other poor fellow is facing the same problem as we are. At least worse come to worse, he'll have the option of switching to either JBoss or Weblogic and know that it works in both :-)
    Some other users seem to be against the idea of using auto-generated keys for precisely the reason that it is not a standard across database and application servers. See this thread:
    http://forum.java.sun.com/thread.jspa?forumID=13&threadID=329896
    I've in fact stopped working on EJB 2.0 and am exploring something called Hibernate, which seems to have a more generic way of dealing with the auto-generated key issue. In fact, I've heard news that EJB 3.0, which is the upcoming standard for EJB, will be heavily inspired by Hibernate as far as CMP Entity Beans are concerned.
    You can check out Hibernate at http://www.hibernate.org.

  • NullPointerException when mouselistener calls method

    Good Evening,
    I get a java.lang.NullPointerException when a mouselistener calls a method "populatethedatafields()" contained within the class. The populatethedatafields method tries to set the values of text fields and it is at this point the exception occurs. I have tried being more explict in identifying the fields using myclassname.this.textfieldname and this.textfieldname without success. When I moved the settext to within the mouselistener scope, I was able to make the changes.
    Why does this occur?
    I know that I can fix it by putting the settext into the listeners, but that does not seem to be good coding practice. Any suggestions for a good coding practice to solve this type of issue?
    Many thanks for your time.
    Some code removed for clarity and brevity.......
    package EMSBeta1;
    public class ContactInfoViewTEST2 extends JPanel {
    private JTextField textFieldFirstName, textFieldLastName;
    private JPanel custDetails;
    /** Creates new ContactInfoView */
    public ContactInfoViewTEST2(PowerSourceRacingModel model) {
    mod = model;
    cqm = mod.getContactQuery();
    cdt = mod.getContactDetails();
    initComponents();
    public void initComponents() {
    JPanel panel1 = new JPanel();
    JPanel panel2 = new JPanel();
    JPanel detailsPanel = new JPanel();
    double size[][] =
    {{10, -1.0, -1.0, -1.0, -1.0, TableLayout.PREFERRED, 10}, // Columns
    {10, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 10}}; // Rows
    panel1.setBorder(BorderFactory.createTitledBorder("This is a title"));
    BoxLayout layout = new BoxLayout(panel1, BoxLayout.Y_AXIS);
    panel1.setLayout(layout);
    // panel2.setBorder(BorderFactory.createTitledBorder("This is a title"));
    BoxLayout layout2 = new BoxLayout(panel2, BoxLayout.X_AXIS);
    panel2.setLayout(layout2);
    detailsPanel.setBorder(BorderFactory.createTitledBorder("This is a title"));
    detailsPanel.setLayout(new TableLayout(size));
    JLabel labelLastName = new JLabel("Last Name") ;
    final JTextField textFieldLastName = new JTextField("Enter LastName",10);
    JLabel labelFirstName = new JLabel("First Name") ;
    final JTextField textFieldFirstName = new JTextField("FirstName",5);
    textFieldLastName.setNextFocusableComponent(textFieldMembershipNum);
    textFieldMembershipNum.setNextFocusableComponent(textFieldAddress);
    textFieldAddress.setNextFocusableComponent(textFieldEmerContactPhone);
    detailsPanel.add(labelLastName, "1, 1, L, C");
    detailsPanel.add(textFieldLastName, "1, 2, L, T");
    detailsPanel.add(labelFirstName, "3, 1, L, C");
    detailsPanel.add(textFieldFirstName, "3, 2, L, T");
    panel1.add(contactListPane);
    this.setLayout(new BorderLayout());
    add(panel1,BorderLayout.WEST);
    add(panel2,BorderLayout.SOUTH);
    add(detailsPanel,BorderLayout.CENTER);
    MouseListener listMouseListener = new MouseListener() {
    public void mouseClicked(MouseEvent e) {
    public void mouseEntered(MouseEvent e) {
    public void mouseExited(MouseEvent e) {
    public void mousePressed(MouseEvent e) {
    public void mouseReleased(MouseEvent e) {
    createNewContact.setEnabled(true);
    updateButton.setEnabled(true);
    insertNewDataButton.setEnabled(false);
    clearButton.setEnabled(false);
    JList theList = (JList)e.getSource();
    int indexValue = theList.getSelectedIndex();
    System.out.println("This is the selected index from the JList: " + indexValue);
    ContactIdName selectedItem = (ContactIdName)list.getSelectedValue();
    int selectedKey = selectedItem.getKey();
    contactInfo = cdt.getContactDetails(selectedKey);
    populateTheDataFields();
    list.addKeyListener(listKeyListener);
    list.addMouseListener(listMouseListener);
    public void clearFields() {
    textFieldFirstName.setText(null);
    textFieldLastName.setText(null);
    public void populateTheDataFields() {
    String first = (String)contactInfo.get("FIRSTNAME");
    String last = (String)contactInfo.get("LASTNAME");
    this.textFieldFirstName.setText(first);
    this.textFieldLastName.setText(last);
    }

    Ah Ha, Discovered the solution/problem.
    Note that I declared textFieldFirstName and textFieldLastName as class objects with private scope. Then in the initComponents METHOD, I created NEW textFieldFirstName and textFieldLastName objects whose scope is limited only to the method. By prefixing the objects with type, I was creating new instances of the objects rather than "re-using" the class objects. Class objects with appropriate scope are accessible by methods and inner classes. Objects created within a method are not unless the method returns the object.
    Subtle, but basic OO stuff that was a painful lesson. Whew!

  • Do someone know the behaviour of the wrap() method?

    Hi all,
    I'm working with an applet that need R-MAC but no card implements it, so i'm implementing my own secure channel.
    But I want to do it well, so..
    do someone know how the wrap() method is supposed to work?
    I have 2 hypothesis:
    1 - the unwrap() method processing remembers the r-mac state, and then the wrap() method has only to be given the data length, actual data and sw.
    2 - the unwrap() method remembers nothing, so the Response APDU has to be appended to the Command APDU and the whole buffer must be passed to wrap(), which means that the length of the command/response pair must not exceed 256 bytes.
    What do you think is the correct behaviour?

              case INS_INITUPDATE:
                   this.flagBuf[OFFSET_CMAC_FLAG] = CMAC_RECALCULATION_NOT_NEEDED;
                   this.flagBuf[OFFSET_SECURE_CHANNEL_FLAG] = SECURE_CHANNEL_CLOSED;
                   // clear CLEAR_ON_DESELECT data if no SELECT before
                   if(this.flagBuf[OFFSET_SELECT_FLAG] != SELECT_APDU_BEFORE){
                        Util.arrayFillNonAtomic(this.lastCMAC, (short)0, (short)this.lastCMAC.length, (byte)0);
                        Util.arrayFillNonAtomic(this.lastRMAC, (short)0, (short)this.lastCMAC.length, (byte)0);
                        Util.arrayFillNonAtomic(this.icvKeyData, (short)0, (short)this.icvKeyData.length, (byte)0);
                   this.flagBuf[OFFSET_SELECT_FLAG] = OTHER_APDU_BEFORE; 
                   // extract host challenge
                   if(dataLength != LENGTH_OF_HOST_CHALLENGE){
                        ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
                   // create session keys
                   // APDU buffer construction
                   // |0     ...    13|14    ...    29|30   ...   45|
                   // | incoming APDU |derivation data|tmp key value|
                   // ENC-Key
                   Util.arrayCopyNonAtomic(DERIVATION_DATA_ENC_KEY, (short)0, buf, (short)14, (short)2);
                   Util.setShort(buf, (short)16, this.sequenceCounter);
                   this.tmpKey.setKey(this.s_ENC_key, (short)0);
                   this.tmpCipher.init(this.tmpKey, Cipher.MODE_ENCRYPT);
                   this.tmpCipher.doFinal(buf, (short)14, (short)16, buf, (short)30);
                   Util.arrayCopyNonAtomic(buf, (short)30, buf, (short)46, (short)8);
                   this.encKey.setKey(buf, (short)30);
                   // CMAC-Key
                   Util.arrayCopyNonAtomic(DERIVATION_DATA_CMAC_KEY, (short)0, buf, (short)14, (short)2);
                   Util.setShort(buf, (short)16, this.sequenceCounter);
                   this.tmpKey.setKey(this.s_MAC_key, (short)0);
                   this.tmpCipher.init(this.tmpKey, Cipher.MODE_ENCRYPT);
                   this.tmpCipher.doFinal(buf, (short)14, (short)16, buf, (short)30);
                   this.cmacKey.setKey(buf, (short)30);
                   // RMAC-Key
                   Util.arrayCopyNonAtomic(buf, (short)30, this.icvKeyData, (short)0, (short)8);
                   Util.arrayCopyNonAtomic(DERIVATION_DATA_RMAC_KEY, (short)0, buf, (short)14, (short)2);
                   Util.setShort(buf, (short)16, this.sequenceCounter);
                   this.tmpKey.setKey(this.s_MAC_key, (short)0);
                   this.tmpCipher.init(this.tmpKey, Cipher.MODE_ENCRYPT);
                   this.tmpCipher.doFinal(buf, (short)14, (short)16, buf, (short)30);
                   this.rmacKey.setKey(buf, (short)30);
                   // create card cryptogram
                   // APDU buffer construction
                // |30   ...    37|38     ...    39|40   ...    45|46  ...  53| <-- buf
                   // |Host Challenge|Sequence Counter|Card Challenge|DES padding|
                   Util.arrayCopyNonAtomic(buf, (short)5, buf, (short)30, (short)8);
                   Util.setShort(buf, (short)38, this.sequenceCounter);
                   Util.arrayCopyNonAtomic(this.cardChallenge, (short)0, buf, (short)40, (short)6);
                   Util.arrayCopyNonAtomic(DES_PADDING, (short)0, buf, (short)46, (short)8);
                   // we can save time if we reuse the initialized cipher
                   // for the encryption of the card challenge used for verification in EXT-AUTH
                // |0   ...        1|2     ...    8|9   ...     16| <-- swapBuf
                   // |Sequence Counter|Card Challenge|Host Challenge|
                   Util.arrayCopyNonAtomic(buf, (short)38, swapBuf, (short)0, (short)8); // counter + card challenge
                   Util.arrayCopyNonAtomic(buf, (short)30, swapBuf, (short)8, (short)8); // host challenge
                   Util.arrayCopyNonAtomic(DES_PADDING, (short)0, swapBuf, (short)16, (short)8); // DES Padding
                   this.tmpCipher.init(this.encKey, Cipher.MODE_ENCRYPT);
                   this.tmpCipher.doFinal(buf, (short)30, (short)24, buf, (short)4); // card cryptogram
                   this.tmpCipher.doFinal(swapBuf, (short)0, (short)24, swapBuf, (short)0); // host cryptogram
                   // build response APDU
                   // APDU buffer construction
                   // |0         ...        9|         10       | 11|12    ...     13|14    ...   19|20    ...    27|
                   // |Key Diversification Data|Key Version Number|SCP|Sequence Counter|Card Challenge|Card Cryptogram|
                   Util.arrayCopyNonAtomic(this.keyDiversicationData, (short)0, buf, (short)0, (short)10);
                   buf[10] = this.keyVersionNumber;
                   buf[11] = SECURE_CHANNEL_PROTOCOL;
                   Util.setShort(buf, (short)12, this.sequenceCounter);
                   Util.arrayCopyNonAtomic(this.cardChallenge, (short)0, buf, (short)14, (short)6);
                   apdu.setOutgoingAndSend((short)0, (short)28);
                   this.flagBuf[OFFSET_INIT_UPD_FLAG] = INIT_UPD_BEFORE; 
                   break;
              case INS_EXTAUTH:
                   this.flagBuf[OFFSET_SECURE_CHANNEL_FLAG] = SECURE_CHANNEL_CLOSED;
                   if(this.flagBuf[OFFSET_INIT_UPD_FLAG] != INIT_UPD_BEFORE){
                        this.flagBuf[OFFSET_CMAC_FLAG] = CMAC_RECALCULATION_NOT_NEEDED;
                        ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
                   this.flagBuf[OFFSET_INIT_UPD_FLAG] = OTHER_APDU_BEFORE;
                   // CLA BYTE = GP + SM
                   if(buf[ISO7816.OFFSET_CLA] != (byte)0x84){
                        this.flagBuf[OFFSET_CMAC_FLAG] = CMAC_RECALCULATION_NOT_NEEDED;
                        ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
                   // Minimum C_MAC (or CRMAC?)
                   if((buf[ISO7816.OFFSET_P1] & (byte)1) != C_MAC_ONLY) {
                        this.flagBuf[OFFSET_CMAC_FLAG] = CMAC_RECALCULATION_NOT_NEEDED;
                        ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
                   } else if(buf[ISO7816.OFFSET_P1] == C_MAC_ONLY)
                        this.flagBuf[OFFSET_SEC_LEVEL] = C_MAC_ONLY;
                   else if(buf[ISO7816.OFFSET_P1] == C_AND_R_MAC)
                        this.flagBuf[OFFSET_SEC_LEVEL] = C_AND_R_MAC;
                   else {
                        this.flagBuf[OFFSET_CMAC_FLAG] = CMAC_RECALCULATION_NOT_NEEDED;
                        ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
                   if(dataLength != LENGTH_OF_HOSTCRYPTOGRAM_AND_MAC){
                        this.flagBuf[OFFSET_CMAC_FLAG] = CMAC_RECALCULATION_NOT_NEEDED;
                        ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
                   if(!this.encKey.isInitialized()){
                        this.flagBuf[OFFSET_CMAC_FLAG] = CMAC_RECALCULATION_NOT_NEEDED;
                        ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
                   // 1st verify host cryptogram (encrypted card challenge)
                   // swapBuf holds our encrypted challenge, prepared in INIT-UPD
                   if(Util.arrayCompare(buf, ISO7816.OFFSET_CDATA, swapBuf, (short)16, (short)8) != 0){
                        this.flagBuf[OFFSET_SECURE_CHANNEL_FLAG] = SECURE_CHANNEL_CLOSED;
                        ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
                   // 2nd verify CMAC on EXT-AUTH
                   this.verifyCMAC(buf, dataLength);
                   // increment sequence counter to avoid 'Replay Attack'!
                   if(sequenceCounter != (short)0xFFFF)
                        this.sequenceCounter++;
                   // this MAC will be the initial ICV for R-MAC
                   Util.arrayCopyNonAtomic(lastCMAC, (short)0, lastRMAC, (short)0, LENGTH_OF_MAC);
                   this.flagBuf[OFFSET_SECURE_CHANNEL_FLAG] = SECURE_CHANNEL_OPENED;
                   break;
    <next post>

  • How the indexof method is realy implemented

    Can please sombody please help me Iam a student of nottingham university and would like know how the java method indexof(String ) wich searches for a given substring in a string is accually implemented.Well at least how the algorithm works

    Here ya go. This is the actual java implementation of both String indexOf(...) methods, as found in JDK 1.2. Note that the 'count' is an int variable showing the length of the string and the 'value' variable references the actual char[] array that houses the string.
    Hope that helps...
         * Returns the index within this string of the first occurrence of the
         * specified substring. The integer returned is the smallest value
         * <i>k</i> such that:
         * <blockquote><pre>
         * this.startsWith(str, <i>k</i>)
         * </pre></blockquote>
         * is <code>true</code>.
         * @param   str   any string.
         * @return  if the string argument occurs as a substring within this
         *          object, then the index of the first character of the first
         *          such substring is returned; if it does not occur as a
         *          substring, <code>-1</code> is returned.
         * @exception java.lang.NullPointerException if <code>str</code> is
         *          <code>null</code>.
        public int indexOf(String str) {
         return indexOf(str, 0);
         * Returns the index within this string of the first occurrence of the
         * specified substring, starting at the specified index. The integer
         * returned is the smallest value <i>k</i> such that:
         * <blockquote><pre>
         * this.startsWith(str, <i>k</i>) && (<i>k</i> >= fromIndex)
         * </pre></blockquote>
         * is <code>true</code>.
         * <p>
         * There is no restriction on the value of <code>fromIndex</code>. If
         * it is negative, it has the same effect as if it were zero: this entire
         * string may be searched. If it is greater than the length of this
         * string, it has the same effect as if it were equal to the length of
         * this string: <code>-1</code> is returned.
         * @param   str         the substring to search for.
         * @param   fromIndex   the index to start the search from.
         * @return  If the string argument occurs as a substring within this
         *          object at a starting index no smaller than
         *          <code>fromIndex</code>, then the index of the first character
         *          of the first such substring is returned. If it does not occur
         *          as a substring starting at <code>fromIndex</code> or beyond,
         *          <code>-1</code> is returned.
         * @exception java.lang.NullPointerException if <code>str</code> is
         *          <code>null</code>
        public int indexOf(String str, int fromIndex) {
             char v1[] = value;
             char v2[] = str.value;
             int max = offset + (count - str.count);
         if (fromIndex >= count) {
             if (count == 0 && fromIndex == 0 && str.count == 0) {
              /* There is an empty string at index 0 in an empty string. */
              return 0;
             /* Note: fromIndex might be near -1>>>1 */
             return -1;
             if (fromIndex < 0) {
                 fromIndex = 0;
         if (str.count == 0) {
             return fromIndex;
             int strOffset = str.offset;
            char first  = v2[strOffset];
            int i = offset + fromIndex;
        startSearchForFirstChar:
            while (true) {
             /* Look for first character. */
             while (i <= max && v1[i] != first) {
              i++;
             if (i > max) {
              return -1;
             /* Found first character, now look at the rest of v2 */
             int j = i + 1;
             int end = j + str.count - 1;
             int k = strOffset + 1;
             while (j < end) {
              if (v1[j++] != v2[k++]) {
                  i++;
                  /* Look for str's first char again. */
                  continue startSearchForFirstChar;
             return i - offset;     /* Found whole string. */

  • How can we remove the "Attack Site" warning from our webpage?

    We host several domains with Dreamhost. (1st mistake)
    Our account was hacked and is being resolved.
    We have taken our site down.
    When searching our url, our prospective customers will see an Explorer message which reads a Dreamhost message stating this website has been "voluntarily parked". Site coming soon.
    In Firefox, the Attack Site message in red is still showing. Can you please remove the message as our website is not available for public viewing?
    Thank you.
    RJ

    I get a status 200 with a message from the site that it is under construction. If I am using the correct URL (www.usana2013.co.za) maybe you need to clear your Firefox cache.
    The database of attack & phishing sites is not directly maintained by Firefox.
    See also
    *http://www.mozilla.org/en-US/firefox/phishing-protection/firefox2/
    *http://www.mozilla.org/en-US/firefox/features/#advancedsecurity
    *http://en.wikipedia.org/wiki/Google_Safe_Browsing
    ** http://www.google.com/tools/firefox/safebrowsing/
    **http://safebrowsing.clients.google.com/safebrowsing/diagnostic?client=Firefox&hl=en-US&site=http://www.usana2013.co.za

  • I cannot figure out how to make the text larger on an incoming email.  The finger method doesn't work and I cannot find any toolbar with which to do it.  I could find nothing in settings also.  Plese help and thank you.

    I cannot figure out how to make the text larger in a received email.  The finger method doesn't work and I can find no tool bar as I can for composing emails.  I can find nothing in settings.  Please help and thank you in advance.

    Hi there,
    Download a piece of software called TinkerTool - that might just solve your problem. I have used it myself to change the system fonts on my iMac. It is software and not an app.
    Good wishes,
    John.

  • Calling the Java Method in PL/SQL Java Stored procedure errors out

    Hi,
    I could not find a suitable thread to post my PL/SQL question so iam posting it here.........
    I have written a java class by name XYZ which has a method ABC for which there are 9 arguements being passed and its a VOID method.
    This java class has been loaded into ORACLE using DBMS_JAVA.LOADJAVA pkg, Now this class is being called in the oracle as a JAVA Stored procedure...... When ever im trying to call the procedure it throws the following error
    ORA-29531: no method
    *Cause:    An attempt was made to execute a non-existent method in a
    Java class.
    *Action:   Adjust the call or create the specified method.
    The code snippet as follows
    JAVA CODE:
    Class xyz
    public static void Abc (String hostName,
    int port,
    String serviceURL,
    String soapAction,
    int timeOut,
    String wsUser,
    String wsPasWd,
    String keyStore,
    String keyStorePasWd)
    //method implementation
    JAVA STORED PROCEDURE:
    create OR REPLACE procedure ABC_JAVA_SP_CALL
    (p_hostname in varchar2, p_port in number, p_serviceurl in varchar2, p_soapaction in varchar2, p_timeout in number, p_wsuser in varchar2, p_wspasswd in varchar2, p_ks_path in varchar2, p_ks_passwd in varchar2)
    as
    language java
    name 'xyz.Abc(java.lang.String, int, java.lang.String, java.lang.String, int, java.lang.String, java.lang.String, java.lang.String, java.lang.String)';
    When i try to call
    declare
    p_hostname varchar2(100);
    p_port number;
    p_serviceurl varchar2(100);
    p_soapaction varchar2(100);
    p_timeout number;
    p_wsuser varchar2(100);
    p_wspasswd varchar2(100);
    p_ks_path varchar2(100);
    p_ks_passwd varchar2(100);
    begin
    //SP which returns the values for the required parameters.
    comppkg.getvcsinfo(
    p_hostname,
    p_port ,
    p_serviceurl,
    p_soapaction,
    p_timeout,
    p_wsuser,
    p_wspasswd,
    p_ks_path,
    p_ks_passwd
    Layer7_icengc_ws_tes(p_hostname,
    p_port ,
    p_serviceurl,
    p_soapaction,
    p_timeout,
    p_wsuser,
    p_wspasswd,
    p_ks_path,
    p_ks_passwd);
    end;
    This thing ends up with
    29531. 00000 - "no method %s in class %s"
    *Cause:    An attempt was made to execute a non-existent method in a
    Java class.
    *Action:   Adjust the call or create the specified method.
    Im not understanding what wrong am i doing
    pls help
    Edited by: madhusudan on Feb 12, 2013 8:07 PM

    Hello,
    there is the forum {forum:id=65} for questions about using Java within Oracle.
    Regards
    Marcus
    Edited by: Marwim on 13.02.2013 07:56
    I could not find a suitable thread to post my PL/SQL question so iam posting it here.........You got the hint to the correct forum alread in another thread {message:id=10837976}
    And if you think this is not related to Java but PL/SQL, then you should ask in {forum:id=75}

  • How do I use the find method to find multiple items in a single paragraph?

    I am desigining a script to find any instances where ctrl+b and ctrl+i are applied to body text and then replace those character format overrides with Italic or Bold chartag.  Here's what the script is supposed to do:
    put the find method in a while loop that searches for character format overrides.
    If a character format override is found, pass the text range returned by the find method and the CharPropsChange flag to the GetTextForRange method.
    Use a boolean compare between the idata of the text item to the character angle and character weight constants.
    Whichever boolean evaluates to true, then use the SetTextProp method to set properties of the text range to the properties of the italic or bold character tag.
    This script does work on the first character format override found however it ignores any other overrides in the same paragraph. The cause of this is that the while loop updates the text loc that the find method uses to the next paragraph in flow. I suspect that i need to add an inner loop that goes through all the text in a single paragraph, where at teach iteration the text loc used by the find method is based on the same paragraph but the offset is modified. I am just not sure how to do that.
    function removeOverrides (pDoc)
        var vDocStart = pDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
        var vBoldFmt=getCharFmt (pDoc, 'Bold')
        var vItalicFmt=getCharFmt (pDoc, 'Italic')
        initFA_errno ();
        while (FA_errno==Constants.FE_Success)
            var vTextLoc = new TextLoc(vDocStart,0);
            var vFindParams=findOverrideParams (pDoc);
            var vTextRange=pDoc.Find(vTextLoc,vFindParams);
            if (vTextRange.beg.obj.ObjectValid())
                var vTextItems=pDoc.GetTextForRange (vTextRange, Constants.FTI_CharPropsChange)
                if (vTextItems.length==!0 )
                    if (vTextItems[0].idata==Constants.FTF_WEIGHT)
                       pDoc.SetTextProps (vTextRange, vBoldFmt.GetProps())
                    if (vTextItems[0].idata==Constants.FTF_ANGLE)
                       pDoc.SetTextProps (vTextRange, vItalicFmt.GetProps())
                    } else (Log (vLogFileName, '\nERROR: No items were found in the text format array but format override was found: '+pDoc.Name))
            vDocStart=vDocStart.NextPgfInFlow;
    function findOverrideParams (pDoc)
        var vFindParams = AllocatePropVals(1);
        vFindParams[0].propIdent.num = Constants.FS_FindObject;
        vFindParams[0].propVal.valType = Constants.FT_Integer;
        vFindParams[0].propVal.ival = Constants.FV_FindCharacterFormatOverride;
       return vFindParams;

    Hi Rick,
    Well, following up on the previous posting, I actually did figure out how to make it work but it seems rather inefficient. I can insert a new paragraph right after the paragraph that has the table anchor but when i cut the table, i also cut the paragraph i just created. So to get around that, I create two paragraphs, so that there will be one paragraph left after i do the cut and that is the paragraph that I paste the table into. Once the table is pasted into the new paragraph, I delete the other paragraph that I created.
    Here's the updated code from the for loop:
    var vTbl = vDoc.GetUniqueObject(Constants.FO_Tbl, vTextItems[i].obj.Unique);                 
    var vAnchorPgf=vDoc.NewSeriesPgf (vTbl.TextLoc.obj)      
    var vAnchorPgf2=vDoc.NewSeriesPgf (vAnchorPgf);        
    var vAnchorTextLoc=new TextLoc (vAnchorPgf2, 0);             
    var vTblTextRange=new TextRange ();        
    vTblTextRange.beg.obj=vTbl.TextLoc.obj;       
    vTblTextRange.beg.offset = vTbl.TextLoc.offset;        
    vTblTextRange.end.obj=vTbl.TextLoc.obj;        
    vTblTextRange.end.offset = Constants.FV_OBJ_END_OFFSET                 
    vDoc.TextSelection=vTblTextRange;        
    vDoc.Cut (0);                
    vTblTextRange.beg.obj=vAnchorTextLoc.obj;        
    vTblTextRange.beg.offset = 0;              
    vTblTextRange.end.obj=vAnchorTextLoc.obj;       
    vTblTextRange.end.offset =0;                 
    vDoc.TextSelection=vTblTextRange;       
    vDoc.Paste (0);                   
    vAnchorPgf2.Delete();        

  • HT1414 having bought a new MacBook, I wanted to Sync my iPhone4 to it, but it insists the only method to do so is to "Erase and Sync" or "Cancel" which leaves no option to just use iTunes on the new MacBook Pro - how annoying is that???

    I have had the iphone4 for 2 years now and I bought a new MacBook Pro, opened iTunes and it knew I already had other machines with iTunes sync'ed with it but it still insisted on offering one option or sync'ing with new MacBook - "Erase and Sync", which means deleting EVERYTHING on the iphone. What if I want my iPhone to dictate and get iTunes on the Macbook to match up with the iPhone??? Or at least get iTunes to relate to what my iTunes account obviously has on it and update that way. Come on Apple, as per usual, very pretty but not very practical!!!

    You can only sync everything with your one syncing computer/iTunes library. Yu can:
    - Make this your syncing computer by:
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive: Apple Support Communities
    - Use the manual method to copy music and videos from any computer/iTunes library to the iPod. See the manual method included here:
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive: Apple Support Communities

  • How to create the custom method and make it available to clients:

    Hello, Can any one help me with this problem ASAP??
    I am trying to work on an example of "Customizing the Query and Creating an Associated Custom Method"
    from http://helponline.oracle.com/jdeveloper/help/topics/jdeveloper/developing_mvc_applications/adf_pviewcustommethod.html?tp=true#method. To do that, the first task is to create the custom method and make it available to clients.
    Following instructions in the helponline documentation, I completed the three steps: (1) "Specify a custom query for the View Object definition for EmployeesView", (2) "Add the custom method to the application module Java class", and (3) "Make the method available to clients".
    The following is the error message I got to test the application module. Can anyone tell me what the message really means and what I should do. I am wondering if there is any mistakes in the document.
    (oracle.jbo.SQLStmtException) JBO-27122: SQL error during statement preparation. Statement: SELECT Employees.EMPLOYEE_ID, Employees.FIRST_NAME, Employees.LAST_NAME, Employees.EMAIL, Employees.PHONE_NUMBER, Employees.HIRE_DATE, Employees.JOB_ID, Employees.SALARY, Employees.COMMISSION_PCT, Employees.MANAGER_ID, Employees.DEPARTMENT_ID FROM EMPLOYEES Employees WHERE Employees.SALARY > :1 and Employees.DEPARTMENT_ID = :2
    ----- LEVEL 1: DETAIL 0 -----
    (java.sql.SQLException) ORA-01008: not all variables bound

    You need to set values for the parameters in your query before you try to execute the query in the view object.
    So you need to call the setBindVars method before the query.

  • How to override the create method invoked by a create form?

    Hello everyone, I'm using ADF Faces and have the next question:
    How can I override the create method which is invoked by a create form to preset an attribute in the new row (the preset value is not fixed, I have to send it to the method as a parameter as it is obtained using an EL expression)?
    In the ADF guide I read how to override a declarative method (Section 17.5.1 How to override a declarative method), but this explains how to do it with a method that is called by a button. I don't know how to do the same with a method which is called automatically when the page is loaded.
    I also tried overriding the view object's createRow() method to receive a parameter with the preset values but it didn't work, I believe that was because the declarative create method is not the same as the view object's createRow. This caused the form to display another row from the viewobject and not the newly created one (I also set the new row into STATUS_INITIALIZED after setting the attribute).
    Well, I hope my problem is clear enough for somebody to help me.
    Thank you!

    Hello,
    I'm not sure you can do it with standard generated Create Form.
    In your view object you'll need to create your own create method with parameters, publish it to client interface and invoke instead of standard generated create action in page definition.
    Rado

  • There is no printer output when using the PrintOut method

    I have a VB6 app with CR XI, and a customer found a situation that when printing a report directly to the printer using the PrintOut method, there is no printer output or error message.
    Some reports using the same code print normally, but a report that is preceded by another print call, presents this behavior.
    And when the output is directed to the screen, we can see the report.
    Could someone give me an idea of what is the problem?
    Thanks,
    Isis
    SP - Brazil
    The code used is below:
                       Set rpt = applic.OpenReport(App.Path & "SEFoto" + TipoRPT + ".rpt")
                       rpt.FormulaSyntax = crCrystalSyntaxFormula
                       rpt.FormulaFields.GetItemByName("Empresa").Text = "'" + Company + "'"
                       rpt.FormulaFields.GetItemByName("Idioma").Text = "'" + Idioma + "'"
                       rpt.FormulaFields.GetItemByName("Versao").Text = "'" + Versao + "'"
                       ' ... Some lines to compose the selection formula
                       rpt.RecordSelectionFormula = Cond
                       ' To evaluate the image length:
                       Arq = rsTMP3!FT_Arquivo
                       ImageScaling = FatorDeReducao(Arq, "F")
                       ' To reduce the image length:
                       AchouOLE = False
                       For Each oSection In rpt.Sections
                           For Each oObject In oSection.ReportObjects
                               If oObject.Name = "PictureFoto" Then
                                  Set oOleObject = oObject
                                  AchouOLE = True
                                  Exit For
                               End If
                           Next oObject
                           If AchouOLE Then Exit For
                       Next oSection
                       With oOleObject
                            .Suppress = True
                            .XScaling = ImageScaling    ' 0.5 = 50%, 1 = 100%
                            .YScaling = ImageScaling
                            .Suppress = False
                       End With
                       Aguarde.Show 1
                       If DestinoRel = 9 Or DestinoRel = 1 Then ' Padrão ou impressora
                          rpt.PrintOut True              ' <<<---- Here using true or false nothing happens
                       Else
                          PrintRPTtela rpt, "Fotos"   ' <<<--- Here it works fine
                       End If

    Hi Isis,
    Not sure if you have applied any service Packs to CR? If please do so and test again. Then you can upgrade to CR XI R2 for free, use your XI Keycode and download Service Pack 4 from this link:
    https://smpdl.sap-ag.de/~sapidp/012002523100011802732008E/crxir2_sp4_full_build.exe
    You'll find the distribution files for your app also from that same download area.
    If you don't want to upgrade to XI R2 then download all patches from XI and test again. This issues rings a bell that it may have been fixed.
    Thank you
    Don

  • Is there a way to run part of the Pain() method once?

    I'm working on a paint program.
    I'm using AWT and Applet supplied by Java, and in the Paint method I have it drawing the UI and checking to see if this or that has been clicked to change color. Problem is, the Paint method is always running, and so the UI is always being redrawn, and so the color is always black, which is the last color to be changed.
    So, is there any way I can have it stop drawing the UI, and just checking the colors? Or is there another method to use to put the UI code in?
    Here's the code:
    // CiPaint
    // Version 0.2
    // Programmed and Designed by Paul Adamski
    // This program is inflexible and exhibits poor design
    // ZOMG!!
    // TODO:     80% -      Changing colors
    import java.awt.*;
    import java.applet.*;
    public class CiPaint extends Applet
         Rectangle red, green, blue, purple, black, white, yellow;
         Color backgroundColor, eraseColor, currentColor;
         int numColor;
         Image virtualMem;
         Graphics gBuffer;
         int oldX, oldY, newX, newY;
         int appletWidth;          
         int appletHeight;
         public void init()
              backgroundColor = Color.white;
              eraseColor = Color.black;
              red = new Rectangle(10,10,25,25);
              green = new Rectangle(40,10,25,25);
              blue = new Rectangle(70,10,25,25);
              purple = new Rectangle(100,10,25,25);
              yellow = new Rectangle(130,10,25,25);
              black = new Rectangle(160,10,25,25);
              white = new Rectangle(85,40,25,25);
              numColor = 0;
              appletWidth = getWidth();
              appletHeight = getHeight();     
              virtualMem = createImage(appletWidth,appletHeight);
              gBuffer = virtualMem.getGraphics();
              //gBuffer.setColor(Color.white); Makes screen flicker
              //gBuffer.setColor(Color.red); Makes whole right side of menu screen red
              gBuffer.fillRect(200,0,appletWidth-200,appletHeight);
         public void paint(Graphics g)
              // Draws the borders and UI     
              g.drawLine(200,0,200,600);
              g.drawLine(1,1,800,1);
              g.drawLine(800,1,800,600);
              g.drawLine(800,600,1,600);
              g.drawLine(1,600,1,1);
              g.setColor(Color.red);
              g.fillRect(10,10,25,25);
              g.setColor(Color.green);
              g.fillRect(40,10,25,25);
              g.setColor(Color.blue);
              g.fillRect(70,10,25,25);
              g.setColor(Color.magenta);
              g.fillRect(100,10,25,25);
              g.setColor(Color.yellow);
              g.fillRect(130,10,25,25);
              g.setColor(Color.black);     // This line unwantingly is the drawing color
              g.fillRect(160,10,25,25);     // This whole section is repeatidly called, it only should be called ONCE
              g.drawRect(85,40,25,25);
              // End Drawing
              switch (numColor)
                   case 1:
                        g.setColor(Color.red);
                        currentColor = Color.red;
                        System.out.println("ITS RED NUBCAKE");
                        break;
                   case 2:
                        g.setColor(Color.green);
                        currentColor = Color.green;
                        break;
                   case 3:
                        g.setColor(Color.blue);
                        currentColor = Color.blue;
                        break;
                   case 4:
                        g.setColor(Color.magenta);
                        currentColor = Color.magenta;
                        break;
                   case 5:
                        g.setColor(Color.yellow);
                        currentColor = Color.yellow;
                        break;
                   case 6:
                        g.setColor(Color.black);
                        currentColor = Color.black;
                        break;
                   case 7:
                        g.setColor(Color.white);
                        currentColor = Color.white;
                        break;
                   case 8:
                        break;
              // Works, but doesn't change color
              if (oldX > 200)
                        g.fillRect(oldX,oldY,2,2);
                        //g.drawImage(virtualMem,0,0,this);     
              /*UBER Flicker and doesn't even draw
              if (oldX > 200)
                        gBuffer.fillRect(oldX,oldY,2,2);
                        g.drawImage(virtualMem,0,0,this);     
         public boolean mouseDown(Event e, int x, int y)
              if(red.inside(x,y))
                   numColor = 1;
              else if(green.inside(x,y))
                   numColor = 2;
              else if(blue.inside(x,y))
                   numColor = 3;
              else if(purple.inside(x,y))
                   numColor = 4;
              else if(yellow.inside(x,y))
                   numColor = 5;
              else if(black.inside(x,y))
                   numColor = 6;
              else if(white.inside(x,y))
                   numColor = 7;
              else
                   numColor = 8;
              newX = x;
              newY = y;
              oldX = newX;
              oldY = newY;
              repaint();
              return true;
         public boolean mouseDrag(Event e, int x, int y)
              newX = x;
              newY = y;
              oldX = newX;
              oldY = newY;
              repaint();
              return true;
         public void update(Graphics g)
              paint(g);
    }

    You have only to move your switch block from paint method to mouseDown method: in this way you first assign correct value to currentColor variable.... then pain method will use the color you have already set.
    Notice that methods mouseDown and mouseDrag are deprecated: you should better use processMouseEvent and processMouseMotionEvent methods (see documentation of class Component to more details.
    Below the implementation I tried.
    Bye
    Diego
    import java.awt.*;
    import java.applet.*;
    public class CiPaint extends Applet
         Rectangle red, green, blue, purple, black, white, yellow;
         Color backgroundColor, eraseColor, currentColor;
         int numColor;
         Image virtualMem;
         Graphics gBuffer;
         int oldX, oldY, newX, newY;
         int appletWidth;          
         int appletHeight;
         public void init()
              backgroundColor = Color.white;
              eraseColor = Color.black;
              red = new Rectangle(10,10,25,25);
              green = new Rectangle(40,10,25,25);
              blue = new Rectangle(70,10,25,25);
              purple = new Rectangle(100,10,25,25);
              yellow = new Rectangle(130,10,25,25);
              black = new Rectangle(160,10,25,25);
              white = new Rectangle(85,40,25,25);
              numColor = 0;
              appletWidth = getWidth();
              appletHeight = getHeight();     
              virtualMem = createImage(appletWidth,appletHeight);
              gBuffer = virtualMem.getGraphics();
              //gBuffer.setColor(Color.white); Makes screen flicker
              //gBuffer.setColor(Color.red); Makes whole right side of menu screen red
              gBuffer.fillRect(200,0,appletWidth-200,appletHeight);
         public void paint(Graphics g)
              // Draws the borders and UI     
              g.drawLine(200,0,200,600);
              g.drawLine(1,1,800,1);
              g.drawLine(800,1,800,600);
              g.drawLine(800,600,1,600);
              g.drawLine(1,600,1,1);
              g.setColor(Color.red);
              g.fillRect(10,10,25,25);
              g.setColor(Color.green);
              g.fillRect(40,10,25,25);
              g.setColor(Color.blue);
              g.fillRect(70,10,25,25);
              g.setColor(Color.magenta);
              g.fillRect(100,10,25,25);
              g.setColor(Color.yellow);
              g.fillRect(130,10,25,25);
              g.setColor(Color.black);     // This line unwantingly is the drawing color
              g.fillRect(160,10,25,25);     // This whole section is repeatidly called, it only should be called ONCE
              g.drawRect(85,40,25,25);
              // End Drawing
    //          switch (numColor)
    //               case 1:
    //                    g.setColor(Color.red);
    //                    currentColor = Color.red;
    //                    System.out.println("ITS RED NUBCAKE");
    //                    break;
    //               case 2:
    //                    g.setColor(Color.green);
    //                    currentColor = Color.green;
    //                    break;
    //               case 3:
    //                    g.setColor(Color.blue);
    //                    currentColor = Color.blue;
    //                    break;
    //               case 4:
    //                    g.setColor(Color.magenta);
    //                    currentColor = Color.magenta;
    //                    break;
    //               case 5:
    //                    g.setColor(Color.yellow);
    //                    currentColor = Color.yellow;
    //                    break;
    //               case 6:
    //                    g.setColor(Color.black);
    //                    currentColor = Color.black;
    //                    break;
    //               case 7:
    //                    g.setColor(Color.white);
    //                    currentColor = Color.white;
    //                    break;
    //               case 8:
    //                    break;
                    g.setColor(currentColor);
              // Works, but doesn't change color
              if (oldX > 200)
                        g.fillRect(oldX,oldY,2,2);
                        //g.drawImage(virtualMem,0,0,this);     
              /*UBER Flicker and doesn't even draw
              if (oldX > 200)
                        gBuffer.fillRect(oldX,oldY,2,2);
                        g.drawImage(virtualMem,0,0,this);     
         public boolean mouseDown(Event e, int x, int y)
              if(red.inside(x,y))
                   numColor = 1;
              else if(green.inside(x,y))
                   numColor = 2;
              else if(blue.inside(x,y))
                   numColor = 3;
              else if(purple.inside(x,y))
                   numColor = 4;
              else if(yellow.inside(x,y))
                   numColor = 5;
              else if(black.inside(x,y))
                   numColor = 6;
              else if(white.inside(x,y))
                   numColor = 7;
              else
                   numColor = 8;
              newX = x;
              newY = y;
              oldX = newX;
              oldY = newY;
              switch (numColor)
                   case 1:
                        currentColor = Color.red;
                        System.out.println("ITS RED NUBCAKE");
                        break;
                   case 2:
                        currentColor = Color.green;
                        break;
                   case 3:
                        currentColor = Color.blue;
                        break;
                   case 4:
                        currentColor = Color.magenta;
                        break;
                   case 5:
                        currentColor = Color.yellow;
                        break;
                   case 6:
                        currentColor = Color.black;
                        break;
                   case 7:
                        currentColor = Color.white;
                        break;
                   case 8:
                        break;
              repaint();
              return true;
         public boolean mouseDrag(Event e, int x, int y)
              newX = x;
              newY = y;
              oldX = newX;
              oldY = newY;
              repaint();
              return true;
         public void update(Graphics g)
              paint(g);
    }

Maybe you are looking for

  • Trying to install the new version of iTunes 10.3 on a windows 7 64 bit machine.

    It is unable to install because of the following error "COULD NOT ACCESS NETWORK LOCATION %APPDATA%\.  Any suggestions would be helpful.

  • Problems with content conversion in File Receiver Adapter

    Hello, everybody.     I have a RFC-to-File scenario with file content conversion. Everything is working well except that my file is generated with 2 blank lines at the top of it.     The function module has 3 importing parameters (1 optional) and the

  • How do I get the reply, forward to come up in my emails?

    I just got my i phone and when I recieve an e mails I cannot reply or forward them because it does not come up on the bottom of the e mail, like it did with my 4. Can anyone tell me how to make this come up?  I am freaking out.  I have to return so m

  • Changing a user name

    I've just got a used MacBook Pro and when I open Users folder it's got a user called "greg" with the little home icon. It contains the usual folders: Pictures, Documents, Library, Music etc. , It's not listed on the accounts page of system preference

  • Unable to backup to iCloud

    We're are using a family-style system with iCloud, so we all share photo stream and back up etc. My wifes's and my iPhones and iPads both are backing up fine to iCloud, but our daughter's (which are iPad 1s) fail each time I select that option under