Java - Write And Read From memory Like CheatEngine ( Writing not working?)

Hello Oracle Forum
I came here some time ago to ask about javaFX , i solved all my issues and im right now waiting for javaFx tot ake over swing and hmm, im working on learning LIBGDX to create games in java.
However, im in need to create an app to change values of memory to fix a bug in an old program that i have, and the only way until now is using cheatEngine, So i decided to take a tutorial and learn how to do that in java.
Well, im able to read from the memory but the write isnt working somehow... Im posting the code here, if anyone can give me a hint, i would thank and a lot, because theres a community that really needs this app to automate the fix without using cheat engine.
package MainStart;
import com.br.HM.User32;
import com.br.kernel.Kernel32;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
public class Cheater {
    static Kernel32 kernel32 = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
    static User32 user32 = (User32) Native.loadLibrary("user32", User32.class);
    static int readRight = 0x0010;
    static int writeRight = 0x0020;
    //static int PROCESS_VM_OPERATION = 0x0008;
    public static void main(String[] args) {
        //Read Memory
        //MineSweeper = Campo Minado
        int pid = getProcessId("Campo Minado"); // get our process ID
        System.out.println("Pid = " + pid);
        Pointer readprocess = openProcess(readRight, pid); // open the process ID with read priviledges.
        Pointer writeprocess = openProcess(writeRight, pid);
        int size = 4; // we want to read 4 bytes
        int address = 0x004053C8;
        //Read Memory
        Memory read = readMemory(readprocess, address, size); // read 4 bytes of memory starting at the address 0x00AB0C62.
        System.out.println(read.getInt(0)); // print out the value!      
        //Write Memory
        int writeMemory = writeMemory(writeprocess, address, new short[0x22222222]);
        System.out.println("WriteMemory :" + writeMemory);
        Memory readM = readMemory(readprocess, address, size);
        System.out.println(readM.getInt(0));
    public static int writeMemory(Pointer process, int address, short[] data) {
        IntByReference written = new IntByReference(0);
        Memory toWrite = new Memory(data.length);
        for (long i = 0; i < data.length; i++) {
            toWrite.setShort(0, data[new Integer(Long.toString(i))]);
        boolean b = kernel32.WriteProcessMemory(process, address, toWrite, data.length, written);
        System.out.println("kernel32.WriteProcessMemory : " + b); // Retorna false
        return written.getValue();
    public static Pointer openProcess(int permissions, int pid) {
        Pointer process = kernel32.OpenProcess(permissions, true, pid);
        return process;
    public static int getProcessId(String window) {
        IntByReference pid = new IntByReference(0);
        user32.GetWindowThreadProcessId(user32.FindWindowA(null, window), pid);
        return pid.getValue();
    public static Memory readMemory(Pointer process, int address, int bytesToRead) {
        IntByReference read = new IntByReference(0);
        Memory output = new Memory(bytesToRead);
        kernel32.ReadProcessMemory(process, address, output, bytesToRead, read);
        return output;
package com.br.HM;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.platform.win32.WinDef.RECT;
import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.StdCallLibrary.StdCallCallback;
import com.sun.jna.win32.W32APIOptions;
* Provides access to the w32 user32 library. Incomplete implementation to
* support demos.
* @author Todd Fast, [email protected]
* @author [email protected]
public interface User32 extends W32APIOptions {
    User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class, DEFAULT_OPTIONS);
    Pointer GetDC(Pointer hWnd);
    int ReleaseDC(Pointer hWnd, Pointer hDC);
    int FLASHW_STOP = 0;
    int FLASHW_CAPTION = 1;
    int FLASHW_TRAY = 2;
    int FLASHW_ALL = (FLASHW_CAPTION | FLASHW_TRAY);
    int FLASHW_TIMER = 4;
    int FLASHW_TIMERNOFG = 12;
    public static class FLASHWINFO extends Structure {
        public int cbSize;
        public Pointer hWnd;
        public int dwFlags;
        public int uCount;
        public int dwTimeout;
    int IMAGE_BITMAP = 0;
    int IMAGE_ICON = 1;
    int IMAGE_CURSOR = 2;
    int IMAGE_ENHMETAFILE = 3;
    int LR_DEFAULTCOLOR = 0x0000;
    int LR_MONOCHROME = 0x0001;
    int LR_COLOR = 0x0002;
    int LR_COPYRETURNORG = 0x0004;
    int LR_COPYDELETEORG = 0x0008;
    int LR_LOADFROMFILE = 0x0010;
    int LR_LOADTRANSPARENT = 0x0020;
    int LR_DEFAULTSIZE = 0x0040;
    int LR_VGACOLOR = 0x0080;
    int LR_LOADMAP3DCOLORS = 0x1000;
    int LR_CREATEDIBSECTION = 0x2000;
    int LR_COPYFROMRESOURCE = 0x4000;
    int LR_SHARED = 0x8000;
    Pointer FindWindowA(String winClass, String title);
    int GetClassName(Pointer hWnd, byte[] lpClassName, int nMaxCount);
    public static class GUITHREADINFO extends Structure {
        public int cbSize = size();
        public int flags;
        Pointer hwndActive;
        Pointer hwndFocus;
        Pointer hwndCapture;
        Pointer hwndMenuOwner;
        Pointer hwndMoveSize;
        Pointer hwndCaret;
        RECT rcCaret;
    boolean GetGUIThreadInfo(int idThread, GUITHREADINFO lpgui);
    public static class WINDOWINFO extends Structure {
        public int cbSize = size();
        public RECT rcWindow;
        public RECT rcClient;
        public int dwStyle;
        public int dwExStyle;
        public int dwWindowStatus;
        public int cxWindowBorders;
        public int cyWindowBorders;
        public short atomWindowType;
        public short wCreatorVersion;
    boolean GetWindowInfo(Pointer hWnd, WINDOWINFO pwi);
    boolean GetWindowRect(Pointer hWnd, RECT rect);
    int GetWindowText(Pointer hWnd, byte[] lpString, int nMaxCount);
    int GetWindowTextLength(Pointer hWnd);
    int GetWindowModuleFileName(Pointer hWnd, byte[] lpszFileName, int cchFileNameMax);
    int GetWindowThreadProcessId(Pointer hWnd, IntByReference lpdwProcessId);
    interface WNDENUMPROC extends StdCallCallback {
         * Return whether to continue enumeration.
        boolean callback(Pointer hWnd, Pointer data);
    boolean EnumWindows(WNDENUMPROC lpEnumFunc, Pointer data);
    boolean EnumThreadWindows(int dwThreadId, WNDENUMPROC lpEnumFunc, Pointer data);
    boolean FlashWindowEx(FLASHWINFO info);
    Pointer LoadIcon(Pointer hInstance, String iconName);
    Pointer LoadImage(Pointer hinst, // handle to instance
            String name, // image to load
            int type, // image type
            int xDesired, // desired width
            int yDesired, // desired height
            int load // load options
    boolean DestroyIcon(Pointer hicon);
    int GWL_EXSTYLE = -20;
    int GWL_STYLE = -16;
    int GWL_WNDPROC = -4;
    int GWL_HINSTANCE = -6;
    int GWL_ID = -12;
    int GWL_USERDATA = -21;
    int DWL_DLGPROC = 4;
    int DWL_MSGRESULT = 0;
    int DWL_USER = 8;
    int WS_EX_COMPOSITED = 0x20000000;
    int WS_EX_LAYERED = 0x80000;
    int WS_EX_TRANSPARENT = 32;
    int GetWindowLong(Pointer hWnd, int nIndex);
    int SetWindowLong(Pointer hWnd, int nIndex, int dwNewLong);
    int LWA_COLORKEY = 1;
    int LWA_ALPHA = 2;
    int ULW_COLORKEY = 1;
    int ULW_ALPHA = 2;
    int ULW_OPAQUE = 4;
    boolean SetLayeredWindowAttributes(Pointer hwnd, int crKey,
            byte bAlpha, int dwFlags);
    boolean GetLayeredWindowAttributes(Pointer hwnd,
            IntByReference pcrKey,
            ByteByReference pbAlpha,
            IntByReference pdwFlags);
     * Defines the x- and y-coordinates of a point.
    public static class POINT extends Structure {
        public int x, y;
     * Specifies the width and height of a rectangle.
    public static class SIZE extends Structure {
        public int cx, cy;
    int AC_SRC_OVER = 0x00;
    int AC_SRC_ALPHA = 0x01;
    int AC_SRC_NO_PREMULT_ALPHA = 0x01;
    int AC_SRC_NO_ALPHA = 0x02;
    public static class BLENDFUNCTION extends Structure {
        public byte BlendOp = AC_SRC_OVER; // only valid value
        public byte BlendFlags = 0; // only valid value
        public byte SourceConstantAlpha;
        public byte AlphaFormat;
    boolean UpdateLayeredWindow(Pointer hwnd, Pointer hdcDst,
            POINT pptDst, SIZE psize,
            Pointer hdcSrc, POINT pptSrc, int crKey,
            BLENDFUNCTION pblend, int dwFlags);
    int SetWindowRgn(Pointer hWnd, Pointer hRgn, boolean bRedraw);
    int VK_SHIFT = 16;
    int VK_LSHIFT = 0xA0;
    int VK_RSHIFT = 0xA1;
    int VK_CONTROL = 17;
    int VK_LCONTROL = 0xA2;
    int VK_RCONTROL = 0xA3;
    int VK_MENU = 18;
    int VK_LMENU = 0xA4;
    int VK_RMENU = 0xA5;
    boolean GetKeyboardState(byte[] state);
    short GetAsyncKeyState(int vKey);
package com.br.kernel;
import com.sun.jna.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.ptr.IntByReference;
// by deject3d
public interface Kernel32 extends StdCallLibrary
    // description from msdn
    //BOOL WINAPI WriteProcessMemory(
    //__in   HANDLE hProcess,
    //__in   LPVOID lpBaseAddress,
    //__in   LPCVOID lpBuffer,
    //__in   SIZE_T nSize,
    //__out  SIZE_T *lpNumberOfBytesWritten
    boolean WriteProcessMemory(Pointer p, int address, Pointer buffer, int size, IntByReference written);
    //BOOL WINAPI ReadProcessMemory(
    //          __in   HANDLE hProcess,
    //          __in   LPCVOID lpBaseAddress,
    //          __out  LPVOID lpBuffer,
    //          __in   SIZE_T nSize,
    //          __out  SIZE_T *lpNumberOfBytesRead
    boolean ReadProcessMemory(Pointer hProcess, int inBaseAddress, Pointer outputBuffer, int nSize, IntByReference outNumberOfBytesRead);
    //HANDLE WINAPI OpenProcess(
    //  __in  DWORD dwDesiredAccess,
    //  __in  BOOL bInheritHandle,
    //  __in  DWORD dwProcessId
    Pointer OpenProcess(int desired, boolean inherit, int pid);
    /* derp */
    int GetLastError();
http://pastebin.com/Vq8wfy39

Hello there,
this tutorial was exactly what I needed, so thank you.
Your problem seems to be in this line:
int writeMemory = writeMemory(writeprocess, address, new short[0x22222222]); 
The problem is, you're creating a new short array with the length of 0x22222222. Which not only results in an java.lang.OutOfMemoryError: Java heap space
but also, if it would work, would create an empty array with the length of 0x22222222.
I think you want to write 0x22222222 as value in your address.
Correctly stored the code you'd need to write would be:
short[] sarray = new short[]{(short) 0x22222222};
But because the value is too long for the short, the value stored in your array would be the number 8738.
I think, what you want to do is to store the number 572662306, which would be the hex value, stored in an int variable.
So first of all you need to strip down your hex-value to shorts:
Short in Java uses 16 Bit = 2 Byte. 0x22222222 -> 0x2222 for your high byte and 0x2222 for your low byte
So your array would be
short[] sarray = new short[]{0x2222,0x2222};//notice, that sarray[0] is the lowbyte and sarray[1] the high byte, if you want to store 20 it would be new short[]{20,0} or if you use hex new short[]{0x14,0x00}
The next part is your writeToMemory Method. If I'm right, the method in the tutorial is a little bit wrong. The right version should be this:
public static int writeMemory(Pointer process, int address, short[] data) {
  IntByReference written = new IntByReference(0);
  int size = data.length*Short.SIZE/8;
  Memory toWrite = new Memory(size);
  for (int i = 0; i < data.length; i++) {
  toWrite.setShort(i*Short.SIZE/8,
  data[i]);
  boolean b = kernel32.WriteProcessMemory(process, address, toWrite,
  size, written);
  return written.getValue();
You need to calculate your offset right. And the size of your memory. Maybe you could write this method not with shorts, but with integers. But this should work.
If you pass your new array to this function, it should write 0x22222222 to your adress. If you read out your toWrite value with toWrite.getInt(0) you get the right value.
And there is one more thing. In order to write data to a process, you need to grant two access rights:
A handle to the process memory to be modified. The handle must have PROCESS_VM_WRITE and PROCESS_VM_OPERATION access to the process.
You have to grant the right to write data: PROCESS_VM_WRITE: 0x0020 and PROCESS_VM_OPERATION: 0x0008
So your writeProcess needs to get initialized this way:
Pointer writeprocess = openProcess(0x0020|0x0008,pid);
I hope this works for you. Let me know.
Greetings
Edit:
Because every data you write will be 1 byte to whatever count of byte I think the best way is to use the following method to write data to the memory:
public static void writeMemory(Pointer process, long address, byte[] data)
  int size = data.length;
  Memory toWrite = new Memory(size);
  for(int i = 0; i < size; i++)
  toWrite.setByte(i, data[i]);
  boolean b = kernel32.WriteProcessMemory(process, address, toWrite, size, null);
You can see some changes. First I changed all address values from int to long, because some addresses are out of range. And with all, i mean all. Not only in writeMemory, but also in readMemory and in your kernel32 Class.
Second I don't use the IntByReference anymore..
To use this method you need to store your data the following way if you would write 4 Byte data:
byte[] values = new byte[]{0x14,0x00,0x00,0x00};
This value would be the number 20. Index 0 will be the lowest byte and index 3 will be the highest byte.
And one more thing I wrote is an method which you can use to calculate your address if you have a baseAddress.
If you restart your program/game your old addresses won't point at the same values of your game. With some research (I use CheatEngine) you can get the baseaddress. This one will alway be the same.
To get from your baseaddress to the dynamic adress you use offsets.
public static long findDynAddy(Pointer process, int[] offsets, long baseAddress)
  long pointer = baseAddress;
  int size = 4;
  Memory pTemp = new Memory(size);
  long pointerAddress = 0;
  for(int i = 0; i < offsets.length; i++)
  if(i == 0)
  kernel32.ReadProcessMemory(process, pointer, pTemp, size, null);
  pointerAddress = ((pTemp.getInt(0)+offsets[i]));
  if(i != offsets.length-1)
  kernel32.ReadProcessMemory(process, pointerAddress, pTemp, size, null);
  return pointerAddress;
This methods gets a process, an array of offsets (hex-values) and your baseadress and returns the dynamic address.
For Solitaire the following code would give you the address to the score:
long baseAddr = 0x10002AFA8L;
  int[] offsets = new int[]{0x50,0x14};
  long addr = findDynAddy(process, offsets, baseAddr);
If somebody wants to get the whole code (user32, kernel32 and the cheater) just pm me and I will give you a link.

Similar Messages

  • Could we write and read from a external drive using a IPad?

    √could we write and read from a external drive using a IPad?

    No, the iPad doesn't work that way. The only thing you can access is camera cards (with the adaptor).
    Matt

  • Update to 10.6.8 and HP F2100 and D2400 Printers stopped working. Restored 10.6.7 and printers from Install CD's but not working,  Same with scanner

    Help....
    Updated to 10.6.8 and HP F2100 and D2400 Printers stopped working.
    Restored 10.6.7 and printers from Install CD's but not working.
    Same with F2100 scanner
    Am I glad I kept Windows desktop as without it I would be scre**ed now
    What is going on with this latest update as its like a return to Windows with things crashing or hanging up every few minutes????
    On a MacBook Air that has not been updated everything still works so what has 10.6.8 done and why won't the restore to 10.6.7 work?
    Steve

    None of those things you mentioned were what I suggested.
    I'm guessing the "ctrl click in printer preferences" means you Reset the Printing System?
    If so, that is what I would have suggested if deleting it by selecting the ( - ) button and then adding it with the ( + ) button.
    But, if HP has a fix, it likely needs to update its drivers.

  • My Itunes account was hacked and my Apple ID was disabled. I followed the instructions from APPLE to backup and restore from Itunes but that did not work. Any suggestions?? Thanks!!

    My Itunes account was hacked and my Apple ID was disabled. I followed the instructions from APPLE to backup and restore from Itunes but that did not work. Any suggestions?? Thanks!!

    Are you saying that you contacted Apple support and they instructed you to backup and restore your iPad? Or do you mean that you picked up this information from an online support article? If you spoke to an Apple rep or received these instructions via email, contact them again for further help.
    I fail to see how restoring your iPad would enable yoyr Apple ID.

  • Blinoz - Write to and read from memory address

    How do I write to or read from a specific memory address such as Hex 378?

    I may be wrong here but I think this cant be done in pure java.. The solution would be to use jni as you can do this sort of thing with c++....

  • HOW TO WRITE AND READ FROM A TEXT FILE???

    How can I read from a text file and then display the contents in a JTextArea??????
    Also how can I write the contents of a JTextArea to a text file.
    Extra Question::::::: Is it possible to write records to a text file. If you have not idea what I am talking about then ignore it.
    Manny thanks,
    your help is much appreciated though you don't know it!

    Do 3 things.
    -- Look through the API at the java.io package.
    -- Search previous posts for "read write from text file"
    -- Search java.sun.com for information on the java.io package.
    That should clear just about everything up. If you have more specific problems, feel free to come back and post them.

  • Using a PCI-6534 card, how does one write and read from the board simultaneously after being triggered on the StartTrig input ?

    I've copied two NI-developed VI's into a single VI. The first VI is the LV 'Buffered Pattern Input-Trig VI' under examples/daq/digital/653x. Using an external data generator, I send it a pulse on StartTrig, a clock on REQ1 and data on DIOA0. The start pulse is negative going so I set the front panel input to trigger on "falling edge" with clock set to 'external'. This VI is configured as Port 0 and Group 0. Once this VI is triggered I need to then start another VI which is simply the Buffered Pattern Output VI that also ships with LV. This VI is configured on Port 2, Group 1. This VI is used to simply send out a previously d
    efined array of data on DIO C0, C1 and C2.
    So, I receive a Start Trig, then clock in data, and then immediatly want to send out data. My problem is that I can't figure out when my receiving VI gets triggered on the StartTrig input. If I know when the trigger occurs, then I can wire this condition to a case statement and activate the second, or write VI. Without having the Trigger condition be met to enable the output VI, the problem is that it always outputs without even be triggered. So, where or how do I tap to find out when the StartTrig happens ? In other words, how do I know when the receiving VI has received a StartTrig pulse. There's got to be a way to do this, and I need to run in continious mode, so I can keep receiving and sending out data over and over again. Any ideas ? If your answer is to look at the examples, please tell me exact and specific examples, because I have not been able to find any examples directly related to my goal. thanks.
    Kirk

    Nestor-
    I tried your first suggestion of connecting ACK1 to ACK2. But, I get Error 10010 at Digital Buffer Control when I run the VI. I've added an array of 32 ones and zeros to the output VI so that I have some data to write. What's really interesting is when I have a scope probe on ACK1 and ACK2 which are now common, the voltage level is less than 5 volts, around 4.7, but there is something wrong with the signal, a few spikes, I've seen this before, like 2 signals are trying to drive the same output or something. When I remove the connection between ACK1 and ACK2 the signal looks perfect since ACK1 is being driven by my data generator. This leads me to believe that you can't connect ACK1 to ACK2, or atleast you can't do it with the way I have the VI'
    s configured. Also, I have a scope probe monitoring DIOC0 (since I'm writing to Port 2,which is Port C) and I don't see any data coming out, which makes sense since I get the error mentioned above.
    In terms of my configuration, I have 2 VI's on the block diagram. I have Buffered Pattern Input-Trig.VI with the following settings:
    Group: 0
    Device: 1
    Port List: 0
    Buffer Size: 1000
    Clk Soruce: External
    Trigger Type: Start Trigger
    Trigger Condition: Trigger off Falling Edge
    # of pretrigger points: 0
    For the 'writing VI' I copied the Buffered Pattern output-Trig.VI with the following setup:
    Device: 1
    Group: 1
    Port List: 2
    #of updates: 1000
    Clock Source: Internal
    Trigger Condition: Trigger on falling edge
    So, do you have any ideas on what might be wrong ? Just realized that I can attach files, so my VI is attached.
    thanks.
    Kirk
    Attachments:
    input_output_at_the_same_time.vi ‏164 KB

  • Since I use Firefox 4.0.1 I cannot save websites or photo's on websites and downloading from a website is also not working. If I click "save" or "save as" nothing happens. How to solve this ? I'm using Windows 7 home premium 32 bit

    If I right click on a downloadable photo on a website and ask to save, nothing happens, sometimes a dialogue box will ask me if I want to save it, I select yes but nothing happens. The same if I go to the menu in Firefox browser and ask to save a page, nothing happens. If I paste the same website address in my IE browser I can save and select savings location without any problem. The same for downloads.

    I have a year old Epson and an HP.. I upgraded to a win 7 64 bit and doing some sharing/networking.. Got some 32 bit XPand two win 7 64 bit..   The Epson ,shares and connects up  with no issues.. the HP is just a fiasco...   No more HP for me ...

  • Problem with ArrayLists and writing and reading from a .dat file (I think)

    I'm brand new to this forum, but I'm sure hoping someone can help me with a problem I'm having with ArrayLists. This program was originally created with an array of objects that were displayed on a GUI with jtextFields, then cycling thru them via jButtons: First, Next, Previous, Last. Now I need to add the ability to modify, delete and add records. Both iterations of this program needed to write to and read from a .dat file.
    It worked just like it was suppose to when I used just the array, but now I need to use a "dynamic array" that will grow or shrink as needed: i.e. an ArrayList.
    When I aded the ArrayList I had the ArrayList use toArray() to fill my original array so I could continue to use all the methods I'd created for using with my array. Now I'm getting a nullPointerException every time I try to run my program, which means somewhere I'm NOT filling my array ???? But, I'm writing just fine to my .dat file, which is confusing me to no end!
    It's a long program, and I apologize for the length, but here it is. There are also 2 class files, a parent and 1 child below Inventory6. This was written in NetBeans IDE 5.5.1.
    Thank you in advance for any help anyone can give me!
    LabyBC
    package my.Inventory6;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.text.DecimalFormat;
    import javax.swing.JOptionPane;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import java.io.*;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.lang.IllegalStateException;
    import java.util.NoSuchElementException;
    import java.util.ArrayList;
    import java.text.NumberFormat;
    // Class Inventory6
    public class Inventory6 extends javax.swing.JFrame {
    private static InventoryPlusColor[] inventory;
    private static ArrayList inList;
    // create a tool that insure the specified format for a double number, when displayed
    private DecimalFormat doubleFormat = new DecimalFormat( "0.00" );
    private DecimalFormat singleFormat = new DecimalFormat( "0");
    // the index within the array of products of the current displayed product
    private int currentProductIndex;
    /** Creates new form Inventory6 */
    public Inventory6() {
    initComponents();
    currentProductIndex = 0;
    } // end Inventory6()
    private static InventoryPlusColor[] getInventory() {
    ArrayList<InventoryPlusColor> inList = new ArrayList<InventoryPlusColor>();
    inList.add(new InventoryPlusColor(1, "Couch", 3, 1250.00, "Blue"));
    inList.add(new InventoryPlusColor(2, "Recliner", 10, 525.00, "Green"));
    inList.add(new InventoryPlusColor(3, "Chair", 6, 125.00, "Mahogany"));
    inList.add(new InventoryPlusColor(4, "Pedestal Table", 2, 4598.00, "Oak"));
    inList.add(new InventoryPlusColor(5, "Sleeper Sofa", 4, 850.00, "Yellow"));
    inList.add(new InventoryPlusColor(6, "Rocking Chair", 2, 459.00, "Tweed"));
    inList.add(new InventoryPlusColor(7, "Couch", 4, 990.00, "Red"));
    inList.add(new InventoryPlusColor(8, "Chair", 12, 54.00, "Pine"));
    inList.add(new InventoryPlusColor(9, "Ottoman", 3, 110.00, "Black"));
    inList.add(new InventoryPlusColor(10, "Chest of Drawers", 5, 598.00, "White"));
    for (int j = 0; j < inList.size(); j++)
    System.out.println(inList);
    InventoryPlusColor[] inventory = (InventoryPlusColor[]) inList.toArray
    (new InventoryPlusColor[inList.size()]);
    return inventory;
    } // end getInventory() method
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
    jPanel1 = new javax.swing.JPanel();
    IDNumberLbl = new javax.swing.JLabel();
    IDNumberField = new javax.swing.JTextField();
    prodNameLbl = new javax.swing.JLabel();
    prodNameField = new javax.swing.JTextField();
    colorLbl = new javax.swing.JLabel();
    colorField = new javax.swing.JTextField();
    unitsInStockLbl = new javax.swing.JLabel();
    unitsInStockField = new javax.swing.JTextField();
    unitPriceLbl = new javax.swing.JLabel();
    unitPriceField = new javax.swing.JTextField();
    invenValueLbl = new javax.swing.JLabel();
    invenValueField = new javax.swing.JTextField();
    restockingFeeLbl = new javax.swing.JLabel();
    restockingFeeField = new javax.swing.JTextField();
    jbtFirst = new javax.swing.JButton();
    jbtNext = new javax.swing.JButton();
    jbtPrevious = new javax.swing.JButton();
    jbtLast = new javax.swing.JButton();
    jbtAdd = new javax.swing.JButton();
    jbtDelete = new javax.swing.JButton();
    jbtModify = new javax.swing.JButton();
    jbtSave = new javax.swing.JButton();
    jPanel2 = new javax.swing.JPanel();
    searchIDNumLbl = new javax.swing.JLabel();
    searchIDNumbField = new javax.swing.JTextField();
    jbtSearch = new javax.swing.JButton();
    searchResults = new javax.swing.JLabel();
    jbtExit = new javax.swing.JButton();
    jbtExitwoSave = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Inventory Program"));
    IDNumberLbl.setText("ID Number");
    IDNumberField.setEditable(false);
    prodNameLbl.setText("Product Name");
    prodNameField.setEditable(false);
    colorLbl.setText("Product Color");
    colorField.setEditable(false);
    colorField.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    colorFieldActionPerformed(evt);
    unitsInStockLbl.setText("Units In Stock");
    unitsInStockField.setEditable(false);
    unitPriceLbl.setText("Unit Price $");
    unitPriceField.setEditable(false);
    invenValueLbl.setText("Inventory Value $");
    invenValueField.setEditable(false);
    restockingFeeLbl.setText("5% Restocking Fee $");
    restockingFeeField.setEditable(false);
    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(unitPriceLbl)
    .addComponent(unitsInStockLbl)
    .addComponent(colorLbl)
    .addComponent(prodNameLbl)
    .addComponent(IDNumberLbl)
    .addComponent(restockingFeeLbl)
    .addComponent(invenValueLbl))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(IDNumberField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
    .addComponent(prodNameField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
    .addComponent(colorField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
    .addComponent(unitsInStockField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
    .addComponent(unitPriceField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
    .addComponent(restockingFeeField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
    .addComponent(invenValueField, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE))
    .addContainerGap())
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(IDNumberLbl)
    .addComponent(IDNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(prodNameLbl)
    .addComponent(prodNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(colorField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(colorLbl))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(unitsInStockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(unitsInStockLbl))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(unitPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(unitPriceLbl))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(restockingFeeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(restockingFeeLbl))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(invenValueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(invenValueLbl))
    .addContainerGap())
    jbtFirst.setText("First");
    jbtFirst.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtFirstActionPerformed(evt);
    jbtNext.setText("Next");
    jbtNext.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtNextActionPerformed(evt);
    jbtPrevious.setText("Previous");
    jbtPrevious.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtPreviousActionPerformed(evt);
    jbtLast.setText("Last");
    jbtLast.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtLastActionPerformed(evt);
    jbtAdd.setText("Add");
    jbtAdd.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtAddActionPerformed(evt);
    jbtDelete.setText("Delete");
    jbtModify.setText("Modify");
    jbtModify.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtModifyActionPerformed(evt);
    jbtSave.setText("Save");
    jbtSave.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtSaveActionPerformed(evt);
    jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Search by:"));
    searchIDNumLbl.setText("Item Number:");
    jbtSearch.setText("Search");
    searchResults.setFont(new java.awt.Font("Tahoma", 1, 12));
    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
    jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(searchIDNumLbl)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addGap(259, 259, 259)
    .addComponent(searchResults, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(jbtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(searchIDNumbField, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    jPanel2Layout.setVerticalGroup(
    jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(searchIDNumLbl)
    .addComponent(searchIDNumbField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addGap(32, 32, 32)
    .addComponent(searchResults, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(jPanel2Layout.createSequentialGroup()
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtSearch)))
    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    jbtExit.setText("Save and Exit");
    jbtExit.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtExitActionPerformed(evt);
    jbtExitwoSave.setText("Exit");
    jbtExitwoSave.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtExitwoSaveActionPerformed(evt);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
    .addComponent(jbtExitwoSave, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(jbtExit)))
    .addGroup(layout.createSequentialGroup()
    .addComponent(jbtFirst)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtNext)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtPrevious)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtLast))
    .addGroup(layout.createSequentialGroup()
    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addGap(12, 12, 12)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(jbtAdd)
    .addComponent(jbtDelete)
    .addComponent(jbtModify)
    .addComponent(jbtSave))))
    .addContainerGap())
    layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbtFirst, jbtLast, jbtNext, jbtPrevious});
    layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbtAdd, jbtDelete, jbtModify, jbtSave});
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(21, 21, 21)
    .addComponent(jbtAdd)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtDelete)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtModify)
    .addGap(39, 39, 39)
    .addComponent(jbtSave))
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(jbtFirst)
    .addComponent(jbtNext)
    .addComponent(jbtPrevious)
    .addComponent(jbtLast))
    .addGap(15, 15, 15)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGroup(layout.createSequentialGroup()
    .addComponent(jbtExit)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jbtExitwoSave)))
    .addContainerGap())
    pack();
    }// </editor-fold>
    private void jbtExitwoSaveActionPerformed(java.awt.event.ActionEvent evt) {                                             
    System.exit(0);
    private void jbtSaveActionPerformed(java.awt.event.ActionEvent evt) {                                       
    String prodNameMod, colorMod;
    double unitsInStockMod, unitPriceMod;
    int idNumMod;
    idNumMod = Integer.parseInt(IDNumberField.getText());
    prodNameMod = prodNameField.getText();
    unitsInStockMod = Double.parseDouble(unitsInStockField.getText());
    unitPriceMod = Double.parseDouble(unitPriceField.getText());
    colorMod = colorField.getText();
    if(currentProductIndex == inventory.length) {
    inList.add(new InventoryPlusColor(idNumMod, prodNameMod,
    unitsInStockMod, unitPriceMod, colorMod));
    InventoryPlusColor[] inventory = (InventoryPlusColor[]) inList.toArray
    (new InventoryPlusColor[inList.size()]);
    } else {
    inventory[currentProductIndex].setIDNumber(idNumMod);
    inventory[currentProductIndex].setProdName(prodNameMod);
    inventory[currentProductIndex].setUnitsInStock(unitsInStockMod);
    inventory[currentProductIndex].setUnitPrice(unitPriceMod);
    inventory[currentProductIndex].setColor(colorMod);
    displayProduct(inventory[currentProductIndex]);
    private static void writeInventory(InventoryPlusColor i,
    DataOutputStream out) {
    try {
    out.writeInt(i.getIDNumber());
    out.writeUTF(i.getProdName());
    out.writeDouble(i.getUnitsInStock());
    out.writeDouble(i.getUnitPrice());
    out.writeUTF(i.getColor());
    } catch (IOException e) {
    JOptionPane.showMessageDialog(null, "I/O Exception writing data",
    "", JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    } //end writeInventory()
    private static DataOutputStream openOutputStream(String name) {
    DataOutputStream out = null;
    try {
    File file = new File(name);
    out =
    new DataOutputStream(
    new BufferedOutputStream(
    new FileOutputStream(file)));
    } catch (IOException e) {
    JOptionPane.showMessageDialog(null, "I/O Error", "", JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    return out;
    } // end openOutputStream()
    private static void closeFile(DataOutputStream out) {
    try {
    out.close();
    } catch (IOException e) {
    JOptionPane.showMessageDialog(null, "I/O Exception closing file",
    "", JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    } // end closeFile()
    private static DataInputStream getStream(String name) {
    DataInputStream in = null;
    try {
    File file = new File(name);
    in = new DataInputStream(
    new BufferedInputStream(
    new FileInputStream(file)));
    } catch (FileNotFoundException e) {
    JOptionPane.showMessageDialog(null, "The file doesn't exist",
    "", JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    } catch (IOException e) {
    JOptionPane.showMessageDialog(null, "I/O Error creating file",
    "", JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    return in;
    private static void closeInputFile(DataInputStream in) {
    try {
    in.close();
    } catch (IOException e) {
    JOptionPane.showMessageDialog(null, "I/O Exception closing file",
    "", JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    } // end closeInputFile()
    private double entireInventory() {
    // a temporary double variable that the method will return ...
    // after each product's inventory is added to it
    double entireInventory = 0;
    // loop to control number of products
    for (int index = 0; index < inventory.length; index++) {
    // add each inventory to the entire inventory
    entireInventory += inventory[index].setInventoryValue();
    } // end loop to control number of products
    return entireInventory;
    } // end method entireInventory
    private void jbtLastActionPerformed(java.awt.event.ActionEvent evt) {                                       
    currentProductIndex = inventory.length-1; // move to the last product
    // display the information for the last product
    displayProduct(inventory[currentProductIndex]);
    private void jbtPreviousActionPerformed(java.awt.event.ActionEvent evt) {                                           
    if (currentProductIndex != 0) // it's not the first product displayed
    currentProductIndex -- ; // move to the previous product (decrement the current index)
    } else // the first product is displayed
    currentProductIndex = inventory.length-1; // move to the last product
    // after the current product index is set, display the information for that product
    displayProduct(inventory[currentProductIndex]);
    private void jbtNextActionPerformed(java.awt.event.ActionEvent evt) {                                       
    if (currentProductIndex != inventory.length-1) // it's not the last product displayed
    currentProductIndex ++ ; // move to the next product (increment the current index)
    } else // the last product is displayed
    currentProductIndex = 0; // move to the first product
    // after the current product index is set, display the information for that product
    displayProduct(inventory[currentProductIndex]);
    private void jbtFirstActionPerformed(java.awt.event.ActionEvent evt) {                                        
    currentProductIndex = 0;
    // display the information for the first product
    displayProduct(inventory[currentProductIndex]);
    private void colorFieldActionPerformed(java.awt.event.ActionEvent evt) {                                          
    // TODO add your handling code here:
    private void jbtModifyActionPerformed(java.awt.event.ActionEvent evt) {                                         
    prodNameField.setEditable(true);
    prodNameField.setFocusable(true);
    unitsInStockField.setEditable(true);
    unitPriceField.setEditable(true);
    private void jbtAddActionPerformed(java.awt.event.ActionEvent evt) {                                      
    IDNumberField.setText("");
    IDNumberField.setEditable(true);
    prodNameField.setText("");
    prodNameField.setEditable(true);
    colorField.setText("");
    colorField.setEditable(true);
    unitsInStockField.setText("");
    unitsInStockField.setEditable(true);
    unitPriceField.setText("");
    unitPriceField.setEditable(true);
    restockingFeeField.setText("");
    invenValueField.setText("");
    currentProductIndex = inventory.length;
    private void jbtExitActionPerformed(java.awt.event.ActionEvent evt) {                                       
    DataOutputStream out = openOutputStream("inventory.dat");
    for (InventoryPlusColor i : inventory)
    writeInventory(i, out);
    closeFile(out);
    System.exit(0);
    private static InventoryPlusColor readProduct(DataInputStream in) {
    int idNum = 0;
    String prodName = "";
    double inStock = 0.0;
    double pric

    BalusC -- The line that gives me my NullPointerException is when I call the "DisplayProduct()" method. Its a dumb question, but with NetBeans how do I find out which reference could be null? I'm not very familiar with how NetBeans works with finding out how to debug. Any help you can give me would be greatly appreciated.The IDE is com-plete-ly irrelevant. It's all about the source code.
    Do you understand anyway when and why a NullPointerException is been thrown? It is a subclass of RuntimeException and those kind of exceptions are very trival and generally indicate an design/logic/thinking fault in your code.
    SomeObject someObject = null; // The someObject reference is null.
    someObject.doSomething(); // Invoking a reference which is null would throw NPE.

  • How can i write and read the same data

    hi,
             i have attached my program to this mail. i have some problems in this program.
    problems:
    1. I want to select the threshold for the rms,varience and s.d.
    But what i used is not doing that. i want to fix the upper threshold value and lower threshold value.
     when ever the input crosses upper threshold value i want the output and it will remains uptill the value above the lower threshold value.
    Once it come down the lower threshold value the output should be stopped.
    2. I want to write this in to a  file and i want to read this file. is this possible or not. 
                please try to help me i am very new with lab view6i
           REGARDS
    CHAMARTHY KOMAL DILEEP.
       [email protected]
    Attachments:
    dileep.vi ‏93 KB

    The easiest way to perform a certain action (such as file I/O) based on a certain condition (such as whether a value has passed a certain threshold) is to use a comparison VI in combination with a case structure. Then you can specify that if your rms, standard deviation and variance are above a threshold then perform a certain action.
    Also consider using shift registers to keep track of data from the last loop. If I understand you correctly, you want to start logging data when an upper threshold has been passed. Then you want to continue logging data until a lower threshold is passed. I have attached a non-functional but explanatory VI that will help explain how to implement logic to that effect. It also demonstrates that you can indeed write and read from the same file in a loop. The best way to do this is to open the file before the loop, do all the necessary writing and reading in the loop, and then close the file after the loop.
    Hope this helps!
    Jarrod S.
    National Instruments
    Attachments:
    dileep_example.vi ‏61 KB

  • Problem using the Write to SGL VI and Read from SGL VI

    Hello Sir, I have a problem using the Write to SGL VI. When I am trying to write the captured data using DAQ board to a SGL file, I am unable to store the data as desired. There might be some problem with the VI which I am using to write the data to SGL file. I am not able to figure out the minor problem I am facing. I am attaching a zip file which contains five files.
    1) Acquire_Current_Binary_Exp.vi -> This is the VI which I used to store my data using Write to SGL file.
    2) Retrive_BINARY_Data.vi -> This is the VI which I used to Read from SGL file and plot it
    3) Binary_Capture -> This is the captured data using (1) which can be plotted using (2) and what I observed is the plot is different and also the time scare is not as expected.
    4) Unexpected_Graph.png is the unexpected graph when I am using Write to SGL and Read from SGL to store and retrieve the data.
    5) Expected_Graph.png -> This is the expected data format I supposed to get. I have obtained this plot when I have used write to LVM and read from LVM file to store and retrieve the data.
    I tried a lot modifying the sub VI’s but it doesn’t work for me. What I think is I am doing some mistake while I am writing the data to SGL and Reading the data from SGL. Also, I don’t know the reason why my graph is not like (5) rather I am getting something like its in (4). Its totally different. You can also observe the difference between the time scale of (4) and (5).
    Have a Good Day
    Regards,
    Krishna
    Attachments:
    LABVIEW_Files.zip ‏552 KB

    As already discussed a while ago, your binary data does not contain timing information. You need to tell it the scan rate so it can reconstruct the time axis correcty.
    From the data, it seems the sample file was recorded at 0.5MHz. Take the inverse and set the time increment. Voila!
    Your sample file is two column data with one colum all zero. You need to set the number of columns to two, to only get the good data in channel 1.
    Your acquisition program contains unecessary FOR loops, you can remove the inner loops without change in result.
    It makes no sense to convert to SGL if you initialize the shift registers with an empty DBL array. You need to initialize with an empty SGL array.
    (The code could be simplified quite a bit more, but this should give you some directions).
    The attached zip shows some ideas (LabVIEW 7.1).
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    LabVIEW_FilesMOD.zip ‏195 KB

  • How to write and read data in a specific memory location ??

    Hi Everyone:
    Does anyone know how to write and read data in a specific memory location by using Java ?
    I need pointers, but I don't know how to do it ??
    Thanks for answering
    Rodger

    Hi Everyone:
    Does anyone know how to write and read data in a
    specific memory location by using Java ?
    I need pointers, but I don't know how to do it ??
    Thanks for answering
    RodgerWith Java you cannot write to a specific memory location. Java does not have pointers. If you really want to do it, you need to use JNI, i.e write the required functions in C (or other languages that support pointers) and make those functions available to Java (through JNI). This approach is not portable. You can have a look at http://java.sun.com/docs/books/tutorial/native1.1/index.html
    Regards.

  • I want to write and read a hex file from the flash buffer of the microcontroller through the USB serial port

    hello sir,
    I am developing a GUI screen from that i want to write and read a hex file from the flash buffer of the microcontroller through the USB serial port. the driver i am using is FTDID2XX driver.if anyone having examples of loading file through serial port.Please reply me .
    Thanks

    Looks like you should post your request in the LabVIEW forum, this one here preferentially is for LabWindows/CVI...

  • How to combine both DAQ AI signal, write and read file in single VI

    Hi
     I am the new user of LabVIEW version 7.1 for testing automation application. I have to measure 33 signals ( mostly analog like temp, pressure, etc...) from NI USB 6210 DAQ system and write in master file for future verfication.From real data or from master file back up have to write  one more file if only the signal reaches steady state , which will used for analysis and same signals to be read from this file parallely & make a waveform and/or table display format.
    Pl. help me to shortout this problem 
    note: I have plan to ugrade labVIEW version 2011 shortly, so let me know doing parrel acquistion write and read file for data analysis in same VI in version 7.1...... 

    Parallel operations in LabVIEW are very simple.  Just code it in parallel and it will work.
    Try taking a look at some of the examples in the NI Example Finder (Help > Find Examples).  There you will find example for writing to and reading from files, as well as data acquistion in parallel with other operations.
    You might need a producer/consumer architecture is you are acquiring data very quickly.
    Chris
    Certified LabVIEW Architect
    Certified TestStand Architect

  • DAQ vi to perform digital write and read measurements using 32 bits binary data saved in a file

    Hi
    DAQ vi to perform digital write and read measurements using 32 bits binary data saved in a file
    Two main
    sections:
    1)     
    Perform
    write and read operations to and fro different spread sheet files, such that
    each file have a single row of 32bits different binary data (analogous to 1D
    array) where the left most bit is the MSB. I don’t want to manually enter the
    32 bits binary data, I want the data written or read just by opening a file
    name saves with the intended data.
          2)     
    And
    by using test patterns implemented using the digital pattern generator or  build digital data functions or otherwise, I need to
    ensure that the     
                binary data written to a spreadsheet file or any supported file type
    then through the NI-USB 6509 is same as the data read.
    I’m aware I can’t use the simulated
    device to read data written to any port but if the write part of the vi works I
    ‘m sure the read part will work on the physical device which I’ll buy later.
    My Plan
    of action
    I’ve
    created a basic write/read file task and a write/read DAQ task for NI USB 6509
    and both combine in a while loop to form a progress VI which I’m confuse of how
    to proceed with the implementation.
    My
    greatest problem is to link both together with the correct functions or operators
    such that there are no syntax/execution errors and thus achieve my intended
    result.
    This
    project is one of my many assignments for my master thesis, so please i’ll
    appreciate every help as I’m not really efficient with LabVIEW programming but
    I prefer it because is fun and interesting if I get to know it.
    Currently I’m
    practicing with LabVIEW 8.6/NI DAQmx 8.8 Demo versions and NI USB 6509
    simulated device.
    Please see
    the attached file for my novice progress, thanks in
    advance for the support
    Rgds
    Paul
    Attachments:
    DIO_write_read DAQ from file.vi ‏17 KB

    What does your file look like?  The DAQmx write is expecting a single U32 value, not an array of I64. 
    Message Edited by vt92 on 09-16-2009 02:42 PM
    "There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal

Maybe you are looking for