0

I am working on a Java project after a very long time of not having used the language, so bear with me (I'm primarily a .NET and Windows Forms developer nowadays, as some background).

I am creating some Java Bean classes to store related data which will be passed between separate Java processes on my local machine through RMI. Some of these processes will act as clients and expose a GUI to the user (most likely Swing-based).

Let's say I have a Java Bean which represents information for a driver's license. Among other things like the license number and information about the driver, one of the properties should be a photo of the driver. This photo will be displayed in a GUI and set by the client's user, and may also have to be stored in a database by another process at some point.

In C#, I would use the System.Drawing.Image class to store this information. But what should I use in a Java Bean? Again, I haven't used Java in a long time to develop a project, so I'm quite rusty; I'm sure this is something simple, but a quick web search is not giving me anything.

Community
  • 1
  • 1
Knowledge Cube
  • 990
  • 12
  • 35
  • You may want refer to [this](http://stackoverflow.com/questions/299495/how-to-add-an-image-to-a-jpanel) – TuyenNTA May 07 '17 at 01:19
  • Simplest would be [How to Use Labels](http://docs.oracle.com/javase/tutorial/uiswing/components/label.html), something more flexible might be [Performing Custom Painting](http://docs.oracle.com/javase/tutorial/uiswing/painting/) and [2D Graphics](http://docs.oracle.com/javase/tutorial/2d/). You should also have a look at [Reading/Loading an Image](http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html) – MadProgrammer May 07 '17 at 01:39
  • @TuyenNguyen and others: Just to be clear, this question is primarily about the class I would use in a Java Bean. Then using this image in a Swing GUI is secondary. What I use may or may not be the same for both, which is why I'm asking. – Knowledge Cube May 07 '17 at 02:07
  • You can save it as a string path to your image, a file or an byte[], then in Swing GUI just load it and draw – TuyenNTA May 07 '17 at 02:14
  • @TuyenNguyen A `String` path or a file is not feasible in my case, because the image data needs to be contained within an object sent to another process via RMI (i.e., the file may not be accessible on the other end if one of the processes is relocated to another host). – Knowledge Cube May 07 '17 at 22:49
  • @ChristopherKyleHorton so you can use an array of byte to save this image data, you can send it to every where you want then [convert this byte array to image](https://www.mkyong.com/java/how-to-convert-byte-to-bufferedimage-in-java/) – TuyenNTA May 07 '17 at 22:56

0 Answers0