Results 1 to 13 of 13
Thread: Passing a variable problem.
- 04-29-2011, 12:37 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 13
- Rep Power
- 0
Passing a variable problem.
Hi guys. I'm having a bit of bother (once again) with passing a variable between 2 classes.
In my first class(called imageFrame), I have the following line of code:
the method that this refers to in the second class(called ImagePanel) is as follows:Java Code:myImagePanel.displayPicture(defaultLoadImage);
The idea is that, I'd like "defaultLoadImage" to be passed into "displayImage", but I can't work out how to go about doing it. I know this is going to be a really simple answer, so sorry for the stupid question, but any help would really be appreciated.Java Code:public void displayPicture(Image displayImage) { gBuffer.drawImage(displayImage, 0, 0, null); paintComponent(this.getGraphics()); }
Thanks.
- 04-29-2011, 12:43 PM #2
Never use getGraphics of a Component in client code. Learn how to correctly perform custom painting:
Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)
db
- 04-29-2011, 12:48 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 13
- Rep Power
- 0
The code above is from a lab as part of a my coursework so I'm afraid it has to be used in order to appease my lecturers. Regardless of how useless or inefficient it is.
- 04-29-2011, 02:21 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
- 04-29-2011, 02:53 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 13
- Rep Power
- 0
Agreed, It's completely stupid. The idea is that we're being taught to work with other peoples code etc. Any ideas what I have to do to pass this variable across? I'm sure it's just a variable declaration somewhere, but I have no idea where it goes or how to go about writing it...
- 04-29-2011, 05:29 PM #6
To call that code misguided is like calling murder a misdemeanor. Using getGraphics() of a Component in client code is 99.999% of the time just plain wrong.
The remaining 0.001% applies to sophisticated programs that perform necessary checks on the returned Graphics value to decide whether to use it for rendering. Certainly not coursework.
db
- 04-30-2011, 12:33 PM #7
Member
- Join Date
- Mar 2011
- Posts
- 13
- Rep Power
- 0
... Ok, I understand that it's not correct... Regardless, it's still what I have to do. Can anyone please help me pass this variable?
- 04-30-2011, 12:45 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 04-30-2011, 02:44 PM #9
Member
- Join Date
- Mar 2011
- Posts
- 13
- Rep Power
- 0
Ok doke. Thanks for your time guys.
-
Phew !
- 04-30-2011, 03:05 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
-
- 04-30-2011, 04:02 PM #13
It's even more exasperating that this crappy code has evidently been around for at least four years.
Java Programming: NullPointerException doing my head in - thatsjava.com
Their one member who responded was even worse than the questioners.
db
Similar Threads
-
Passing Variable In Frame
By amitabh in forum JDBCReplies: 2Last Post: 06-07-2010, 04:36 PM -
passing variable in trees??
By player123 in forum Advanced JavaReplies: 2Last Post: 02-03-2009, 12:42 PM -
Passing Environment Variable in Eclipse Europa
By ajaymenon.k in forum EclipseReplies: 0Last Post: 11-19-2007, 10:08 AM -
Passing variable information between classes
By zen_to_go in forum New To JavaReplies: 1Last Post: 10-30-2007, 08:09 PM -
Variable passing, Error: IOException
By fernando in forum New To JavaReplies: 3Last Post: 07-31-2007, 02:03 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks