Painting Graphics from an Array

I have a GUI that displays the Towers of Hanoi solution in a JPanel. Everything actually works except for a slight repainting issue.
Currently I am overriding the paint() function, I know that for my purpose using paintComponent() would probably be the better route, however that's not my issue...
The images (disks) in my JPanel are not redrawing properly, and I have no idea why...
Basically:
- I call setup() to set the number of disks and the co ordinates they should be drawn. (store them in an array)
- I call moveDisk() to change the co ordinates of each disk as they are being moved.
- then drawDisk() is called to go through the array of disks and print them.
currently paint() calls drawDisk() in order to display the current position of all the disks.
It seems to work fine for the first 2 moves, then disks start disappearing until there is one (the last disk) left...BUT if I print the co ordinates of the disks they seem to be correct, just not drawing.
could someone take a look at my code and see what is wrong?
below is the meat of the code, minus the GUI:
    public class HanoiFrame extends javax.swing.JFrame {
    private static final int STATE_SETUP = 0;
    private static final int STATE_ANIMATE = 1;
    private static final int POLE_AREA_HEIGHT = 356;
    private static final int POLE_AREA_WIDTH = 205;
    private static final int DISK_ARC_HEIGHT = 15;
    private static final int DISK_ARC_WIDTH = 15;
    private static final int DISK_HEIGHT = 23;
    private static final int MAX_DISKS = 10;
    private static final int MAX_ANIMATION_DELAY = 30000;
    private static final int MAX_PHYSICAL_DELAY = 100000;
    private static final int MIN_DISKS = 1;
    private static final int MIN_ANIMATION_DELAY = 1;
    private static final int MIN_PHYSICAL_DELAY = 1;
    private static final int EMPTY_CELL_VALUE = -1;
    private static final int CELL_HEIGHT = 25;
    private static final int COLUMNS = 3;
    private static final int ROW = 11;
    private  static final int MILLISECONDS_PER_SECOND = 1000;
    private final static String newline = "\n";
    private static Disk[] disks;
    private static Disk newDisk;
    private static int[][] diskCells;
    public static  int startX = 2;
    public static  int startY = 340;
    public static int setDiskAmount = 0;
    public static int setAnimationDelay = 0;
    public static int  setPhysicalDelay = 0;
    public static int  moveNumber = 0;
    public static int intMovesLeft = 0;
    private boolean  buttonPressed = false;
    private double movesLeft = 0;
    private int windowState = 0;
    /** Creates new form HanoiFrame */
    public HanoiFrame() {
        initComponents();
        /* initialize the "poles" to hold a certain number of "cells */
        this.diskCells = new int[ROW][COLUMNS];
        for (int row = ROW - 1;row >= 0; row--) {
            for (int col = 0;col < COLUMNS ; col++) {
                diskCells[row][col] = EMPTY_CELL_VALUE;
    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
        /* reset all the variable to original state */
        setDiskAmount = 0;
        setAnimationDelay = 0;
        setPhysicalDelay = 0;
        moveNumber = 0;
        movesLeft = 0;
        intMovesLeft = 0;
        buttonPressed = false;
        windowState = 0;
        this.startButton.setEnabled(true);
        this.diskAmount.setEditable(true);
        this.animationDelay.setEditable(true);
        this.physicalDelay.setEditable(true);
        /* reset all the cell vales to empty (this could be its own function) */
        for (int row = ROW - 1;row >= 0; row--) {
            for (int col = 0;col < COLUMNS ; col++) {
                diskCells[row][col] = EMPTY_CELL_VALUE;
        /* reset the content of the TextFields and Area */
        this.diskAmount.setText("");
        this.animationDelay.setText("");
        this.physicalDelay.setText("");
        this.outTextArea.setText("");
        /* repaint the display panel */
        this.hanoiPanel.repaint();
    /* i have no idea why this is here...It was generated by Netbeans when I
     *made the reset button.  As you can see it made 2.  The one above it the same
     *except it contains code.  Since it was automatically generated
     *I cannot delete it.
    private void resetButtonMouseReleased(java.awt.event.MouseEvent evt) {                                         
    /* is executed when the start button is pressed.
     *also executes a field check and intializes key variables. Finally,
     *it executes the solution and generates the solve time
    private void startButtonMouseReleased(java.awt.event.MouseEvent evt) {                                         
        /* check if the program has already been run (without being reset) */
        if (!buttonPressed){
            /* check the fields to ensure the input is correct and useable */
            if (checkFields()){
                /* give button a pressed status if all info valid */
                buttonPressed = true;
                windowState = 1;
                /* disable the button */
                this.startButton.setEnabled(false);
                /* disable the fields */
                this.diskAmount.setEditable(false);
                this.animationDelay.setEditable(false);
                this.physicalDelay.setEditable(false);
                /* setup the disks on the starting pole */
                setup();
                /* initialize the number of moves required. 2 to the power of n minus 1 */
                movesLeft = Math.pow(2, setDiskAmount) - 1;
                /* convert the number to an integer */
                intMovesLeft = (int)movesLeft;
                /* set the physical delay */
                setPhysicalDelay = Integer.parseInt(this.physicalDelay.getText());
                /* create and start a new thread.  This is EXTREMELY important
                 *as it allows for GUI to be repainted while the soulution
                 *is animated */
                SolveEngine s = new SolveEngine();
                s.start();               
     * @param args the command line arguments
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new HanoiFrame().setVisible(true);
    /*returns the Animation panel area graphics
     *@return Animation area graphics
    public static Graphics getAnimationArea(){
        /* get the usable area of poleA */
        Container clientArea = hanoiPanel;
        //Container clientArea = this.getContentPane();
        /* get the graphics to the display panel*/
        Graphics gfx = clientArea.getGraphics();
        return gfx;
     *set up the requested amount of disks on the first pole
     *@param diskAmount the amount of disks entered by the user
    public void setup(){
        int numberOfDisks = setDiskAmount;
        this.disks = new Disk[numberOfDisks];
        int diskNumber = 0;
        int diskWidth = POLE_AREA_WIDTH - 4;
        int arcH = DISK_ARC_HEIGHT;
        int arcW = DISK_ARC_WIDTH;
        int x = startX;
        int y = startY;
        int row = 0;
        int col = 0;
        /* get the graphics to the display panel*/
        //Graphics gfx = getAnimationArea();
        /* set the color of the disks */
        //gfx.setColor(Color.MAGENTA);
        /* draw the specified number of disks */
        while (diskNumber < numberOfDisks){
            /* reduce the y position */
            y = startY - diskNumber * CELL_HEIGHT;
            /* draw the disk */
            //gfx.fillRoundRect(x, y, diskWidth, DISK_HEIGHT, arcH, arcW);
            /* create a new instance of disk */
            newDisk = new Disk(x, y, diskWidth);
            /* give the new disk an id */
            this.disks[diskNumber] = newDisk;
            /* add the id to the cell array of poleA */
            this.diskCells[row][col] = diskNumber;
            /* make the disk smaller and center */
            x = x + 8;
            diskWidth = diskWidth - 16;
            /* increase disk number */
            diskNumber++;
            /* move to the next row */
            row++;
        repaint();
     *move the disk from a source pole to the destination pole.
     *this should take the source col and destination col to determine where to draw the
     *disk.  It will also need to know to draw the disk in the first available cell
     *in a col
     *@param source the starting pole of the next move
     *@param destination the end pole of the next move
    public void moveDisk(int src, int dest){
        /* the lines below would not be necessary if I were to pass the Graphics
         *gfx object as a parameter.  I may have to use this option in order
         *to work around the current repainting issue */
        /* get the graphics to the display panel*/
        Graphics gfx = getAnimationArea();
        /* get the id of the disk to be moved */
        int disk = getDiskId(src);
        /* get the to and from rows */
        int sourceRow = getRow(src);
        int destinationRow = getRow(dest);
        /* set the co ordintates of the destination */
        int col = dest * POLE_AREA_WIDTH;
        int x = disks[disk].getStartX() + col;
        int y = startY - (destinationRow * CELL_HEIGHT);
        int width = disks[disk].getDiskWidth();
        disks[disk].setStartX(x);
        disks[disk].setStartY(y);
        disks[disk].setDiskWidth(width);
        //System.out.println("startX " + x);
        //System.out.println("startY " + y);
        //System.out.println("destination row " + destinationRow);
        //System.out.println("disk " + disk);
        //System.out.println("Width " + width);
        diskCells[sourceRow - 1][src] = EMPTY_CELL_VALUE;
        /* set the destination row to the disk id */
        diskCells[destinationRow][dest] = disk;
        drawDisk();
        repaint();
    public void drawDisk(){
        int diskNum = setDiskAmount -1;
        int i = 0;
        Graphics gfx = getAnimationArea();
        gfx.setColor(Color.MAGENTA);
        while(diskNum >= 0){
            //System.out.println("here is the disk IDs " + diskNum);
            //System.out.println("the startY during draw " + disks[diskNum].getStartY());
            gfx.fillRoundRect(disks[diskNum].getStartX(), disks[diskNum].getStartY(), disks[diskNum].getDiskWidth(), DISK_HEIGHT, DISK_ARC_WIDTH, DISK_ARC_HEIGHT);
            diskNum--;
    public void paint(Graphics gfx){
        if(windowState == 0){
            super.paint(gfx);
            setup();
        } else if (windowState == 1){
            super.paint(gfx);
            drawDisk();
     *returns the id of the disk
     *@param col the the designated column
     *@return the disk identification number
    public static int getDiskId(int col){
        int diskIdent = 0;
        /* initialize the row number to max -1, because the array start at 0 */
        int row = MAX_DISKS - 1;
        /* do a cell check while row is greater than 0
         *this is done so that is starts at the top row
         *and moves down
        while (row > EMPTY_CELL_VALUE){
            /* when the first cell that is not -1 is reached get the disk number
             *that disk will be the smallest in the stack */
            if(diskCells[row][col] != -1){
                //diskIdent = this.diskCells[row][col];
                diskIdent =diskCells[row][col];
                break;
            row--;
        return diskIdent;
     *returns the first available row
     *@param col the designated col
     *@return the first available row number
    public static int getRow(int col){
        int rowNumber = 0;
        /* cycle through the cells until it finds an empty one */
        while (diskCells[rowNumber][col] != -1){
            rowNumber++;
        return rowNumber;
     *calculate the total time it takes for the tower of hanoi game to be
     *solved, given the amount of disk and the amount of time it takes
     *to physically move a disk from one pole to the other.
    public static void totalTime(){
        int timeInSeconds = setPhysicalDelay * intMovesLeft;
        int i = 0;
        int seconds = 0;
        int minute = 0;
        int hour = 0;
        int day = 0;
        int month = 0;
        int year = 0;
        while (i < timeInSeconds){
            if(seconds > 60){
                minute++;
                seconds = 0;
            if(minute > 60){
                hour++;
                minute = 0;
            if(hour > 24){
                day++;
                hour = 0;
            if(day > 30){
                month++;
                day = 0;
            if(month > 12){
                year++;
                month = 0;
            seconds++;
            i++;
        updateMessageCenter("It would take:" + year + " years " + month + " months " + day +
                " days " + hour + " hours " + minute + " minutes and " + seconds + " seconds, to move " + setDiskAmount +
                " disks at " + setPhysicalDelay + " seconds per move");
   

Sorry if my post was a little too cryptic...
"How do you know? You have a problem you can't solve. Anything could be your issue." Agreed. However, using the process of elimination and debug statments I have been able to narrow the scope of the issue.
"If you can't solve it by executing the code and adding debug statements how to you expect us to help."If I could solve but "executing code and adding debug statements" there would be no need to post the problem here.
"We don't know exactly what you are attempting to do."Trying to paint my graphics to a JPanel based on a set of co ordinates.
"We don't know why you are passing the Graphics object around."Why not? is it impossible to do it this way?
"The big problem is in the alogorithm you use to determine the location of each component."Who said you couldn't read minds?
"If you are using some kind of animation then I would use a Timer to schedule the moving of components. I don't even see how you are doing this in your code."Sorry I guess stating that I didn't post my entire code may have threw things off...I do use a timer in a seperate class. I will include it in the next post.
"I can't tell if you are using Threads of not."guess you overlooked these lines of code:
                /* create and start a new thread.  This is EXTREMELY important
                 *as it allows for GUI to be repainted while the soulution
                 *is animated */
                SolveEngine s = new SolveEngine();
                s.start();   Here is the code once again:
public class HanoiFrame extends javax.swing.JFrame {
    private static final int STATE_SETUP = 0;
    private static final int STATE_ANIMATE = 1;
    private static final int POLE_AREA_HEIGHT = 356;
    private static final int POLE_AREA_WIDTH = 205;
    private static final int DISK_ARC_HEIGHT = 15;
    private static final int DISK_ARC_WIDTH = 15;
    private static final int DISK_HEIGHT = 23;
    private static final int MAX_DISKS = 10;
    private static final int MAX_ANIMATION_DELAY = 30000;
    private static final int MAX_PHYSICAL_DELAY = 100000;
    private static final int MIN_DISKS = 1;
    private static final int MIN_ANIMATION_DELAY = 1;
    private static final int MIN_PHYSICAL_DELAY = 1;
    private static final int EMPTY_CELL_VALUE = -1;
    private static final int CELL_HEIGHT = 25;
    private static final int COLUMNS = 3;
    private static final int ROW = 11;
    private  static final int MILLISECONDS_PER_SECOND = 1000;
    private final static String newline = "\n";
    private static Disk[] disks;
    private static Disk newDisk;
    private static int[][] diskCells;
    public static  int startX = 2;
    public static  int startY = 340;
    public static int setDiskAmount = 0;
    public static int setAnimationDelay = 0;
    public static int  setPhysicalDelay = 0;
    public static int  moveNumber = 0;
    public static int intMovesLeft = 0;
    private boolean  buttonPressed = false;
    private double movesLeft = 0;
    private int windowState = 0;
    /** Creates new form HanoiFrame */
    public HanoiFrame() {
        initComponents();
        /* initialize the "poles" to hold a certain number of "cells */
        this.diskCells = new int[ROW][COLUMNS];
        for (int row = ROW - 1;row >= 0; row--) {
            for (int col = 0;col < COLUMNS ; col++) {
                diskCells[row][col] = EMPTY_CELL_VALUE;
    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
        /* reset all the variable to original state */
        setDiskAmount = 0;
        setAnimationDelay = 0;
        setPhysicalDelay = 0;
        moveNumber = 0;
        movesLeft = 0;
        intMovesLeft = 0;
        buttonPressed = false;
        windowState = 0;
        this.startButton.setEnabled(true);
        this.diskAmount.setEditable(true);
        this.animationDelay.setEditable(true);
        this.physicalDelay.setEditable(true);
        /* reset all the cell vales to empty (this could be its own function) */
        for (int row = ROW - 1;row >= 0; row--) {
            for (int col = 0;col < COLUMNS ; col++) {
                diskCells[row][col] = EMPTY_CELL_VALUE;
        /* reset the content of the TextFields and Area */
        this.diskAmount.setText("");
        this.animationDelay.setText("");
        this.physicalDelay.setText("");
        this.outTextArea.setText("");
        /* repaint the display panel */
        this.hanoiPanel.repaint();
    /* i have no idea why this is here...It was generated by Netbeans when I
     *made the reset button.  As you can see it made 2.  The one above it the same
     *except it contains code.  Since it was automatically generated
     *I cannot delete it.
    private void resetButtonMouseReleased(java.awt.event.MouseEvent evt) {                                         
    /* is executed when the start button is pressed.
     *also executes a field check and intializes key variables. Finally,
     *it executes the solution and generates the solve time
    private void startButtonMouseReleased(java.awt.event.MouseEvent evt) {                                         
        /* check if the program has already been run (without being reset) */
        if (!buttonPressed){
            /* check the fields to ensure the input is correct and useable */
            if (checkFields()){
                /* give button a pressed status if all info valid */
                buttonPressed = true;
                windowState = 1;
                /* disable the button */
                this.startButton.setEnabled(false);
                /* disable the fields */
                this.diskAmount.setEditable(false);
                this.animationDelay.setEditable(false);
                this.physicalDelay.setEditable(false);
                /* setup the disks on the starting pole */
                setup();
                /* initialize the number of moves required. 2 to the power of n minus 1 */
                movesLeft = Math.pow(2, setDiskAmount) - 1;
                /* convert the number to an integer */
                intMovesLeft = (int)movesLeft;
                /* set the physical delay */
                setPhysicalDelay = Integer.parseInt(this.physicalDelay.getText());
                /* create and start a new thread.  This is EXTREMELY important
                 *as it allows for GUI to be repainted while the soulution
                 *is animated */
                SolveEngine s = new SolveEngine();
                s.start();
     *Check all the fields at once to ensure that they are valid
    private boolean checkFields(){
        String numberOfDisks = null;
        String animationDelay = null;
        String physicalDelay = null;
        numberOfDisks = this.diskAmount.getText();
        animationDelay = this.animationDelay.getText();
        physicalDelay = this.physicalDelay.getText();
        /* initiate my array of error messages */
        ArrayList errMsg = new ArrayList(0);
        /* check if the number of disks was left blank */
        if (numberOfDisks.equals("")){
            errMsg.add("Please enter the Number of Disks (MAX " + MAX_DISKS + ")");
        }else{
            /* check if the input given is valid */
            try {
                /* parse the disk amount entered into an integer */
                setDiskAmount = Integer.parseInt(numberOfDisks);
                /* check the # of disks entered is greater than 0 and less than 10 */
                if (setDiskAmount < MIN_DISKS){
                    errMsg.add("Number of Disks must be greater than " + MIN_DISKS);
                } else if (setDiskAmount > MAX_DISKS){
                    errMsg.add("Number of Disks must be less than" + MAX_DISKS);
            } catch (NumberFormatException ex) {
                errMsg.add("Number of Disks must be a Number");
        /* check if animation delay was left blank */
        if (animationDelay.equals("")){
            errMsg.add("Please enter disk Animation Delay");
        } else {
            /* check if the input given is valid */
            try {
                /* parse the animation delay entered into an integer */
                setAnimationDelay = Integer.parseInt(animationDelay);
                /* check range of animation delay */
                if (setAnimationDelay < MIN_ANIMATION_DELAY){
                    errMsg.add("Animation Delay must be greater than 0");
                } else if (setAnimationDelay > MAX_ANIMATION_DELAY){
                    errMsg.add("Animation Delay must be less than " + MAX_ANIMATION_DELAY);
            } catch (NumberFormatException ex) {
                errMsg.add("Animation Delay must be a Number");
        /* check if physical delay was left blank */
        if (physicalDelay.equals("")){
            errMsg.add("Please enter the Physical disk delay");
        } else {
            /* check if the input given is valid */
            try {
                /* parse the physical delay entered into an integer */
                setPhysicalDelay = Integer.parseInt(physicalDelay);
                /* check check the range of the physical delay */
                if (setPhysicalDelay < MIN_PHYSICAL_DELAY){
                    errMsg.add("Physical Delay must be greater than 0");
                } else if (setPhysicalDelay > MAX_PHYSICAL_DELAY){
                    errMsg.add("Physical Delay must be less than " + MAX_PHYSICAL_DELAY);
            } catch (NumberFormatException ex) {
                errMsg.add("Physical Delay must be a Number");
        /* if there is any problem, add the message to the popup and display */
        if (!errMsg.isEmpty()){
            JOptionPane.showMessageDialog(this, errMsg.toArray());
            return false;
        return true;
     * @param args the command line arguments
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new HanoiFrame().setVisible(true);
    /*returns the Animation panel area graphics
     *@return Animation area graphics
    public static Graphics getAnimationArea(){
        /* get the usable area of poleA */
        Container clientArea = hanoiPanel;
        //Container clientArea = this.getContentPane();
        /* get the graphics to the display panel*/
        Graphics gfx = clientArea.getGraphics();
        return gfx;
     *set up the requested amount of disks on the first pole
     *@param diskAmount the amount of disks entered by the user
    public void setup(){
        int numberOfDisks = setDiskAmount;
        this.disks = new Disk[numberOfDisks];
        int diskNumber = 0;
        int diskWidth = POLE_AREA_WIDTH - 4;
        int arcH = DISK_ARC_HEIGHT;
        int arcW = DISK_ARC_WIDTH;
        int x = startX;
        int y = startY;
        int row = 0;
        int col = 0;
        /* get the graphics to the display panel*/
        //Graphics gfx = getAnimationArea();
        /* set the color of the disks */
        //gfx.setColor(Color.MAGENTA);
        /* draw the specified number of disks */
        while (diskNumber < numberOfDisks){
            /* reduce the y position */
            y = startY - diskNumber * CELL_HEIGHT;
            /* draw the disk */
            //gfx.fillRoundRect(x, y, diskWidth, DISK_HEIGHT, arcH, arcW);
            /* create a new instance of disk */
            newDisk = new Disk(x, y, diskWidth);
            /* give the new disk an id */
            this.disks[diskNumber] = newDisk;
            /* add the id to the cell array of poleA */
            this.diskCells[row][col] = diskNumber;
            /* make the disk smaller and center */
            x = x + 8;
            diskWidth = diskWidth - 16;
            /* increase disk number */
            diskNumber++;
            /* move to the next row */
            row++;
        repaint();
     *move the disk from a source pole to the destination pole.
     *this should take the source col and destination col to determine where to draw the
     *disk.  It will also need to know to draw the disk in the first available cell
     *in a col
     *@param source the starting pole of the next move
     *@param destination the end pole of the next move
    public void moveDisk(int src, int dest){
        /* the lines below would not be necessary if I were to pass the Graphics
         *gfx object as a parameter.  I may have to use this option in order
         *to work around the current repainting issue */
        /* get the graphics to the display panel*/
        Graphics gfx = getAnimationArea();
        /* get the id of the disk to be moved */
        int disk = getDiskId(src);
        /* get the to and from rows */
        int sourceRow = getRow(src);
        int destinationRow = getRow(dest);
        /* set the co ordintates of the destination */
        int col = dest * POLE_AREA_WIDTH;
        int x = disks[disk].getStartX() + col;
        int y = startY - (destinationRow * CELL_HEIGHT);
        int width = disks[disk].getDiskWidth();
        disks[disk].setStartX(x);
        disks[disk].setStartY(y);
        disks[disk].setDiskWidth(width);
        //System.out.println("startX " + x);
        //System.out.println("startY " + y);
        //System.out.println("destination row " + destinationRow);
        //System.out.println("disk " + disk);
        //System.out.println("Width " + width);
        diskCells[sourceRow - 1][src] = EMPTY_CELL_VALUE;
        /* set the destination row to the disk id */
        diskCells[destinationRow][dest] = disk;
        drawDisk();
        repaint();
        String output = "";
        //must initialize row to max - 1 and increment 'til = 0
        //since the array position starts at 0
        //this will print the array from the top down
        for (int row = ROW - 1;row >= 0; row--) {
            for (int colm = 0;colm < COLUMNS ; colm++) {
                output = output + diskCells[row][colm];
            output = output + "\n";
        System.out.println(output);
        System.out.println(newline);
    public void drawDisk(){
        int diskNum = setDiskAmount -1;
        int i = 0;
        Graphics gfx = getAnimationArea();
        gfx.setColor(Color.MAGENTA);
        while(diskNum >= 0){
            //System.out.println("here is the disk IDs " + diskNum);
            //System.out.println("the startY during draw " + disks[diskNum].getStartY());
            gfx.fillRoundRect(disks[diskNum].getStartX(), disks[diskNum].getStartY(), disks[diskNum].getDiskWidth(), DISK_HEIGHT, DISK_ARC_WIDTH, DISK_ARC_HEIGHT);
            diskNum--;
    public void paint(Graphics gfx){
        if(windowState == 0){
            super.paint(gfx);
            setup();
        } else if (windowState == 1){
            super.paint(gfx);
            drawDisk();
     *returns the id of the disk
     *@param col the the designated column
     *@return the disk identification number
    public static int getDiskId(int col){
        int diskIdent = 0;
        /* initialize the row number to max -1, because the array start at 0 */
        int row = MAX_DISKS - 1;
        /* do a cell check while row is greater than 0
         *this is done so that is starts at the top row
         *and moves down
        while (row > EMPTY_CELL_VALUE){
            /* when the first cell that is not -1 is reached get the disk number
             *that disk will be the smallest in the stack */
            if(diskCells[row][col] != -1){
                //diskIdent = this.diskCells[row][col];
                diskIdent =diskCells[row][col];
                break;
            row--;
        return diskIdent;
     *returns the first available row
     *@param col the designated col
     *@return the first available row number
    public static int getRow(int col){
        int rowNumber = 0;
        /* cycle through the cells until it finds an empty one */
        while (diskCells[rowNumber][col] != -1){
            rowNumber++;
        return rowNumber;
     *calculate the total time it takes for the tower of hanoi game to be
     *solved, given the amount of disk and the amount of time it takes
     *to physically move a disk from one pole to the other.
    public static void totalTime(){
        int timeInSeconds = setPhysicalDelay * intMovesLeft;
        int i = 0;
        int seconds = 0;
        int minute = 0;
        int hour = 0;
        int day = 0;
        int month = 0;
        int year = 0;
        while (i < timeInSeconds){
            if(seconds > 60){
                minute++;
                seconds = 0;
            if(minute > 60){
                hour++;
                minute = 0;
            if(hour > 24){
                day++;
                hour = 0;
            if(day > 30){
                month++;
                day = 0;
            if(month > 12){
                year++;
                month = 0;
            seconds++;
            i++;
        updateMessageCenter("It would take:" + year + " years " + month + " months " + day +
                " days " + hour + " hours " + minute + " minutes and " + seconds + " seconds, to move " + setDiskAmount +
                " disks at " + setPhysicalDelay + " seconds per move");
     *add the message to the diplay window
     *currently this is not necessary, but may be required to
     *dynamically display the contents of message into the text area
     *@param message the message to be added/appended the the text area
    public static void updateMessageCenter(String message){
        /* append text to the message */
        outTextArea.append(message + newline);
        /* ensure the the most recent line is viewable - auto scroll */
        outTextArea.setCaretPosition(outTextArea.getDocument().getLength());
    public class SolveEngine extends Thread {
        /** Creates a new instance of SolveEngine */
        public SolveEngine() {
        public void run(){
            /* start the engine/animation */
            solutionEngine(HanoiFrame.setDiskAmount,0, 2, 1);
            /* calculate and print the total time after the solution is complete */
            HanoiFrame.totalTime();
     *the recursive solution to the Towers of Hanoi problem
     *@param diskAmount the number of disks that need to be moved
     *@param start the identity of the starting column
     *@param end the identity of the ending column
     *@param temp the identity of the temporary column
        public void solutionEngine(int diskAmount,int start, int end, int temp){
            int disks = diskAmount;
            int startPole = start;
            int endPole = end;
            int tempPole = temp;
            try {
                if ( disks == 1 ) {
                    HanoiFrame.moveNumber++;
                    HanoiFrame.updateMessageCenter("Moving disk from  "+ startPole + " to "+ endPole + " Move #: " + HanoiFrame.moveNumber + " of " + HanoiFrame.intMovesLeft);
                    /* delay the movement of the disk */
                    Thread.sleep(HanoiFrame.setAnimationDelay);
                    /* move the disk */
                    moveDisk(startPole, endPole);
                } else {
                    solutionEngine( disks - 1, startPole, tempPole, endPole);
                    HanoiFrame.moveNumber++;
                    HanoiFrame.updateMessageCenter("Moving disk from  "+ startPole + " to "+ endPole + " Move #: " + HanoiFrame.moveNumber + " of " + HanoiFrame.intMovesLeft);
                    /* delay the movement of the disk */
                    Thread.sleep(HanoiFrame.setAnimationDelay);
                    moveDisk(startPole, endPole);
                    solutionEngine( disks - 1, tempPole, endPole, startPole);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
    }

Similar Messages

  • Need to paint objects from one applet into another

    Maybe this question is more at home here; I have an applet test program which uses the timer class to make a car drive across the screen. The test works fine with the rectangle I used, but now I need to use the car created in this class:
       import java.applet.Applet;
       import java.awt.Graphics;
       import java.awt.Graphics2D;
       import java.awt.Rectangle;
       import java.awt.geom.Ellipse2D; 
       import java.awt.geom.Line2D;
       import java.awt.geom.Point2D;
         public class Car extends Applet
              public void paint(Graphics g)
                   Graphics2D g2 =(Graphics2D)g;
                   Rectangle body =new Rectangle(100, 110, 60, 10);
                   Ellipse2D.Double frontTire =new Ellipse2D.Double(110, 120, 10, 10);
                   Ellipse2D.Double rearTire =new Ellipse2D.Double(140, 120, 10, 10);
                   Point2D.Double r1 =new Point2D.Double(110, 110);
                   //the bottom of the front windshield
                   Point2D.Double r2 =new Point2D.Double(120, 100);
                   //the front of the roof
                   Point2D.Double r3 =new Point2D.Double(140, 100);
                   //the rear of the roof
                   Point2D.Double r4 =new Point2D.Double(150, 110);
                   //the bottom of the rear windshield
                   Line2D.Double frontWindshield =new Line2D.Double(r1, r2);
                   Line2D.Double roofTop =new Line2D.Double(r2, r3);
                   Line2D.Double rearWindshield =new Line2D.Double(r3, r4);
                   g2.draw(body);
                   g2.draw(frontTire);
                   g2.draw(rearTire);
                   g2.draw(frontWindshield);
                   g2.draw(roofTop);
                   g2.draw(rearWindshield);
         }The only thing I could think of was making an object of type Car in the test program and then doing something like this:
    Car c =new Car();
    g2.draw(c.paint(g));
    But it says in the test program void type not allowed here. Any tips as to what I'm doing wrong? My guess is that its a problem in the Car class and not the test program, but I didn't think I was supposed to alter Car. (Plus I tried already and couldn't get it to work.)

    what? I don't see what you are trying to do..
    You are trying to make an instance of a class which has no constructor?
    You are trying to move a Panel (an Applet is a subclass of Panel) in another Panel (in Test class?)
    Keep in mind that the Panel automatically has flow layout. In flow layout the components are sized to minimum size, and if the component is another Panel, the minimum size is 0 if there are no components in it.
    Do you need both applets open at once?
    Why not just copy this paint code into your test class?
    Also note that you CAN copy the Graphics from one component onto another, but the Graphics object cannot be null, or you will get a NullPointerException... which is what will happen if you try to copy it in the init() of your test class.
    Why not just make your car a Component (or a Panel even) and give it a constructor? (And make sure to set minimum size to something other than zero?)
    I think you have more than one problem..
    Jen

  • Painting graph from loop?

    * I am having a hard time trying to figure out why this is not working
    * the input file is single line entries (these numbers are from the file and the format)
    * 1
    * 891.67
    * 1968.12
    * 198031.88
    * 2859.79
    * 200000
    * 5.35
    * nl
    * 2
    * 882.89
    * 1976.9
    * 196054.98
    * 2859.79
    * 200000
    * 5.35
    * nl
    * 3 and so on, depending on what the other program is writing.
    * could someone please tell me why this is not painting as I expected it should?
    * right now it only paints the grid hash marks. What did I do wrong?
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.io.*;
    import javax.swing.JOptionPane;
    public class graph extends Frame
         Line2D lineu = new Line2D.Double(20, 40, 20, 300);
         Line2D linel = new Line2D.Double(370, 300, 20,300);
         Stroke drawingStroke = new BasicStroke(2);
         public static String[] aa;
         public void paint(Graphics y)
              Graphics2D graph1 = (Graphics2D)y;
         graph1.setStroke(drawingStroke);
         graph1.setPaint(Color.black);
         graph1.draw(lineu);
         graph1.setPaint(Color.black);
         graph1.draw(linel);
         for(int x = 20; x < 370; x++)
              Line2D hash = new Line2D.Double(x, 300, x, 305);
              graph1.draw(hash);
              x = x + 5;
         for(int x = 45; x < 300; x++)
              graph1.setPaint(Color.black);
              Line2D hash2 = new Line2D.Double(15, x, 20, x);
              graph1.draw(hash2);
              x = x + 5;
         try
                   File file = new File("temp.sto");
                   FileInputStream FIS = new FileInputStream(file);
                   BufferedReader BR = new BufferedReader(new InputStreamReader(FIS));
                   aa = new String[3];
                   for (int i = 0; i < aa.length; i++)
                        aa[i] = BR.readLine();
                   for (int j = 0; j < aa.length; j++)
                             int month = Integer.parseInt(aa[j]);
                             int monthI = Integer.parseInt(aa[j+1]);
                             int monthPrin = Integer.parseInt(aa[j+2]);
                             int amtlft = Integer.parseInt(aa[j+3]);
                             int monthp = Integer.parseInt(aa[j+4]);
                             int totloan = Integer.parseInt(aa[j+5]);
                             int intval = Integer.parseInt(aa[j+6]);
                             System.out.println(aa[j]);
                                  graph1.setPaint(Color.red);
                                  Line2D monthID = new Line2D.Double(month+20, monthI, month+20, monthI + 5);
                             graph1.draw(monthID);
                             graph1.drawString("Monthly Interest", 50, 50);
                             graph1.setPaint(Color.green);
                                  Line2D monthPrinD = new Line2D.Double(month+20, monthPrin, month+20, monthPrin + 5);
                                  graph1.draw(monthPrinD);
                                  graph1.drawString("Monthly Principle", 50, 60);
                                  graph1.setPaint(Color.red);
                                  Line2D amtlftD = new Line2D.Double(month+20, amtlft, month+20, amtlft + 5);
                                  graph1.draw(amtlftD);
                                  graph1.drawString("Amount Left", 50, 70);
                                  graph1.setPaint(Color.black);
                                  graph1.drawString("The full loan of " + totloan + " with " + intval + "% interest", 50, 80);
                                  graph1.drawString("has a monthly payment of " + monthp, 50, 90);
                             j = j + 6;
                             if (aa[j+8]=="zzz" || aa[j+8] == "")
                                  j=100000000;
         }catch (FileNotFoundException e)
                   JOptionPane.showMessageDialog(null, "The file is not where you think it is. I can not continue.");
                   System.exit(0);
              }catch (Exception e)
         public static void main(String args[])
              Frame frame = new graph();
         frame.addWindowListener(new WindowAdapter()
         public void windowClosing(WindowEvent we)
              System.exit(0);
         frame.setSize(400, 400);
         frame.setVisible(true);
    }

    Please post code in code tags and indent it properly.

  • How to drag a painted square from one panel to the other?

    Hi there,
    I'm a student IT, and for the course Programming, which uses Java, we have to write a game.
    I've got a JFrame with two JPanels. Both are overriding paint(Graphics g). One JPanel, let's say JP1, draws a board with 196 squares, the other, JP2, draws 21 pieces made up from the same size squares. What I want is, when I press on a piece in JP2, that I can drag that piece over to the board, JP1, and when I release the mousebutton, the piece is drawn in the board.
    How can I realize the dragging part? I've tried with an extra JPanel, with the size of the JFrame, but then either JP1, JP2, or both won't draw anymore.
    Can someone help me with this?
    Check here for a paint what I mean (don't mind my painting skills :p). At no.1, the mousebutton is pressed on the piece, at no. 2 the dragging starts, and at no. 3 the mousebutton is released again.
    Hope I've provided you enough information, I would post the source code here, but it's a lot in Dutch, and it may just confuse you ;)
    Greetings,
    Niek

    Ok, I'll study the link, and try to post my threads in the right section next time ;)
    Didn't even came up with me there might be a tutorial or something for this..
    Thank you! ;)
    Edited by: Niekfct on 17-mrt-2009 21:19

  • Get distinct values from plsql array

    Hi,
    I have declared a variable as below in plsql proc.
    type t_itemid is table of varchar2(10);
    inserted set of items in to this using a program
    now i want distinct values from that array how can i get it.

    I am using 9i so i cannot use set operator and more over my problem is that i am declaring the variable inside the plsql block . when i tried i am getting the below errors:
    SQL> r
    1 declare
    2 type t_type is table of varchar2(10);
    3 v_type t_type;
    4 begin
    5 v_type := t_type('toys','story','good','good','toys','story','dupe','dupe');
    6 for i in (select column_value from table(v_type)) loop
    7 dbms_output.put_line(i.column_value);
    8 end loop;
    9* end;
    for i in (select column_value from table(v_type)) loop
    ERROR at line 6:
    ORA-06550: line 6, column 41:
    PLS-00642: local collection types not allowed in SQL statements
    ORA-06550: line 6, column 35:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    ORA-06550: line 6, column 10:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 7, column 22:
    PLS-00364: loop index variable 'I' use is invalid
    ORA-06550: line 7, column 1:
    PL/SQL: Statement ignored

  • How do I remove NaN values from an array?

    I'm trying to test if the values in an array are less than 0.001. All of them are...BUT the problem is that some of the elements in the array are NaN. I'd like to do one of two things:
    1. Remove the NaN elements from the array and set them to zero to make the test work.
    2. Make the test understand that NaN elements are okay.
    The test results in a boolean array of T/F values. If all of the values of the boolean array are T, it will result in a single boolean value of T. In #2, I am saying that I want it to test if an element of the array is less than 0.001 OR equal to NAN.
    Solved!
    Go to Solution.

    Your statements don't make much sense. It's irrelevant how many NaNs are in the array. A sort will move them all to the bottom. You had said you wanted to find out if all the elements in an array are less than 0.001, and that you've got some NaNs in there. Well, this will do that:
    twolfe13 wrote:
     I did see how to remove NaN once, but couldn't determine a good way to generalize it other than doing a test loop. I thought there might have been a simple function that I overlooked to do this.
    As I noted, there have been several posts in the past about efficient techniques for removing certain elements out of an array. Seek, and ye shall find.
    Joseph Loo wrote:
    Have you look at the coerce function where you can set the lower and upper limit?
    That won't do anything for NaN. Or perhaps I misunderstood what you are suggesting to do?
    Attachments:
    NaN sort.png ‏20 KB
    NaN sort small.png ‏5 KB

  • Without loops how can i read data from associative Array??

    Hi all,
    I am facing scenario like...
    i need to read data from associative array  without using loops is it possible,
    CREATE OR REPLACE PACKAGE BODY test_pkg IS
        TYPE t1 IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
       -- in array we can expect more than one row or sometimes no data also.
      FUNCTION test1(vt1 T1 DEFAULT CAST(NULL AS t1)) RETURN NUMBER IS
      BEGIN
        -- basically in array we'll get data of column2
        -- this loop should satisfies table1.colum2 = nvl(NULL, table2.colum2 )if array is null.
        -- if array is not null then only compare with array values
        FOR i IN (SELECT t1.colum1,t1.column2
                         FROM table1 t1, table1 t2
                              WHERE t1.colum1 = t2.column1
                                AND t1.colum2 = nvl(vt1, t2.colum2)
          LOOP
            generateTEXT(i.colum1, i.colum2);
         END LOOP;
      END test1;
    END test_pkg;
    in table1 we have date like...
    colum1          column2
    Jan                  1
    Feb                  2
    Mar                  3
    if i call select test_pkg.test1(1) from dual then output should
    be Jan..
    and
    select test_pkg.test1(null) from dual then it should display all elements from table1.
    Jan                  1
    Feb                  2
    Mar                  3,
    Thanks for your quick replay..

    i need to read data from associative array  without using loops is it possible,
    No - you would need to create a SQL type and then use the TABLE operator to unnest the collection.
    create or replace TYPE my_nums IS TABLE OF INTEGER;
    DECLARE
    --  TYPE my_nums IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;
      v_nums my_nums := my_nums(1, 2, 3);
      v_total number;
    BEGIN
      select sum(column_value) into v_total from table(v_nums);
      DBMS_OUTPUT.PUT_LINE
        ('Sum of the numbers is ' || TO_CHAR(v_total));
    END;
    Sum of the numbers is 6

  • How to delete rows from 2D array in this case...

    Hello. I'm just begging adventure with labview so please for patient. I created a program whitch suppose work in following way:
    2D Input array is array created by FOLDER BROWSING subVI. It works in this way,that browse folder and looking for txt files whose contanins measurment data. In my case subVI founds 4 files,and from theirs headers read information about what kind of data are in file also their's path. In this way is created 2D Input Array. subVI named PLOTS FROM PATHS ARRAY make picture with polar/XY plot. It's create only those plots and legends on one picture as many files(their paths) is setted to the program by output array. I made this subVI in that way and I would not like to change it. 
    My problem is that in even loop (witch check for any change by user) program suppose to relay anly those rows(files) for which checkbox are marked, e.g. marking anly 1 and 4 box, program should chose from input array row 1 and 4 only and pass them to output array,then  PLOTS FROM PATHS ARRAY subVI makes a picture only with 1 and 4 plot and legend only for plot 1 and 4. The best solution would be some relay witch is avtivated by logical signal. It lost to me ideas how to solve it, I'm just in blaind corner...
    I tried to use delete from array but I don't know how to do use it properly in this program,becease it can be only before or afeter for loop. Below is scan of front panel and also main problem. Please set me up somehow to solve this problem. 
    Regards 
    Solved!
    Go to Solution.
    Attachments:
    plots selector.vi ‏17 KB
    problem.PNG ‏18 KB

    I have attached a vi. Is this the one that you need?
    Anand kumar SP
    Senior Project Engineer
    Soliton Technologies Pvt Ltd
    Attachments:
    plot selector modified.vi ‏14 KB

  • Is there a way to remove elements from an array 1 by 1?

    I have an two arrays, and they vary in size depending on a parameter set by the user (both arrays are the same size though, they both can vary in length). What I need to do, is remove elements one by one from the array, and use these as indices for another array. Basically, I built two arrays to store x-values on a graph. At the first value on the first array, I want y values on the graph to move from 0 to Y (any value). Then on the first value on the second array, I want the y values to move back from Y to 0 (creating a pulse, essentially, from the first value on the first array and the first value on the second array). By having each x value act as an indice for the y array, I belive I can acc
    omplish this (ie, y =0 up to indice 90, then y = 5, then at indice 100, y goes back to equaling 0). I know this is poorly phrased, but it's difficult to explain. If anyone could help me out, I'd really appreciate it.

    jdaltonnal,
    Note: to add an attachment based on your comment of 6/12/01 to my earlier reply, I had to go back to this 'answer' mode, which gives me the option of adding attachments.
    Per your comment, you have a sequence, so I've added a simple sequence structure and the 2nd array to provide a 250ms delay between each array output. Let me know...Doug
    Attachments:
    arrayindexplus1withseqdelays.vi ‏27 KB

  • How to view motion graphics from websites on iphone 4 ?

    07/27/2013
    Hello, can anyone provide information as to viewing motion graphics from websites on iphone4 ?  -- when I view a website; I can see still pictures, words, numbers, colors ,etc... EXCEPT for the motion graphics.   The motion graphics does not show-up at all from the websites on the iphone4. The websites that I am having prolems viewing are the ones that are animated (cartoon-ish) in motion.
    Example:  I can see an animated still picture of a man driving a car, but; I cannot see the animated motion graphics of the man actually turning the steering wheel, moving his head while looking in different directions while driving, the car wheels turning, etc... on the same website being viewed - the animated motion graphics will not show-up at all on the iphone4.
    I would like to know if there is a mobile app from the apple archive, or any type of mobile software to install to be able to view the motion graphics and, if so; I would appreciate any feedback pertaining to this matter.
    Thank You.

    I actually purchased GoodReader because it is easy to transfer files without iTunes.  I dislike the file sharing through iTunes.   You can use a Mac or PC.  Once I was in the app I clicked the "Wi-Fi" symbol which brings me to "WiFi-transfer."  It will show this --
    "WiFi status: ON
    Use one of the following addresses exactly as you see them
    1. IP-address: http://192.168.0.98:8080 <-- Local LAN address the iPhone is broadcasting on.
    2. Bonjour-address http://Myname-iPhone.local:8080"
    All you have to do is type one of those addresses into your browser. (Safari, etc.)
    It will take you to a page that has iPhone Connection and a list of options.  You can either create a new directory within the application or use an existing one to upload a text file.  It's rather simple, you just select "Choose a file to upload" > Select your file > Press upload > Start the app and see your text/pdf/whatever file.
    You can also connect to a server to download a text file, browse the web, or enter a url.  I see it also has an ICloud folder which I'm not sure if it integrates with Apple's iCloud or not, I think it does.  I'm not affliated with the app and I'm not saying you have to buy it, I'm just a happy user.
    If you don't want to buy this app let me know I'll keep looking for a free or cheaper one for you if you want.

  • Display one div at a time from an array?

    I am trying to make a multiple choice quiz. I have each question and answer in a div. There are 20 divs. All are set to not display on the stage, and I want to call one randomly to display as the user answers that question.
    For the moment, I am trying to get even one question to display on the stage. Here is my code, which is at the top in the edgeActions.js file inside the first function.
    //Edge code
    (function($, Edge, compId){
    var Composition = Edge.Composition, Symbol = Edge.Symbol; // aliases for commonly used Edge classes
    //my code
    var divs = new Array( 'div.ques1', 'div.ques2', 'div.ques3', 'div.ques4', 'div.ques5', 'div.ques6', 'div.ques7', 'div.ques8', 'div.ques9', 'div.ques10', 'div.ques11', 'div.ques12', 'div.ques13', 'div.ques14', 'div.ques15', 'div.ques16', 'div.ques17', 'div.ques18', 'div.ques19', 'div.ques20' ), idx;
    var idx = Math.floor(Math.random()*divs.length);
    function getQuestion() {
    //the following commands do not work
                        $('idx').show();
                        $('idx').css('display','inline');
                        $('divs[idx]').appendTo(document.body);
                        $('sym.que2').show();
      $('que2').show();
                        $('div.ques1').show();
                        $('ques2').show();
    //these do work
                        alert("blah");
                        console.log('this is working');
                        console.log('id=%d', idx);
              getQuestion();
    Since the console is returning the random number from the array, I have a feeling Edge cannot distinguish the array number from the corresponding div. Converting them to symbols does nothing. I am starting to think it would have been easier to just hand code this rather than using Edge.

    Hi Elaine,
    Thank you for your response!
    Your new randomize line worked beautifully
    I have tried defining my array elements in every connotation I can think of, inlcuding changing them to symbols. I did figure out today that an element has to be displayed before it will even be hit by jQuery, [.show() will not work] and if autoplay is checked while they are off, they will show, and vice versa. Confusing, but it narrowed it down enough for me to see I really just needed to figure out how to call the elements, then figure out all the on/off/autoplay stuff from there.
    Here is my new code in its new location, the compositionReady panel:
    var divs = new Array( 'Symbol_1', 'Symbol_2', 'Symbol_3', 'Symbol_4', 'Symbol_5', 'Symbol_6', 'Symbol_7', 'Symbol_8', 'Symbol_9', 'Symbol_10', 'Symbol_11', 'Symbol_12', 'Symbol_13', 'Symbol_14', 'Symbol_15',
    'Symbol_16', 'Symbol_17', 'Symbol_18', 'Symbol_19', 'Symbol_20' );   // display is on for all symbols
    sym.setVariable("myArr", divs);
    var random = Math.floor(Math.random() * 100) % 20;
    console.log( divs );   //works
    console.log( "myArr" );   //works
    console.log( random );    //works
    function getQuestion() {
             sym.$("myArr").hide();  // doesn't work
             sym.$("myArr").hide();  //doesn't work
                        console.log('this is working');  //works
                        console.log('id=%d', random);   //works
    getQuestion();
    All of the questions are showing at once and I want to be able to hide all of them.
    Array[20] 
    0: "Symbol_1"
    1: "Symbol_2"
    2: "Symbol_3"
    3: "Symbol_4"
    4: "Symbol_5"
    5: "Symbol_6"
    6: "Symbol_7"
    7: "Symbol_8"
    8: "Symbol_9"
    9: "Symbol_10"
    10: "Symbol_11"
    11: "Symbol_12"
    12: "Symbol_13"
    13: "Symbol_14"
    14: "Symbol_15"
    15: "Symbol_16"
    16: "Symbol_17"
    17: "Symbol_18"
    18: "Symbol_19"
    19: "Symbol_20"
    length: 20
    myArr
    17
    this is working
    17

  • Adding data from an array to a table

    How can i add information from an array to a table via JDBC? I have tried:
    stmt.executeUpdate("INSERT INTO TEMP " + "VALUES (" + carData[0] + ", " + carData[1]);
    but i get the error:
    SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
    Also, can i only add data to some columns of a row and not all?

    If your TEMP table has only two columns and both of
    them are of number
    types, and your array contains only numeric types
    (int[], long[] etc., it should not be a problem.
    If your table contains more than two columns (and the
    remaining columns are nullable) you need to list the
    column names in the insert statement. Check your table
    definition in the database and see SQL syntax for
    insert.
    If your columns are of string type, you need to
    enclose the values in quotes (alternatively, use
    PreparedStatement).I agree with this.
    Here is the syntax that he was talking about
    //if the values are numeric
    stmt.executeUpdate("INSERT INTO TEMP(<COLUMN NAME>,<COLUMN NAME>) "
    + "VALUES(" + carData[0] + "," + carData[1] + ")";
    //if the values are text
    stmt.executeUpdate("INSERT INTO TEMP(<COLUMN NAME>,<COLUMN NAME>) "
    + "VALUES('" + carData[0] + "','" + carData[1] + "')";
    Notice that the last part of your original query was incorrect. You forgot to put the bracket in quotes again.

  • Just converted a PDF document to Word, none of the graphics from the PDF file show up in the Word document?

    Just converted a PDF document to Word, none of the graphics from the PDF file show up in the Word document?
    What do I need to do to bring the graphics and exhibits from the PDF file to the Word file?

    Hi jackp52432917,
    How was that PDF file created? Please see  Will Adobe ExportPDF convert both text and form... | Adobe Community
    It could be that the PDF file you're converting was created using a third-party application, and it doesn't contain all the information necessary to ensure a clean conversion. Have you had similar troubles converting other PDF files?
    Best,
    Sara

  • Getting a single value from an array collection

    I have an array collection that was created from an XML file
    through the HTTP Service. One of the nodes in the XML file was
    product_number and I can display all of the items in this node in a
    datagrid so I know the array has the name of the node in it.
    I would like to be able to retrieve a single item from the
    array collection (e.g. a product_number = to xxx) and assign it to
    a variable.
    I would also like to be able to assign all the items in a
    particlur column (e.g. all product_numbers) to separate variables
    at the same time.
    Any help would be greatly appreciated.

    You can apply a filterFunction.
    Or you can do it the brute force way: loop over the elements,
    and test for the value you want.
    As far as putting values into variables, I am not sure what
    you want.
    And this is not a Flex Builder question and should go in the
    General Discussion forum.
    Tracy

  • Error while retrieving data from an ARRAY resultset

    We hava an Oracle stroed procedure which has a table type as its OUT parameter and where the data is being entered into. This data requries to be returned to the Java client through a JDBC connection. We have used the OracleTypes' ARRAY object for this. We are facing errors when retieving data from the ARRAY resultset
    The Oracle Package
    ----I created a table type called "PlSqlTable":
    CREATE OR REPLACE TYPE PlSqlTable IS TABLE OF VARCHAR2(20);
    ----I defined this as the out parameter for my procedure :
    PROCEDURE testSQL
    arrayOutID OUT PlSqlTable
    Then populated the object :
    arrayOutID := PlSqlTable();
    arrayOutID.extend(4);
    arrayOutID(1):= 'Hello';
    arrayOutID(2) := 'Test';
    arrayOutID(3) := 'Ora';
    ----The procedure executes fine - all debug statements are printed ----right till the end of execution.
    The Java class
    ----Here is how I have defined the parameters :
    OracleCallableStatement stmnt = (OracleCallableStatement)connection.prepareCall("begin testSQL(?);end;");
    stmnt.registerOutParameter(2,OracleTypes.ARRAY,"PLSQLTABLE");
    System.out.println("Executing..");
    stmnt.execute();
    System.out.println("Executed..");
    ARRAY outArray = stmnt.getARRAY(1);
    System.out.println("Got array");
    ResultSet rset = outArray.getResultSet();
    System.out.println("Got Resultset..");
    int i = 1;
    while(rset.next()){
    System.out.println("VALUE : " + rset.getString(i));
    i = i+1;
    ----On execution, the debug messages display :
    Executing..
    Executed..
    Got array
    Got Resultset..
    VALUE : 1
    VALUE : Test
    ERROR : java.sql.SQLException: Invalid column index
    ----But I have populated upto 3 values in th e procedure. Then why this error ?
    PLLLEEEASE help me out on this.
    Thanks, Sathya

    haven't worked with db arrays but I think your problem is here:int i = 1;
    while(rset.next()){
         System.out.println("VALUE : " + rset.getString(i));
         i = i+1;
    }In the first loop you are retrieving the value from column 1(rs.getString(1)), which is OK, but in the second loop, you are trying to retrieve a value from the second column(rs.getString(2)) which doesn't exist. Try this code which only reads from column1:
    while(rset.next()){
         System.out.println("VALUE : " + rset.getString(1));
    }Jamie

Maybe you are looking for

  • Any hope for older Mac Pro?

    My Mac Pro is a 2007 model and just under the necessary limit to be allowed to upgrade to either Mt. Lion or Mavericks. Is there any sort of upgrade that would make it eligible? (I can supply exact specs if needed)

  • TS1702 ipod no longer finds updates in the app store. it say app store not found.

    my ipod no longer update apps from app store. How do I fix it?

  • Value Transport (Exporting) to multiple screen fields in Search Help

    Hi all, I have created elementary search help using exit and attached it to data element. After F4 when I get hitlist I want all the values from the selected rows to get copied to the screen fields. I.e. I want the value transport. In the search help

  • Auto Login in Apex 4.2.3

    Hi All, Am calling a apex application url from a third party application. In the url am passing user name and password and i to want to check the user is valid user or not, if the user is valid then it should skip the login page and go to the home pa

  • Can´t update iPhoto and iWeb

    Starting with software update in the Apple menu. There are updates for iPhoto (7.1.4) and iWeb (2.0.4). I press the Install Items button. After a short time I get the message: None of the checked updates could be installed. Sorry an unexpected error