For ease of use I recommend a BufferedImage.
There are two options, one provided by HRgiger where you never store the image, instead load it each time, the other is to store it directly in the Student
instance.
Instead of storing it as a byte[] picture;
as you might need some functionality in the future for the image. Which BufferedImage
has, or you can easily add to it.
As you mentioned you were comfortable with Swing it is fairly easy to handle. Note, I would not let the student render the image itself. Just provide a getter for the image and render it from the relevant method.
A short example.
Student.java
public class Student {
private String name;
private BufferedImage image;
public Student (String name) {
this.name = name;
this.image = ImageIO.read(new File(name + ".png"));
}
public getName () {
return name;
}
public getImage () {
return image;
}
}
Some paint method somewhere where it makes sense to paint the Student.image
private final List<Student> students = new ArrayList<>();
...
@override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (Student s : students) {
g.drawImage (s.getImage(), x, y, null);
}
}
That paintComponent
needs to have access in some way to the List<Student>
. You can also of course just paint one student.