Click to See Complete Forum and Search --> : Can't invoke a method on a int


javaQQ
June 16th, 2001, 02:55 AM
I am trying to change the background colour of successive rows as another row is dragged over them. I have run into a problem.

" public boolean dragMoved( DragEvent e ) {

dragEntered( e );

return true;
}

public boolean dragEntered( DragEvent e ) {

int dragEnteredRow = table.rowAtPoint( e.getPoint() );

// dragEnteredRow.setForeground( selected );
// table.rowAtPoint( e.getPoint() ).setForeground( selected );

if ( dragEnteredRow == -1 ) {;
System.out.println( "out of bounds !!" );

} else {
System.out.println( "Drag Entered at : Row" + dragEnteredRow );
System.out.println( "" );
}
return true;
} "

The segment of code above works as indended (this stuff implements the Macintosh Drag and Drop API):
It prints out the following:

" Drag Entered at : Row4
... several times...
Drag Entered at : Row5
... several times...
Drag Entered at : Row6
... several times...
Drag Entered at : Row7
... etc. "

However, when I try to get it to change the rows' background colour:

" dragEnteredRow.setForeground( selected ); "
- OR -
" table.rowAtPoint( e.getPoint() ).setForeground( selected ); "

I get this error message from the compiler:

"... Can't invoke a method on a int.
dragEnteredRow.setForeground( selected ); ... "
- OR -
"... Can't invoke a method on a int.
table.rowAtPoint( e.getPoint() ).setForeground( selected ); ... "

How should I adjust the code to work properly?

Many thanks in advance for your solutions.

slushi
June 16th, 2001, 03:10 AM
Type int is a primitive, not an object. You can't invoke methods on it. I think you want to replace the first commented line with

table.setForeground(selected)

Norm
June 16th, 2001, 10:49 AM
What do you want the code to do? Program comments are useful for that.
Your code is trying to call the setForeground() method of an int (but int is not a class so that doesn't make any sense). int's don't have colors or any other attributes that can be set? Is the int value an index into an array of object that have colors?
Then what you want to do is to index into that array with the int to get to the object whose color you want to change:

ObjectWithColor[dragEnteredRow].setForeground(selected);



What does the method: table.rowAtPoint(...) return? If it's not an object with a setForeground() method then you need to change that also.

Norm